【发布时间】:2021-02-08 15:44:49
【问题描述】:
我正在尝试在 discord.py 中编写一个仅响应命令的 Discord 机器人,例如当您键入 =!firewall 时,它会显示 Hello!这是我的代码:
import discord
from discord.ext import commands
TOKEN = ('')
client = discord.Client()
bot = commands.Bot(command_prefix='=!')
@bot.event
async def on_ready():
print('Bot ready')
@bot.event
async def on_message(message):
if message.author == client.user:
return
@bot.command(pass_context=True)
async def chickennuggets(ctx):
await message.channel.send("Hello!")
await bot.process_commands(message)
bot.run(TOKEN)
但是,当我尝试在 Discord 中使用 =!firewall 运行命令时,控制台会返回:
Ignoring exception in on_message
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "/Users/pixdoet/Code/python/firewall/bottest.py", line 19, in on_message
async def chickennuggets(ctx):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/discord/ext/commands/core.py", line 1257, in decorator
self.add_command(result)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/discord/ext/commands/core.py", line 1143, in add_command
raise CommandRegistrationError(command.name)
discord.ext.commands.errors.CommandRegistrationError: The command chickennuggets is already an existing command or alias.
很明显,chickennuggets 不是默认命令,也不是 Python 中任何其他库使用的命令。我已经在互联网上搜索过这个但没有用。请帮忙。谢谢!
【问题讨论】:
标签: python discord discord.py