【发布时间】:2021-02-03 18:20:32
【问题描述】:
我正在尝试制作一个帮助命令,该命令将机器人的当前服务器前缀发送到嵌入中。我在试图弄清楚如何编写代码时遇到了一些麻烦,我希望得到一些帮助。我试过这样做:
@bot.command()
async def help(ctx):
embed = discord.Embed(
title='Help', description='', colour=discord.Colour.blue())
embed.set_footer(text='Have fun!')
prefix = command_prefix
embed.add_field(
name='Prefix',
value=
f'The current prefix for this server is {prefix}',
inline=True)
await ctx.send(embed=embed)
但是,当我这样做时,我得到了错误:
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NameError: name 'command_prefix' is not defined
我不确定我做错了什么,任何帮助将不胜感激。 (:
【问题讨论】:
-
你需要定义
command_prefix来做prefix = command_prefix。 -
这样,
async def help(ctx, command_prefix):? -
不,这不是您需要的,您需要将这些前缀自动保存并发送到一个文件中。
-
那我可以用json数据来显示吗?
-
是的,如果你为多个公会做这个机器人,或者你想打印出前缀,或者你想用命令更改前缀,你需要保存它。
标签: python command discord discord.py discord.py-rewrite