我想让机器人在发送消息后立即对其做出反应。这是我的代码:
@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>")
当这是触发时,它发送嵌入但不对其作出反应。我收到此错误:
AttributeError: 'Bot' object has no attribute 'add_reaction'
不太清楚如何解决这个问题。我是编程新手,因此不胜感激。
答案 0 :(得分:2)
您收到的错误显然是因为属性问题。这意味着 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>")