discord.py запустить только определенный Cog - PullRequest
0 голосов
/ 23 марта 2020

Я программирую своего бот-диска и хочу, чтобы вы отправили DM другому боту. У меня есть DM винтик и CHANNELS винтик. В моем event.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)

Спасибо за вашу помощь!

1 Ответ

0 голосов
/ 24 марта 2020

Я понял это! На discord.ext.commands есть проверка:

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

Вы даже можете использовать cog_check:

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