![](/img/trans.png)
[英]On_Reaction_Add() with messages sent in On_Ready() Discord.PY
[英]Reaction to messages not working (discord.py)
如果消息是由某個作者發送的,我希望機器人對消息做出反應。
代碼:
@bot.event
async def on_message(message):
if message.author.id == '356268235697553409':
await message.add_reaction('👍')
await message.add_reaction('👎')
await message.add_reaction('😐')
我試過了,但它沒有用,它甚至沒有顯示任何錯誤,我做錯了什么? 謝謝!
discord.Member.id
返回一個int
類型的值。 這意味着您無法將str
值與discord.Member.id
值進行比較。 你只需要做:
if message.author.id == 356268235697553409:
ID 始終是整數,您將 int 與字符串進行比較,以修復它:
if message.author.id == 356268235697553409:
# ...
首先,正如其他用戶已經提到的那樣,您不能將int
與string.
正確的語法是:
if message.author.id == 356268235697553409:
# Rest of your code here
其次,您正在做的是覆蓋默認提供的on_message
命令。 這會禁止運行任何命令,這可能是問題的根本原因。 使用on_message
的正確方法是將以下內容添加到on_message
的末尾:
@bot.event
async def on_message(message):
# Your code
await bot.process_commands(message)
或者,您將on_message
邏輯放入偵聽器中(無需手動調用bot.process_commands()
。這樣做是為了允許多個異步操作來響應消息。例如:
@bot.listen('on_message')
async def whatever_you_want_to_call_it(message):
# do stuff here
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.