[英]TypeError. on_message() missing 1 required positional argument: 'ctx'
[英]TypeError: on_message() missing 1 required positional argument: 'message'
您好,我嘗試使用 Discord.py 制作一個機器人,並嘗試在我的代碼中實現此功能,但標題中出現錯誤。 我還不知道很多 Python 而且我很新,所以我不知道是什么導致了這個錯誤。 任何幫助都會很棒,謝謝!
import discord
import os
import requests
import json
import random
from keep_alive import keep_alive
import asyncio
client = discord.Client()
basura = ["rezero"]
verdad = [
"es una mierda",
"no debería existir",
"VIVA K-ON",
]
def get_quote():
response = requests.get("https://zenquotes.io/api/random")
json_data = json.loads(response.text)
quote = json_data[0]['q'] + " - " + json_data[0]['a']
return (quote)
@client.event
async def on_ready():
print ('We logged in as {0.user}'.format(client))
@client.event
async def on_message(self,message):
if message.author.id == self.user.id:
return
if message.content.startswith('Hola'):
await message.channel.send('Sup nerd')
if message.content.startswith('Inspirame'):
quote = get_quote()
await message.channel.send(quote)
if any(word in message.content for word in basura):
await message.channel.send(random.choice(verdad))
if message.content.startswith('^Guess'):
await message.channel.send('Adivina un numero del 1 al 10')
def is_correct(m):
return message.content.author == message.author and m.content.isdigit()
answer = random.randint(1,10)
try:
guess = await self.wait_for('message',check=is_correct,timeout=5.0)
except asyncio.TimeoutError:
return await message.channel.send('Se acabó el tiempo, la respuesta era {}.'.format(answer))
if int(guess.content) == answer:
await message.channel.send('Acertaste')
else:
await message.channel.send('Fallaste, la respuesta era {}.'.format(answer))
keep_alive()
client.run(os.getenv('TOKEN'))
在這里提供完整的錯誤日志和確切的代碼運行是一種很好的做法。
此錯誤表明未給出“on_message”function 的“消息”參數。 在這種情況下,我假設您在從 object 中提取此方法以制作獨立的 function 時忘記刪除“self”參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.