如何将 discord.py 帮助命令放入嵌入中?

时间:2023-05-11
本文介绍了如何将 discord.py 帮助命令放入嵌入中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

所以,我目前有一个使用 discord.py 运行的 discord 机器人,如您所知,discord.py 带有自己的帮助命令(所以我不必自己制作).它非常有用,我将我的命令分成了 cogs/categories.它确实有助于简化,因为现在我不必编写自己的帮助命令.

So, I currently have a discord bot running with discord.py, and as you know, discord.py comes with its own help command (so I don't have to make my own). It's very useful, and I have my commands separated into cogs/categories. It really helps with simplicity, because now I don't have to write my own help command.

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

The problem is, when I run the help command, it comes to me in a giant code block, like so: I have heard some complaints from users that this isn't exactly visually appealing, and as I add more commands, it fills up the screen. Is there simple way (without writing my own help command) to move all of this onto an embed? Maybe copy the output of this help command, and move that onto an embed? If not, it's ok, I'll write my own help command, but I'm just trying to look for a simple way to do this without getting my hands dirty coding. As always, thank you in advance.

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

In case it is needed, here is sample from my code:

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

Here is a simple embed implementation I threw together inheriting from 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()

这篇关于如何将 discord.py 帮助命令放入嵌入中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:在单独的线程中执行 run_coroutine_threadsafe 下一篇:如何创建一个新的私人文本频道并添加 2 个人?

相关文章