Python event()缺少1个必需的位置参数:';科罗';错误discord.py
我正在为一个新的服务器制作一个机器人,我不断地遇到这个错误,我对python和一般的编码都是相当陌生的,所以非常感谢您的帮助 event()缺少1个必需的位置参数:“coro”error discord.py 当我发布这篇文章的时候,这意味着我的文章看起来大部分是代码,所以我只需要输入随机的东西,直到它允许我发布它。我有一只非常酷的狗,它非常可爱,是有史以来最棒的男孩:) 下面是我得到错误的代码Python event()缺少1个必需的位置参数:';科罗';错误discord.py,python,discord.py,Python,Discord.py,我正在为一个新的服务器制作一个机器人,我不断地遇到这个错误,我对python和一般的编码都是相当陌生的,所以非常感谢您的帮助 event()缺少1个必需的位置参数:“coro”error discord.py 当我发布这篇文章的时候,这意味着我的文章看起来大部分是代码,所以我只需要输入随机的东西,直到它允许我发布它。我有一只非常酷的狗,它非常可爱,是有史以来最棒的男孩:) 下面是我得到错误的代码 @client.event async def on_ready(): pr
@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 :)')
消息上的多个
事件将无效
一次只能有一个事件,因此必须合并这些事件。这看起来像这样:
client=discord.client()#添加了括号
@客户端事件
异步def on_消息(消息):
如果message.author==client.user:
返回
如果message.content.startswith('>Hey Sylas'):
如果[“Trax#8949”]中的str(message.author)]:
等待消息。频道。发送('Hey Trax!')#第一个事件
[缩短]
如果message.content.startswith('>ban'):
等待成员。禁止(原因=原因)#最后一个事件
您可以有多个client.command()
“函数”,但这不计入事件
一篇解释得很好的帖子:试试这个:
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
elif message.content.startswith('>Hello Sylas'):
await message.channel.send('Hello there!')
elif message.content.startswith('>Is Dobbie cool?'):
await message.channel.send('Yes, he is the goodest boy!')
elif message.content.startswith('>Hey Sylas'):
if str(message.author) == "Trax#8949":
await message.channel.send('Hey Trax!')
elif message.content.startswith('>ban'): # You should restrict that to specific roles
await member.ban(reason = reason)
client.run('now its my token :)')
我所做的:
- 将所有的
放在一个的
- 更改为“禁止”
,而不是在其中使用未调用的函数
”更改为“=='Trax'”
elif
s欢迎使用堆栈溢出!为了尽快得到高质量的回复,请不要仅仅为了通过问题内容要求而输入胡言乱语。虽然你的狗看起来很好,但它一点帮助都没有,更详细地描述你的问题会有用得多。这样,也就没有必要发布全部代码,因为堆栈溢出只需要很少的代码就可以重现问题。您对消息函数有了一些了解。try client=discord.client()引用@Dominik文章末尾链接的帖子,我强烈建议使用discord.ext.commands bot而不是discord.client()。我现在把它用在我的机器人上,它让事情变得简单多了。很明显,您需要一组不同的on_消息来分割代码。您可以使用链接帖子中提到的侦听器来实现这一点。只要确保在原始on_消息的末尾放置
wait bot.process_命令(消息)
,如果您希望命令仍能工作(如果有)。