python - 如何将 discord.py help 命令放入嵌入中?

标签 python discord discord.py

因此,我目前有一个运行 discord.py 的 discord 机器人,如您所知,discord.py 带有自己的帮助命令(所以我不必自己创建)。它非常有用,我将我的命令分成齿轮/类别。它确实有助于简化,因为现在我不必编写自己的帮助命令。

问题是,当我运行帮助命令时,它出现在一个巨大的代码块中,如下所示: enter image description here 我听到一些用户提示说这在视觉上并不吸引人,而且当我添加更多命令时,它会填满屏幕。有没有简单的方法(无需编写我自己的帮助命令)将所有这些移动到嵌入中?也许复制此帮助命令的输出,并将其移动到嵌入中?如果没有,没关系,我会编写自己的帮助命令,但我只是想寻找一种简单的方法来执行此操作,而不会弄脏我的代码。一如既往,提前感谢您。

如果需要,这里是我的代码示例:

import discord
from discord.ext import commands, tasks

TOKEN = "INSERT TOKEN HERE"
client = commands.Bot(command_prefix="wurf ", case_insensitive=True)

#Utility Category
class Utility(commands.Cog):
    def __init__(self, client):
        self.client = client
        
    @commands.command(
        help="Shows the ping/latency of the bot in miliseconds.",
        brief="Shows ping."
    )
    async def ping(self, ctx):
        if round(client.latency * 1000) <= 50:
            embed=discord.Embed(title="PING", description=f":ping_pong: Pingpingpingpingping! The ping is **{round(client.latency *1000)}** milliseconds!", color=0x44ff44)
        elif round(client.latency * 1000) <= 100:
            embed=discord.Embed(title="PING", description=f":ping_pong: Pingpingpingpingping! The ping is **{round(client.latency *1000)}** milliseconds!", color=0xffd000)
        elif round(client.latency * 1000) <= 200:
            embed=discord.Embed(title="PING", description=f":ping_pong: Pingpingpingpingping! The ping is **{round(client.latency *1000)}** milliseconds!", color=0xff6600)
        else:
            embed=discord.Embed(title="PING", description=f":ping_pong: Pingpingpingpingping! The ping is **{round(client.latency *1000)}** milliseconds!", color=0x990000)
        await ctx.send(embed=embed)
client.add_cog(Utility(client))
client.run(TOKEN)

最佳答案

您必须使用 Bot.help_command 覆盖默认帮助命令

这是我从 MinimalHelpCommand 继承而来的一个简单的嵌入实现

class MyHelpCommand(commands.MinimalHelpCommand):
    async def send_pages(self):
        destination = self.get_destination()
        e = discord.Embed(color=discord.Color.blurple(), description='')
        for page in self.paginator.pages:
            e.description += page
        await destination.send(embed=e)

client.help_command = MyHelpCommand()

关于python - 如何将 discord.py help 命令放入嵌入中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64092921/

相关文章:

python - 在 Matplotlib 的条形图上显示负值的问题

python - TypeError : tuple indices must be integers or slices, 命令中不是 str

javascript - DiscordJS - 从数组中嵌入随机图像

python - Discord Python - 私有(private) channel (DM) 中的 bot.wait_for_message

python - 我如何将两个嵌入合二为一?不和谐.py

python - 使用 aiohttp 在 Python 中从内存上传 multipart/form-data

python - 如何从 python 脚本查找计算机中某个目录是否存在(我不知道路径)

python - Pip --user 将包安装到 Windows 10 上的默认用户目录

javascript - 使用 Python 或 JavaScript 的交互式 3D 图形

node.js - Discord.js client.on