【发布时间】:2021-11-05 11:35:33
【问题描述】:
这是我的代码
main.py
import discord
from discord.ext import commands
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
client.load_extension(f'cogs.{filename[:-3]}')
@client.event
async def on_message(message):
if client.user == message.author:
return
# The message logging command comes here
await client.process_commands(message)
client.run("NeverShareTheToken")
./cogs/botinfo.py
import discord
from discord.ext import commands
from json import load as loadjson
class BotGeneralCommands(commands.Cog):
def __init__(self, client: commands.Bot):
self.client = client
self.botconfigdata = loadjson(open("config.json", "r"))
self.bot_inv_link = self.botconfigdata["invite-link"]
@commands.command(aliases=["invite", "botlink", "invitelink"])
async def invite(self, ctx):
await ctx.send("```Hey there! Make sure you have me in your server too! Bot Invite link:```" + str(self.bot_inv_link))
def setup(client: commands.Bot):
client.add_cog(BotGeneralCommands(client))
ERROR I GET, WHEN I RUN THE FILE
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 618, in _load_from_module_spec
setup(self)
File "/home/runner/Main-Discord-Bot-of-ZeaCeR5641/cogs/botinfo.py", line 79, in setup
client.add_cog(BotGeneralCommands(client))
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 507, in add_cog
cog = cog._inject(self)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/cog.py", line 413, in _inject
raise e
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/cog.py", line 407, in _inject
bot.add_command(command)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 1155, in add_command
raise CommandRegistrationError(alias, alias_conflict=True)
discord.ext.commands.errors.CommandRegistrationError: The alias invite is already an existing command or alias.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "main.py", line 523, in <module>
client.load_extension(f'cogs.{filename[:-3]}')
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 678, in load_extension
self._load_from_module_spec(spec, name)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 623, in _load_from_module_spec
raise errors.ExtensionFailed(key, e) from e
discord.ext.commands.errors.ExtensionFailed: Extension 'cogs.botinfo' raised an error: CommandRegistrationError: The alias invite is already an existing command or alias.
我确实检查了这个不和谐机器人和这个命令的所有其他齿轮(invite 只存在于这里......)。为什么我总是收到这个错误?
我做了什么: 我注释掉了那段代码,再次启动机器人,它给了我同样的错误,但命令名称不同,我注释了所有显示的命令 11 次(即使它们只在一个地方定义)。但我一直收到这个错误!
这个机器人有超过 240 条命令,它和问题有什么关系吗?
我能做什么?
【问题讨论】:
标签: python python-3.x discord discord.py