#discord.py #bots
#discord.py #боты
Вопрос:
В настоящее время я пытаюсь исправить этот код. Я пытаюсь создать команду .shutdown, которая в основном выходит из бота и отключает бота. Я создал код, но, похоже, он не работает. Вот мой код. Помощь очень ценится; p
@client.command()
async def shutdown(ctx, *, reason):
if ctx.message.author.id(581457749724889102):
ctx.send('Bot is shutting down... ;(')
logs_channel = client.get_channel(825005282535014420)
logs_channel.send(f"Bot is being shutdown for: {reason}")
exit()
else:
ctx.send("I'm sorry, only officer grr#6609 can do that."
Заранее спасибо за помощь!
Редактировать:
вот моя ошибка
Ignoring exception in on_command_error
Traceback (most recent call last):
File "C:UsersUSERAppDataLocalProgramsPythonPython39-32libsite-packagesdiscordextcommandscore.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "c:UsersUSERDesktopdiscord bot folderNuova cartellaconnor.py", line 173, in shutdown
if ctx.message.author.id(581457749724889102):
TypeError: 'int' object is not callable
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:UsersUSERAppDataLocalProgramsPythonPython39-32libsite-packagesdiscordclient.py", line 343, in _run_event
await coro(*args, **kwargs)
File "c:UsersUSERDesktopdiscord bot folderNuova cartellaconnor.py", line 82, in on_command_error
raise error
File "C:UsersUSERAppDataLocalProgramsPythonPython39-32libsite-packagesdiscordextcommandsbot.py", line 902, in invoke
await ctx.command.invoke(ctx)
File "C:UsersUSERAppDataLocalProgramsPythonPython39-32libsite-packagesdiscordextcommandscore.py", line 864, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:UsersUSERAppDataLocalProgramsPythonPython39-32libsite-packagesdiscordextcommandscore.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: 'int' object is not callable
Комментарии:
1. Что именно не работает? Какие-нибудь ошибки?
Ответ №1:
Пожалуйста, всегда учитывайте await
свои функции. У вас также есть некоторые ошибки формирования и понимания в коде, возможно, взгляните еще раз на документы
Вы можете проверить, является ли пользователь, выполняющий команду, владельцем бота. Если это не так, конечно, появляется сообщение об ошибке.
Взгляните на следующий код:
@client.command()
@commands.is_owner() # Checks if the bot owner exectued the command
async def shutdown(ctx):
await ctx.send("Logging out.")
await client.logout() # Logging out
@shutdown.error
async def shutdown_error(ctx, error):
if isinstance(error, commands.NotOwner):
await ctx.send("You are not the owner of the bot.") # Error message
Что мы сделали?
await
отредактировал большинство функций.- Встроенная проверка, чтобы проверить, выполнил ли владелец команду.
- Встроенный обработчик ошибок, который выдаст сообщение, если не владелец попытается отключить бота.