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

标签 python python-3.x discord.py

我正在尝试使用 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/

相关文章:

python - Pandas,如何从系列中的所有值中减去第一行值?

python - 是否可以将 mmap 文件视为字节对象?

python-3.x - 来自 DataFrame 的一张图上的多个图

python - 模块未找到错误 : No module named 'cogs'

python - 检查 num 是否可以除以 1(不是 1.9、2.5,而是 1.0、6.0)

python - PyQt QTableView - 捕获 KeyDown/KeyPress 事件

python - 有没有办法找到矩阵中不同值的概率

python - 作为发起者重置接受者序列号,但无法使用 onLogon

Discord.py新超时命令错误: "AttributeError: ' User' object has no attribute 'timeout_for' "

discord - discord.py 和 discord.py 的区别[语音]