【问题标题】:Is there a way to automatically reply/react to a Discord bot's message (Mudae)?有没有办法自动回复/响应 Discord 机器人的消息(Mudae)?
【发布时间】:2020-09-20 15:07:47
【问题描述】:

如果消息包含我想要的句子或值,我正在尝试制作一个程序来响应或响应 Discord 机器人的消息。

我想到的机器人是 Mudae,一个动漫人物扭蛋生成器。程序应键入“ message.react(":heart:")" 或如果确实出现了我想要的角色,请单击默认声明反应

【问题讨论】:

  • 这是可能的。只需检查您要查找的参数 - 机器人 (message.author.id) 和所需的值 (message.content)。

标签: python discord discord.py


【解决方案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 事件一起使用。

【讨论】:

    猜你喜欢
    • 2021-05-25
    • 2023-02-10
    • 2021-03-11
    • 2022-11-27
    • 2022-09-29
    • 2020-11-19
    • 2020-12-31
    • 2022-10-24
    相关资源
    最近更新 更多