#python #discord #discord.py
Вопрос:
Я получаю следующую ошибку:
Traceback (most recent call last):
File "main.py", line 41, in <module>
@bot.event()
TypeError: event() missing 1 required positional argument: 'coro'
Мой код:
main.py
#------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_message
событие, которое находится в main.py. В on_message
других файлах также нет другого события.
Примечание: Если вы хотите ознакомиться со всеми моими другими файлами и их кодом, пожалуйста, перейдите по этой ссылке
Ответ №1:
bot.event
не следует называть
@bot.event # without the parenthesis
async def on_message(message):
...