【发布时间】:2022-12-19 18:18:19
【问题描述】:
我设置了一个简单的文本命令来同步我的 discord 机器人中的所有命令。 (discord.py)出于某种原因,只有混合命令的文本部分有效。当我输入 o.sync 时,它说已同步 0 个命令,但 o.ping 命令有效。我是否遗漏了任何明显的错误?
import discord
from discord.ext import commands
from discord import app_commands
class Survey(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
@commands.Cog.listener()
async def on_ready(self):
print('Survey cog loaded.')
@commands.command()
async def sync(self, ctx) -> None:
fmt = await ctx.bot.tree.sync(guild=ctx.guild)
await ctx.send(
f"Synced {len(fmt)} commands to the current guild."
)
@commands.command()
async def unsync(self, ctx) -> None:
ctx.bot.tree.clear_commands(guild=ctx.guild)
sync_tree = await ctx.bot.tree.sync(guild=ctx.guild)
await ctx.send(
f"Unsynced {len(sync_tree)} commands to the current guild."
)
return
@commands.hybrid_command(name='ping', with_app_command=True)
async def help(self, ctx: commands.Context):
await ctx.send("pong", ephemeral=True)
async def setup(bot):
await bot.add_cog(Survey(bot), guilds=[discord.Object(id=874842871801479208)])
`
o.ping 命令显示混合命令正在运行,但斜杠命令根本没有出现在菜单中。
【问题讨论】:
标签: python discord.py