我想在python重写中编写不和bot,以检查仅在通道中发送的嵌入内容



我唯一能想到的就是这个但是它也检查正常消息

我正在使用discord.py重写1.6.0版本

import discord
client = discord.Client()
@client.event
async def on_ready():
print("Bot is ready")
@client.event
async def on_message(message):
if message.content == "Blah Blah"
print ("I got  that")
client.run(BOT_TOKEN)

您可以检查消息是否有嵌入,并使用以下代码遍历消息的所有嵌入:

import discord
client = discord.Client()
@client.event
async def on_ready():
print("Bot is ready")
@client.event
async def on_message(message):
for embed in message.embeds:
# do something here with the embed
client.run(BOT_TOKEN)

注意,Embed有一个非常具体的结构,你可以在嵌入文档中找到,以防万一你想对嵌入中的数据做一些事情!

检查消息是否为嵌入,您可以访问其中的任何元素。试一下:

import discord
client = discord.Client()
@client.event
async def on_ready():
print("Bot is ready")
@client.event
async def on_message(message):
embeds = message.embeds
if not embeds: #checks if message was an embed or not
return
else:
embed = (message.embeds)[0]
print(embed.title) # you can access its other elements as well

除了打印嵌入的标题,您还可以执行类似print(embed.description)的操作。

您可以执行以下命令检查嵌入描述或标题

import discord
client = discord.Client()
@client.event
async def on_ready():
print("Bot is ready")
@client.event
async def on_message(message):
for embed in message.embeds:
if embed.title or embed.description == 'Blah Blah':
await message.channel.send('I got that')
client.run(BOT_TOKEN)

最新更新