我想为多个命令添加多个自定义 react ,或者如果我们添加 react 列表,它将从该列表中添加随机 react 。那么如何做到这一点。
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)
随机 react
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-3.x - Python为消息添加自定义 react ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52685273/