python - 列出 discord.py Cog 中的命令
问题描述
使用 discord.py,您可以列出机器人的命令。这是最好的例证:
x = []
for y in client.commands:
x.append(y.name)
print(x)
一个特定的齿轮将如何做到这一点?
解决方案
您可以检查该命令属于哪个 cog Command.cog
。请注意,None
如果该命令不属于某个 cog,则会出现这种情况。
齿轮.py
from discord.ext import commands
class Test(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command()
async def foo(self, ctx):
await ctx.send('bar')
def setup(bot):
bot.add_cog(Test(bot))
僵尸软件
from discord.ext import commands
client=commands.Bot(command_prefix='!')
client.load_extension('cog')
@client.command()
async def ping(ctx):
await ctx.send('pong')
x = []
for y in client.commands:
if y.cog and y.cog.qualified_name == 'Test':
x.append(y.name)
print(x)
client.run('token')
推荐阅读
- python-3.x - 使三个数据帧的最大值索引相似
- html - 如何在嵌套 SVG 中设置“preserveAspectRatio”属性?
- google-apps-activity - 如何在 Google Drive Activity API 中过滤掉 MIMETYPE
- discord - discord.py bot 检测用户名更改
- node.js - fswin.node:1:2 - 错误:模块解析失败:意外字符 '�' (1:2)
- hosting - 如何找出我的网站托管在哪里
- encryption - onenssl 上的密文窃取
- css - Tailwind CSS 网格提供 3 行而不是 3 列,但仅适用于 grid-cols-6
- web - 亚马逊是否使用 CURL(或任何程序化方式)进行搜索?
- python-3.x - 如何删除使用滑块小部件添加的 axhline