我在discord.py的on_message事件中收到TypeError
我收到以下错误:
Traceback (most recent call last):
File "main.py", line 41, in <module>
@bot.event()
TypeError: event() missing 1 required positional argument: 'coro'
我的代码:
主文件
#------importing packages
import keep_alive
import os
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix = '-', case_insensitive=True)
my_token = os.environ['Token']
#------When bot is online
@bot.event
async def on_ready():
#status
#playing game status
await bot.change_presence(activity=discord.Game(
name=f'On {len(bot.guilds)} Servers | -help'))
print('Bot is Ready')
@bot.event()
async def on_message(message):
# if message.content.startswith(bot.user.mentioned_in(message)):
# await message.channel.send('My prefix is `-`')
if message.content == ('hello'):
await message.channel.send('Hello i am bot')
initial_extensions = ['math1', 'mod', 'weather', 'fun1', 'help']
if __name__ == '__main__':
for extension in initial_extensions:
bot.load_extension(extension)
#ping latency....
@bot.command()
async def ping(ctx):
await ctx.send(f'Pongn{round(bot.latency * 1000)}ms')
#------Running the bot
keep_alive.keep_alive()
bot.run(my_token)
我没有多个on_message事件。on_messagemain.py 中只有一个事件。on_message任何其他文件中也没有其他事件。
注意:如果您想查看我所有的其他文件及其代码,请查看此链接
回答
bot.event应该不叫
@bot.event # without the parenthesis
async def on_message(message):
...
THE END
二维码