event() 缺少 1 个必需的位置参数:"Coro"错误 discord.py



我正在为新服务器制作一个bot,我一直得到这个错误,我对python和编码相当陌生,所以任何帮助都很感激。

event()缺少1个必需的位置参数:'coro' error 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 :)') 

多个on_message事件将工作。

你一次只能有一个事件,所以你必须合并这些事件。它看起来像这样:

client = discord.Client() # Added brackets
@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!') # First event
[Shortened]
if message.content.startswith('>ban'):
await member.ban(reason = reason) # Last event

您可以有多个client.command()"功能"但这并不包括事件。

一篇解释得很好的文章:为什么多个on_message事件不能工作

试试这个:

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 :)')

我做了什么:

  • 把所有on_message放到一个on_message
  • 更改为">ban"而不是在其中使用未调用的函数
  • "in ['Trax']"更改为"== 'Trax'"
  • 添加elifs

最新更新