英文:
Wanting to add a reaction whenever a message is sent (Using Hikari + Lightbulb)
问题
I'm using Hikari + Lightbulb to create my first discord bot and I'm using this as an opportunity to learn as much as possible. As mentioned in the title, I just want to learn how to use add_reaction(":smile:")
correctly. I've read through the Hikari documentation and to be honest, I am having difficulties understanding it fully. I thought the correct line of code would be something along the lines of this
@bot.listen(hikari.MessageCreateEvent)
async def message(event):
print(event.content)
await message.add_reaction(":smile:")
When I go to run this code I receive the following error: AttributeError: 'GuildMessageCreateEvent' object has no attribute 'add_reaction'
. This is making think my error lies with using the MessageCreateEvent
object but after reading the documentation I can't tell which object does support this attribute. Is there something I'm missing? Or am I simply not using the attribute correctly and it's meant to be used in some other way?
英文:
I'm using Hikari + Lightbulb to create my first discord bot and I'm using this as an opportunity to learn as much as possible. As mentioned in the title, I just want to learn how to use
add_reaction(":smile:")
correctly. I've read through the Hikari documentation and to be honest, I am having difficulties understanding it fully. I thought the correct line of code would be something along the lines of this
@bot.listen(hikari.MessageCreateEvent)
async def message(event):
print(event.content)
await message.add_reaction(":smile:")
When I go to run this code I receive the following error: AttributeError: 'GuildMessageCreateEvent' object has no attribute 'add_reaction'
. This is making think my error lies with using the MessageCreateEvent
object but after reading the documentation I can't tell which object does support this attribute. Is there something I'm missing? Or am I simply not using the attribute correctly and it's meant to be used in some other way?
答案1
得分: 0
Sure, here is the translated content:
"好的,所以在评论的帮助下(感谢Guimoute),我已经设法找出解决方法。
我需要在message.add_reaction
之前包含event.
。
以防有人遇到类似问题,这是对我有效的完整代码
@bot.listen(hikari.MessageCreateEvent)
async def message(event):
print(event.content)
await event.message.add_reaction(emoji="👍")
你们中的敏锐者会注意到我不得不更改结尾。如果你不具体并且使用emoji=""
,它会告诉你该值不是雪花,我不完全理解,但在查看一些discord开发门户文档时,我认为这是discord的要求。"
英文:
Okay so I've managed to figure it out with Help from the comments (Thank you Guimoute).
I needed to include event.
before the message.add_reaction
.
Just in case anyone has had a similar issue this is the complete code that worked for me
@bot.listen(hikari.MessageCreateEvent)
async def message(event):
print(event.content)
await event.message.add_reaction(emoji="👍")
Keen eyed among you will notice I had to change the end. If you don't be specific and and use emoji=""
is will tell you that the value is not snowflake, I don't fully understand it but reading over some of the discord dev portal documentation, I think it's a requirement of discord.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论