【发布时间】:2021-10-07 14:57:09
【问题描述】:
我正在尝试让我的 Discord 机器人说出服务器设置的前缀。
这是前缀更改命令的代码。
@client.command(pass_context=True)
@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}')
这不是问题,问题是我试图让我帮助命令说出用户设置的特定前缀。我尝试让它读取 json 并从公会的 ID 中获取前缀,但这不起作用。
@client.command(aliases=["commands"])
async def help(ctx, cmd=None):
with open('prefixes.json', 'r') as f:
prefixes = json.load(f)
p = prefixes[ctx.guild.id]
embed=discord.Embed(color=0xff0080, description=
f"<:polylogo:894531390899642419> **Prefix** ``{p}``\nJoin our [Official Discord](https://discord.com)\n\n**Moderation (7)** \n``{p}Warn, {p}Warnings, {p}Mute, {p}Unmute, {p}Kick, {p}Ban, {p}Unban``\n\n**Utility / Miscellaneous (5)** \n ``{p}Ping, {p}Avatar, {p}Info, {p}Sinfo, {p}Help, {p}Members``")
await ctx.send(embed=embed)
【问题讨论】: