【发布时间】:2019-03-12 02:55:00
【问题描述】:
我想为多个命令添加多个自定义反应,或者如果我们添加反应列表,它将从该列表中添加随机反应。那么该怎么做呢。
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)
【问题讨论】:
-
在the comments here 中,您提到您正试图让机器人对其对命令的响应添加反应。您可以在此处添加该代码吗?
-
a:abc:78768768768不是您的表情符号之一,因此您不能那样使用它。相反,只需将该字符串直接应用于add_reaction:for emoji in reactions: await bot.add_reaction(reply, emoji) -
终于为
Emoji Name和Emoji ID工作了,谢谢。 -
@PatrickHaugh 感谢您的帮助,现在
Add Emoji by Name和Add Emoji by ID一切正常,现在我尝试在添加反应之前进行随机反应。但它不工作。我在我的问题 3rd 代码中添加了上面的代码。 -
emojiresult = random.sample(reactions, k=len(reactions))改为
标签: python-3.x discord.py