如何使用discord bot命令和事件?

loading...


1

我需要制作一个机器人来监听服务器中写入的消息,同时接受命令 .

# Create the Discord client
client = discord.Client()
client = commands.Bot(command_prefix = '!')
client.remove_command('help')

@client.event
async def on_ready():
    print('ready')


@client.event                                               #ricerca messaggi 
async def on_message(message):
    # Ignore messages made by the bot
    if(message.author == client.user):
        return
    a = ''
    a += message.embeds[0]["description"]
    if a == 'abcdef':
        print(' aaaaa ')



@client.command()
async def hello():
    await client.say('hello')


client.run('token')

我怎样才能使它有效?我认为问题是机器人在第一个事件中继续循环...我读到了关于sub_process但我不明白如何使用它 .

loading...

1回答

  • 0

    您需要在on_message的末尾添加process_commands() . This is because overriding the default on_message forbids commands from running .

    @client.event                                               #ricerca messaggi 
    async def on_message(message):
        # Ignore messages made by the bot
        if(message.author == client.user):
            return
        a = ''
        a += message.embeds[0]["description"]
        if a == 'abcdef':
            await message.channel.send(' aaaaa ')
        await client.process_commands(message)
    
评论

暂时没有评论!