web-dev-qa-db-fra.com

Python ajoute une réaction personnalisée au message

Je veux ajouter plusieurs réactions personnalisées pour plusieurs commandes. Si nous ajoutons des listes de réactions, cela ajoutera des réactions aléatoires à partir de ces listes. Alors, comment faire ça.

from discord.utils import get

Ajoutez Emoji par nom.

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)

Ajouter Emoji par 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)

réaction aléatoire 

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)
4
Demotry

Vous devez capturer le message que vous envoyez, puis appeler add_reaction sur ce message et non la message transmise en tant qu'argument à 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
3
Patrick Haugh
for r in reactions:
    await bot.add_reaction(message, r)
0
Mehvix