如何对我刚发送的消息添加反应
How do I add a reaction to the message I just sent
我的一个 Cog 文件中有一个任务函数,如下所示。它不是命令,它只是每 30 秒获取 运行 作为后台任务。我想对我刚刚发送的消息添加一个反应。我该怎么做?
async def _say_hello(self, channelId):
channel = self.client.get_channel(channelId)
await channel.send("Hi everyone")
await channel.add_reaction(':heart:') # This part gives me an error
发送消息时,您可以将其放入变量并将其用作 discord.Message
对象,如下所示:
async def _say_hello(self, channelId):
channel = self.client.get_channel(channelId)
msg = await channel.send("Hi everyone")
await msg.add_reaction('❤') # heart's unicode is \u2764
添加反应时,您想使用实际的表情符号(如果您的编辑器支持),或者可以从 this 网站获得的 unicode。
自定义表情符号
async def _say_hello(self, channelId):
channel = self.client.get_channel(channelId)
msg = await channel.send("Hi everyone")
emoji = discord.utils.get(ctx.guild.emojis, name="emojiname")
# emoji = discord.utils.get(ctx.guild.emojis, id=112233445566778899) alternative method
await msg.add_reaction(emoji)
discord.utils usage:
obj = discord.utils.get(iter, attr="something")
# examples
member = discord.utils.get(ctx.guild.members, id=112233445566778899)
channel = discord.utils.get(ctx.guild.text_channels, name="general")
在查找特定对象时,您可以使用该对象具有的任何属性。如果您需要任何提示,请参阅 docs。
我的一个 Cog 文件中有一个任务函数,如下所示。它不是命令,它只是每 30 秒获取 运行 作为后台任务。我想对我刚刚发送的消息添加一个反应。我该怎么做?
async def _say_hello(self, channelId):
channel = self.client.get_channel(channelId)
await channel.send("Hi everyone")
await channel.add_reaction(':heart:') # This part gives me an error
发送消息时,您可以将其放入变量并将其用作 discord.Message
对象,如下所示:
async def _say_hello(self, channelId):
channel = self.client.get_channel(channelId)
msg = await channel.send("Hi everyone")
await msg.add_reaction('❤') # heart's unicode is \u2764
添加反应时,您想使用实际的表情符号(如果您的编辑器支持),或者可以从 this 网站获得的 unicode。
自定义表情符号
async def _say_hello(self, channelId):
channel = self.client.get_channel(channelId)
msg = await channel.send("Hi everyone")
emoji = discord.utils.get(ctx.guild.emojis, name="emojiname")
# emoji = discord.utils.get(ctx.guild.emojis, id=112233445566778899) alternative method
await msg.add_reaction(emoji)
discord.utils usage:
obj = discord.utils.get(iter, attr="something")
# examples
member = discord.utils.get(ctx.guild.members, id=112233445566778899)
channel = discord.utils.get(ctx.guild.text_channels, name="general")
在查找特定对象时,您可以使用该对象具有的任何属性。如果您需要任何提示,请参阅 docs。