本文介紹了(discord.py) 有沒有辦法讓 on_message 事件查看嵌入式消息而不是普通消息?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我正在嘗試制作一個 discord.py 機(jī)器人,它在帶有 on_message 事件的每條消息中查找給定的關(guān)鍵字.雖然這適用于普通文本,但我無法讓它與我需要的嵌入式消息一起使用.有沒有辦法做到這一點?
I'm trying to make a discord.py bot that looks for given keywords in every message with the on_message event. While this works great with normal text, I can't get it to work with an embedded message which is what I need. Is there any way to do this?
推薦答案
message.embeds
將為您提供 Embed
對象的列表.您可以嘗試類似
message.embeds
will get you a list of Embed
objects. You might try something like
def check_all_message(check_for, message):
if check_for in message.content:
return True
for e in message.embeds:
if any(item and check_for in item for item in (e.title, e.footer, e.description)):
return True
if e.fields:
for field in e.fields:
if check_for in field.name or check_for in field.value:
return True
return False
@bot.event
async def on_message(message):
if message.author == bot.user:
return
if check_all_message("apple", message):
await bot.send_message(message.channel, 'You said "apple"!')
這篇關(guān)于(discord.py) 有沒有辦法讓 on_message 事件查看嵌入式消息而不是普通消息?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!