代码之家  ›  专栏  ›  技术社区  ›  Olimpiia_ ART

我无法在私人消息中使用我的userbot斜线命令

  •  0
  • Olimpiia_ ART  · 技术社区  · 7 月前

    我可以在服务器上使用机器人的斜线命令,但不能在私人消息中使用。机器人的命令根本不会出现在选择菜单中。

    import discord
    from discord.ext import commands
    
    intents = discord.Intents.default()
    intents.message_content = True
    bot = commands.Bot(command_prefix="/", intents=intents)
    
    @bot.event
    async def on_ready():
        try:
            await bot.tree.sync()
            print(f"{bot.user.name} online")
        except Exception as e:
            print(f"Sync error: {e}")
    
    @bot.tree.command(name="ping")
    async def ping(ctx):
        await ctx.response.send_message("Pong", ephemeral=True)
        
    bot.run("TOKEN")
    
    1 回复  |  直到 7 月前
        1
  •  1
  •   Lia Milenakos    7 月前

    在disconfirm.py 2.4+中,您可以通过以下方式使斜线命令在DM和Group DM中可用:

    1. 允许使用以下命令将命令安装到用户配置文件中 @discord.app_commands.allowed_installs 装饰师,以及
    2. 允许在DM和GDM(后者被称为 private_channels )使用 @discord.app_commands.allowed_contexts 装饰师

    此示例允许在任何地方安装和使用命令:

    @discord.app_commands.allowed_installs(guilds=True, users=True)
    @discord.app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
    @bot.tree.command(name="ping")
    async def ping(ctx):
    

    @discord.app_commands.allowed_installs

    @discord.app_commands.allowed_contexts