【问题标题】:discord.py :: How can I get my bot to react to it's own message?discord.py :: 我怎样才能让我的机器人对它自己的消息做出反应?
【发布时间】:2021-08-29 07:15:21
【问题描述】:

在我的 on_message 下我有这个;

 if message.channel.id == 809991898722861137:
        emoji = client.get_emoji(830070201885130823)
        await message.add_reaction(emoji)
        emoji = client.get_emoji(830070201722601523)
        await message.add_reaction(emoji)
        emoji = client.get_emoji(830070202091175976)
        await message.add_reaction(emoji)
        emoji = client.get_emoji(830070201654837249)
        await message.add_reaction(emoji)

但每当我执行命令让我的机器人发送消息时,反应只会发布在我的消息上,而不是我的机器人。

有没有办法让我的机器人消息也能得到反应?

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    我猜你希望对你的消息和机器人的消息都有反应。

    import discord
    from discord.ext import commands
    import asyncio
    
    client = commands.Bot(command_prefix=".")
    
    @client.event
    async def on_message(message):
        if message.channel.id == 809991898722861137:
            emoji = '\N{THUMBS UP SIGN}' # Thumbs up emoji
            await message.add_reaction(emoji)
        await client.process_commands(message)
    

    或者,如果您希望仅在机器人上做出反应:

    import discord
    from discord.ext import commands
    import asyncio
    
    client = commands.Bot(command_prefix=".")
    
    @client.event
    async def on_message(message):
        if message.channel.id == 809991898722861137:
            if message.author == client.user: # Check if the message came from the bot
                emoji = '\N{THUMBS UP SIGN}' # Thumbs up emoji
                await message.add_reaction(emoji)
            else:
                # Do something else
        await client.process_commands(message)
    

    【讨论】:

    • 感谢您的回复!我尝试了您作为示例列出的顶级代码,但不幸的是它仍然没有对自己的消息做出反应。相反,当我执行命令让机器人发送消息时,它现在发送消息两次。知道这是为什么吗?
    • 我不确定它重复该消息的原因,对不起。奇怪的是代码在我这边工作......你可以尝试在if message.channel.id == 809991898722861137: 之后添加if message.author != client.user or message.author == client.user: 吗?我尝试了这个并得到了相同的结果。
    猜你喜欢
    • 2021-08-04
    • 2020-11-07
    • 1970-01-01
    • 1970-01-01
    • 2018-12-15
    • 1970-01-01
    • 2020-12-05
    • 2022-01-05
    • 2020-07-29
    相关资源
    最近更新 更多