How to make discord python bot react to its own message?

蓝咒 提交于 2020-12-07 15:19:54

问题


Currently working on a small bot which sends an embed and I want it to react to itself but am unsure on how to do that. Any help?


回答1:


Get the message you want to react to and use Client.add_reaction()

For example, if you're reacting to an embed

msg = await bot.send_message(ctx.message.channel,embed=embed)
await bot.add_reaction(msg, "😮")



回答2:


If you have this in your code

if message.author == client.user:
    return

Your bot will not respond to itself, and it shouldn't respond to itself normally. A way around this would be to put any code you want to execute despite message.author == client.user above it. For instance:

# This will respond to itself
if (message.content.lower() == "!yell"):
    msg = "!yell"
    await client.send_message(message.channel, msg)

# This checks to see if the author is the client    
if message.author == client.user:
    return

# This will not respond to itself
if (message.content.lower() == "!yell2"):
    msg = "!yell"
    await client.send_message(message.channel, msg)

!yell will result in your bot talking to itself until it reaches the message threshold, however, !yell2 will not because it come after the section that checks whether or not it's the client.user.



来源:https://stackoverflow.com/questions/54173483/how-to-make-discord-python-bot-react-to-its-own-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!