如何在私人DMS中使用消息应用程序命令(上下文菜单命令)。 Pycord/discord.py

问题描述 投票:0回答:1
@commands.message_command(
        name="Remind Me"
    )
    async def message_com(self, ctx, message):
        view = util.reminderInteraction.ReminderSelectView(
            self.process_reminder,
            ctx=ctx,
            message_content=message.content,
            message_by=message.author.global_name,
        )
        await ctx.respond(view=view, ephemeral=True)

这仅显示在公会和机器人 dm 中,我希望也能够在我的 dm 中与其他用户一起使用此命令。

我在官方discord api 文档中看到了一些上下文和集成类型,也许与此相关,但 pycord 没有。

discord discord.py pycord
1个回答
0
投票

此功能现已随 py-cord 2.6 一起发布。您可以使用

pip install py-cord==2.6
安装它。

这里是一个示例代码,取自官方示例

import discord

# debug_guilds must not be set if we want to set contexts and integration_types on commands
bot = discord.Bot()


@bot.slash_command(
    # Can only be used in private messages
    contexts={discord.InteractionContextType.private_channel},
    # Can only be used if the bot is installed to your user account,
    # if left blank it can only be used when added to guilds
    integration_types={discord.IntegrationType.user_install},
)
async def greet(ctx: discord.ApplicationContext, user: discord.User):
    await ctx.respond(f"Hello, {user}!")


@bot.slash_command(
    # This command can be used by guild members, but also by users anywhere if they install it
    integration_types={
        discord.IntegrationType.guild_install,
        discord.IntegrationType.user_install,
    },
)
async def say_hello(ctx: discord.ApplicationContext):
    await ctx.respond("Hello!")


# If a bot is not installed to a guild and the channel has the `USE_EXTERNAL_APPS`
# permission disabled, the response will always be ephemeral.


bot.run("TOKEN")
© www.soinside.com 2019 - 2024. All rights reserved.