是否有一种方法可以检查嵌入是否是特定的颜色?



这是我在绞尽脑汁和烦恼之后想出的办法,但你瞧,它不起作用。

import discord
client = discord.Client()
@client.event
async def on_ready():
print("Bot is ready")
@client.event
async def on_message(message):
if (message.channel.id == "the-channel-id-here"):
embeds = message.embeds
if not embeds:
return
else:
embed = (message.embeds)[0]
if (embed.color == 4caf50 or e53935):
print('I got that')
else:
return
client.run(BOT_TOKEN)

discord.py总是返回一个Color对象,而不是一个integer,所以你现在比较的是一个Color的实例(顺便说一下,这里定义的)和一个数字。Color对象有一个属性value,它返回一个整数表示的颜色,所以你可以用它来比较它与一个数字。

下面的代码片段应该可以工作了:

import discord
client = discord.Client()
@client.event
async def on_ready():
print("Bot is ready")
@client.event
async def on_message(message):
if (message.channel.id == "the-channel-id-here"):
embeds = message.embeds
if not embeds:
return
else:
embed = (message.embeds)[0]
if (embed.color.value == 4caf50 or embed.color.value == e53935):
print('I got that')
else:
return
client.run(BOT_TOKEN)

请注意,我稍微修改了你的if表达式,你对or的使用是错误的,你必须再次重复embed.color.value的比较工作!

最新更新