How to create a simple bot that auto-reacts to messages containing a certain trigger sentence?

前端 未结 2 2020
隐瞒了意图╮
隐瞒了意图╮ 2020-12-11 12:15

I\'m setting up a Discord server for me and my friends, and I\'m in need of a bot able to add 20 reactions to any message in which a certain trigger phrase was typed. I used

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-11 12:59

    You're looking at old tutorials. Client.add_reaction was moved to Message.add_reaction in discord.py 1.0

    The functionality you describe could look something like:

    default_emojis = [
        "\N{GRINNING FACE}",
        "\N{KEYCAP DIGIT ONE}"
    ]
    
    custom_emojis = [
        "war_tank"
    ]
    
    async def react(message):
        for emoji in default_emojis:
            await message.add_reaction(emoji)
        for emoji in message.guild.emojis:
            if emoji.name in custom_emojis:
                await message.add_reaction(emoji)
    
    @bot.event
    async def on_message(message):
        if message.author == bot.user:
            return
        if "react to me" in message.content.lower():
            await react(message)
    

提交回复
热议问题