【发布时间】:2020-06-17 04:58:12
【问题描述】:
【问题讨论】:
标签: python discord.py
【问题讨论】:
标签: python discord.py
为了add_reaction(),您需要获取消息对象并指定您要使用的表情符号。因为它是coroutine,所以它必须是awaited。
表情符号:
指定表情符号时,它必须是以下之一:
\u2705
<:emoji_name:112233445566778899>(用于自定义表情符号) - get_emoji() 也可用,返回 discord.Emoji
您可以使用this 网站查找表情符号的 unicode 和字符串表示形式并将其粘贴到其中。
对于自定义表情符号,您可以在 discord 中输入\:emoji_name: 并发送消息,您将收到<:emoji_name:123...> 格式的消息。
命令:
感谢Context,我们可以在使用命令时通过ctx.message获取消息:
@bot.command()
async def cmd(ctx):
# Do some stuff
await ctx.message.add_reaction("\u2705")
on_message():
我们在on_message 事件中获得了message 对象本身:
@bot.event
async def on_message(message):
await bot.process_commands(message) # Don't forget this is you're using commands too
if message.content.lower().startswith("!cmd"):
# Do some stuff
await message.add_reaction("\u2705")
参考资料:
commands.ContextMessage.add_reaction()Client.get_emoji()Guild.fetch_emoji()Bot.process_commands() - “没有这个协程,任何命令都不会被触发。如果你选择覆盖on_message()事件,那么你也应该调用这个协程。”【讨论】: