gpt4 book ai didi

python - 您如何让机器人使用自定义表情符号添加 react ?

转载 作者:行者123 更新时间:2023-11-28 21:37:46 25 4
gpt4 key购买 nike

我正在尝试使用 discord.py 0.16.12 版添加自定义表情符号作为对消息的 react ,但无法使其正常工作。这是我正在使用的代码:

@bot.event
async def on_message(message):
if message.content.find(':EmojiName:'):
await bot.add_reaction(message, '<:EmojiName:#EmojiID#>')

我还尝试将表情符号 id 作为类似于 discord.js (message, '#EmojiID#') 的字符串传递.我应该通过 add_reaction作用于表情符号对象?如果是这种情况,我如何从 get_all_emojis 中找到特定的表情符号对象功能?

最佳答案

您可以使用实用函数 discord.utils.get 获得合适的 Emoji object .

from discord.utils import get

@bot.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == bot.user:
return
if ':EmojiName:' in message.content:
emoji = get(bot.get_all_emojis(), name='EmojiName')
await bot.add_reaction(message, emoji)

关于python - 您如何让机器人使用自定义表情符号添加 react ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48982061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com