discord.py斜杠命令在cogs中不起作用

jm2pwxwz  于 2021-09-08  发布在  Java
关注(0)|答案(1)|浏览(392)

我正在构建一个discord机器人,希望在cogs中使用斜杠命令,但这些命令不显示也不起作用,下面是代码


## cog

guild_ids = [858573429787066368, 861507832934563851]

class Slash(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @cog_ext.cog_slash(name="test", guild_ids=guild_ids, description="test")
    async def _test(self, ctx: SlashContext):
        embed = Embed(title="Embed Test")
        await ctx.send(embed=embed)

## bot

bot = discord.ext.commands.Bot(command_prefix = "!")

@bot.event
async def on_ready():
  print(f'{bot.user} has logged in.')
  bot.load_extension('slash_music_cog')

bot.run("bot-token")
zzlelutf

zzlelutf1#

您需要稍微修改 bot.py 要初始化的文件 SlashCommand 对象查看库中的自述文件,了解使用cogs的机器人的更详细示例。


# bot

from discord_slash import SlashCommand

bot = discord.ext.commands.Bot(command_prefix = "!")
slash = SlashCommand(bot)

@bot.event
async def on_ready():
  print(f'{bot.user} has logged in.')
  bot.load_extension('slash_music_cog')

bot.run("bot-token")

相关问题