我想为多个命令添加多个自定义反应,或者如果我们添加反应列表,它将从该列表中添加随机反应。那么该怎么做。
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)
答案 0 :(得分:3)
您需要捕获要发送的消息,然后对该消息调用add_reaction
,而不是作为参数传递给message
的{{1}}
on_message
答案 1 :(得分:0)
for r in reactions:
await bot.add_reaction(message, r)