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

前端 未结 2 2016
隐瞒了意图╮
隐瞒了意图╮ 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:49

    First of all, you're going to want to change your token now, if you haven't already.

    You're using syntax from a version of discord.py, v0.16, that isn't supported anymore.
    See the guide for migrating to v1, specifically the Models are Stateful section.
    You should use Message.add_reaction rather than Bot.add_reaction.

    0 讨论(0)
  • 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)
    
    0 讨论(0)
提交回复
热议问题