[英]discord.py not reaction on embed message
所以我正在嘗試編寫一個命令,當它看到帶有“Diona”的消息時會做出反應
async def on_message(message):
channel = message.channel
emoji = '\N{THUMBS UP SIGN}'
if "Diona" in message.content:
await message.add_reaction(emoji)
當用戶發送“Diona”時,它正在對用戶起作用,但是當它來自帶有嵌入消息的機器人時,它不會對其做出反應。 我如何使它工作?
您可以通過遍歷message.embeds
並遍歷所有字段來獲取嵌入內容,獲取標題和描述:
@client.event
async def on_message(message):
all_data = ""
if len(message.embeds) > 0:
for embed in message.embeds: #loop through all embeds in the message
try: #I use try and except for every, because when the field is empty, TypeError is raised.
all_data = all_data + embed.description #get embed description
except TypeError:
pass
try:
all_data = all_data + embed.title #get embed title
except TypeError:
pass
for field in embed.fields: #loop through each field
try:
all_data = all_data + field.value #get value of field
except TypeError:
pass
try:
all_data = all_data + field.name #get name of field
except TypeError:
pass
if "Diona" in all_data: #test if Diona is in any of the data we got
await message.add_reaction(emoji)
if "Diona" in message.content:
await message.add_reaction(emoji)
參考:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.