Python为消息添加自定义反应 [英] Python add custom reaction for message
本文介绍了Python为消息添加自定义反应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
from discord.utils import get
按名称添加表情符号。
reactions = ['emoji_name_1', 'emoji_name_2', 'emoji_name_3']
@bot.command(pass_context=True)
async def ping1(ctx):
msg = "Pong {0.author.mention}".format(ctx.message)
reply = await bot.say(msg)
for emoji_name in reactions:
emoji = get(bot.get_all_emojis(), name=emoji_name)
await bot.add_reaction(reply, emoji)
按ID添加表情符号。
reactions = ['a:abc:78768768768', 'a:def:768768766', 'a:ghi:878768787687']
@bot.command(pass_context=True)
async def ping2(ctx):
msg = "Pong {0.author.mention}".format(ctx.message)
reply = await bot.say(msg)
for emoji in emojilist:
await bot.add_reaction(reply, emoji)
随机反应
reactions = ['a:abc:78768768768', 'a:def:768768766', 'a:ghi:878768787687']
@bot.command(pass_context=True)
async def ping2(ctx):
msg = "Pong {0.author.mention}".format(ctx.message)
reply = await bot.say(msg)
emojiresult = random.shuffle(reactions)
for emoji in emojiresult:
await bot.add_reaction(reply, emoji)
推荐答案
您需要捕获要发送的消息,然后对该消息调用add_reaction
,而不是将message
作为参数传递给on_message
from discord.utils import get
reactions = ['123', '456', '💖']
@commands.command(pass_context=True)
async def ping(self, ctx):
msg = "Pong {0.author.mention}".format(ctx.message)
reply = await self.bot.say(msg)
for emoji_id in reactions:
emoji = get(ctx.server.emojis, name=emoji_id)
await bot.add_reaction(reply, emoji or emoji_id)
# If emoji is None, then emoji_id is likely a unicode emoji
这篇关于Python为消息添加自定义反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文