Hello I tried to make a bot with Discord.py and I tried implementing this to my code but I get the error in the title. I don’t know a lot of Python yet and I’m very new so I don’t know what may cause this error. Any help would be great, thanks!
JavaScript
x
61
61
1
import discord
2
import os
3
import requests
4
import json
5
import random
6
from keep_alive import keep_alive
7
import asyncio
8
9
10
client = discord.Client()
11
basura = ["rezero"]
12
verdad = [
13
"es una mierda",
14
"no debería existir",
15
"VIVA K-ON",
16
]
17
18
19
def get_quote():
20
response = requests.get("https://zenquotes.io/api/random")
21
json_data = json.loads(response.text)
22
quote = json_data[0]['q'] + " - " + json_data[0]['a']
23
return (quote)
24
25
26
@client.event
27
async def on_ready():
28
print ('We logged in as {0.user}'.format(client))
29
30
@client.event
31
async def on_message(self,message):
32
if message.author.id == self.user.id:
33
return
34
35
if message.content.startswith('Hola'):
36
await message.channel.send('Sup nerd')
37
38
if message.content.startswith('Inspirame'):
39
quote = get_quote()
40
await message.channel.send(quote)
41
if any(word in message.content for word in basura):
42
await message.channel.send(random.choice(verdad))
43
44
if message.content.startswith('^Guess'):
45
await message.channel.send('Adivina un numero del 1 al 10')
46
def is_correct(m):
47
return message.content.author == message.author and m.content.isdigit()
48
answer = random.randint(1,10)
49
50
try:
51
guess = await self.wait_for('message',check=is_correct,timeout=5.0)
52
except asyncio.TimeoutError:
53
return await message.channel.send('Se acabó el tiempo, la respuesta era {}.'.format(answer))
54
if int(guess.content) == answer:
55
await message.channel.send('Acertaste')
56
else:
57
await message.channel.send('Fallaste, la respuesta era {}.'.format(answer))
58
59
keep_alive()
60
client.run(os.getenv('TOKEN'))
61
Advertisement
Answer
Giving the full error log and the exact code run is good practice here.
This error indicates that the ‘on_message’ function was not given its ‘message’ argument. In this case, I would presume that you forgot to delete the ‘self’ argument when extracting this method from an object to make a stand-alone function out of it.