discord.py仅运行某些齿轮

2024-09-30 02:17:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在为我的discord机器人编程,我想在您向机器人发送DM时设置一个不同的命令集。我有一个DMcog和一个CHANNELScog。在myevent.on_message中,我的代码是:

if message.channel.id in _allowed_channels:
    await bot.process_commands(message)

有没有办法做到这一点:

if message.guild == None: # Direct messages
    await DM.process_commands(message)
else:
    await CHANNELS.process_commands(message)

谢谢你的帮助


Tags: 代码messageifon编程机器人dmawait
1条回答
网友
1楼 · 发布于 2024-09-30 02:17:16

我知道了! discord.ext.commands有一个复选框:

from discord.ext import commands
#Code...
@bot.command()
@commands.dm_only() #The Check
async def _cmd(self, ctx):
    #Code...

您甚至可以使用cog_检查:

class MyCog(commands.Cog):
    #Code...
    async def cog_check(ctx):
        return True
    #Code...

相关问题 更多 >

    热门问题