【发布时间】:2021-03-10 06:49:57
【问题描述】:
我正在为新服务器制作一个机器人,但我不断收到此错误,我对 python 和一般编码相当陌生,因此感谢任何帮助。
event() 缺少 1 个必需的位置参数:'coro' 错误 discord.py
当我发帖时,我的意思是说我的帖子主要是代码,所以我只是随机输入内容,直到它允许我发布为止。我有一只很酷的狗,他很可爱,而且他是有史以来最优秀的男孩:)
下面是我收到错误的代码
@client.event
async def on_ready():
print('We have logged in as {0.user}'
.format(client))
下面是我的完整代码
import discord
client = discord.Client
@client.event
async def on_ready():
print('We have logged in as {0.user}'
.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('>Hello Sylas'):
await message.channel.send('Hello there!')
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('>Is Dobbie cool?'):
await message.channel.send('Yes, he is the goodest boy!')
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('>Hey Sylas'):
if str(message.author) in ["Trax#8949"]:
await message.channel.send('Hey Trax!')
@client.event
async def on_message(message):
if message.author == client.user:
return
async def on_message(message):
if message.content.startswith('>'):
async def ban(ctx, member : discord.Member, *, reason = None):
await member.ban(reason = reason)
client.run('my token :)')
【问题讨论】:
-
欢迎来到 Stack Overflow!为了尽快获得高质量的回复,请不要为了通过问题内容要求而输入乱码。虽然你的狗看起来不错,但它根本没有帮助,详细描述你的问题会更有用。这样,也没有必要发布整个代码,因为 Stack Overflow 需要最少的代码来重现问题。
-
你有很多 on_message 函数..????也许您应该首先将它们全部放在功能上,然后看看它是否有效
-
尝试客户端 = discord.Client()
-
参考@Dominik 帖子末尾链接的帖子,我强烈建议使用 discord.ext.commands 机器人而不是 discord.client()。我现在将它用于我的机器人,它使事情变得非常简单。很明显,您需要一堆不同的 on_messages 来拆分您的代码。您可以使用链接帖子中提到的听众来做到这一点。如果您希望命令仍然有效(如果有的话),请确保将
await bot.process_commands(message)放在原始 on_message 的末尾。
标签: python discord.py