繁体   English   中英

如何获取函数 Discord.PY 的结果?

[英]How to get the result of the function Discord.PY?

所以我有我的机器人,在我的帮助命令中,我想说服务器的前缀是什么。 我正在使用一个函数来执行此操作,因为我使用的是自定义服务器前缀。 发送的消息不是函数的结果,它只是给出了名称。 这是帮助命令:

@commands.group(invoke_without_command=True)
    async def help(self, ctx):

        embed = discord.Embed(title="Help",
        description=f"The prefix for this bot is `{get_prefix}` .\n"
                                          f"Use `{get_prefix}help <command>` for information about "
                                          f"that command. Use `{get_prefix}help <category>` for all "
                                          f"commands on that category.",
        olor=0x505050)

        embed.add_field(name="Moderation", 
        value="All moderation commands, such as kick or ban.",
        inline=False)
        embed.add_field(name="Fun",
        value="Fun commands to play around with, such as 8ball.",
        inline=False)
        embed.add_field(name="Miscellaneous",
        value="Miscellaneous commands such as bot information.",
        inline=False)

        await ctx.send(embed=embed)

这就是它发送的内容:

https://i.stack.imgur.com/rMsoI.png

如果需要,这是我的 get_prefix 函数:

def get_prefix(client, message):
    with open('prefixes.json', 'r') as f:
        prefixes = json.load(f)
    return prefixes[str(message.guild.id)]

除了修改默认的帮助命令外,有没有办法解决这个问题?

您需要实际调用该函数并传递必要的参数

prefix = get_prefix(self.client, ctx.message)  # or `self.bot`, however you named it

embed = discord.Embed(title="Help",
    description=f"The prefix for this bot is `{prefix}` .\n"
                f"Use `{prefix}help <command>` for information about "
                f"that command. Use `{prefix}help <category>` for all "
                f"commands on that category.",
    color=0x505050
)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM