【发布时间】:2021-05-16 16:51:12
【问题描述】:
我让我的机器人为每台服务器设置一个特定的前缀。我希望它能够通过使用 {prefix}help 来说明它用于该服务器的前缀。下面是我的前缀代码。
def get_prefix(client, message):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
return prefixes[str(message.guild.id)]
bot = commands.Bot(command_prefix=(get_prefix), intents=discord.Intents.all())
bot.remove_command("help")
这里是改前缀。
@bot.command(pass_context=True)
@commands.has_permissions(administrator=True)
async def changeprefix(ctx, prefix):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
prefixes[str(ctx.guild.id)] = prefix
with open('prefixes.json', 'w') as f:
json.dump(prefixes, f, indent=4)
await ctx.send(f'Prefix changed to: {prefix}')
这是我必须显示服务器正在使用的当前前缀的代码。这只是我的帮助命令的一部分。
embed.add_field(name="Current Prefix", value=f'The current prefix for this server is {get_prefix}', inline=False)
embed.set_footer(text="I'm strongly recommened for FAMILY FRIENDLY servers!")
await ctx.send(embed=embed)
我问我怎样才能让机器人说,“这个服务器的前缀是 {prefix}
【问题讨论】:
-
你为什么不将参数传递给
{get_prefix}? -
因为我还是新手,我真的不知道该怎么做。对不起
-
你声明了一个带有两个参数的函数
def get_prefix(client, message):client&message。为了显示函数在您的嵌入中返回的内容,您必须提供这两个参数。喜欢f'The current prefix for this server is {get_prefix(arg1,arg2)}' -
所以需要
f'The current prefix for this server is {get_prefix(client, message)}'吗? -
可能会解决它
标签: python discord discord.py