在Python中编程不和机器人-我如何使机器人对自己的消息做出反应?



我想让bot在发送消息后立即对其自己的消息做出反应。下面是我的代码:

@client.event
async def on_message(message):
if any(word in msg for word in submission_triggers):
channel = client.get_channel(805132829691215882)
mention = message.author.name
image_url = message.attachments[0].url
em = discord.Embed(title = f"Created by: {mention}", color = random.choice(colors))
em.set_image(url = image_url)
await channel.send(embed = em)
await client.add_reaction("<:ThumbsUp:796201003816321034>")

当this被触发时,它发送嵌入但不响应它。我得到这个错误:

AttributeError: 'Bot' object has no attribute 'add_reaction'

不太确定如何解决这个问题。我是编程新手,如果你有什么见解,我将不胜感激。

您得到的错误显然是因为属性问题。这意味着Bot不能对消息添加反应。另外,在不指定要添加的消息的情况下,您如何期望添加一个反应?discord.Message对象具有add_reaction属性。你必须得到它的实例。您可以简单地为发送的消息分配一个变量,然后添加反应。

@client.event
async def on_message(message):
if any(word in msg for word in submission_triggers):
channel = client.get_channel(805132829691215882)
mention = message.author.name
image_url = message.attachments[0].url
em = discord.Embed(title = f"Created by: {mention}", color = random.choice(colors))
em.set_image(url = image_url)
sent = await channel.send(embed = em)
await sent.add_reaction("<:ThumbsUp:796201003816321034>")

最新更新