有没有一种方法可以自动回复/响应Discord机器人的消息(Mudae)?

时间:2020-09-20 04:20:16

标签: python discord discord.py

如果消息中包含所需的句子或值,我试图制作一个对Discord bot消息做出响应或反应的程序。

我想到的机器人是动漫角色gacha生成器Mudae。该程序应键入“ message.react(“:heart:”)“或单击默认的索赔反应(如果确实出现了我想要的字符)

1 个答案:

答案 0 :(得分:1)

您必须使用:

这是一个简单的例子:

bot = commands.Bot(command_prefix='!')

@bot.event
async def on_message(message):
    if not message.author.bot: #Check if author is not a bot
        return
    if ':heart:' in message.content:
        message.add_reaction('❤️')
    elif 'hello' in message.content:
        message.channel.send(f'Hi {message.author.mention} :)')

    await bot.process_commands(message)

PS:on_message个事件会覆盖命令,因此您需要await bot.process_commands(message)才能与on_message事件一起使用命令。