如何在私人DM中使用Pycord/discord.py的消息应用命令
解决Pycord消息命令无法在用户私人DM中使用的问题
你可以通过为消息命令指定上下文类型集合来实现需求,Pycord(2.4.0及以上版本)已经支持对应配置,无需绕开框架直接调用API。
修改后的代码示例
首先导入上下文类型枚举:
from discord import ApplicationCommandContextType
然后更新消息命令的装饰器配置:
@commands.message_command( name="Remind Me", contexts={ ApplicationCommandContextType.BOT_DM, ApplicationCommandContextType.GUILD, ApplicationCommandContextType.PRIVATE_CHANNEL } ) 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)
关键说明
ApplicationCommandContextType.PRIVATE_CHANNEL对应用户之间的私人DM场景,将其加入contexts参数后,命令就会在该场景下显示。- 若当前Pycord版本不支持该参数,直接升级到最新稳定版即可解决兼容性问题。
内容的提问来源于stack exchange,提问作者IAM々Unknown
相关产品推荐
相关产品推荐

