Discord bot reading reactions

隐身守侯 提交于 2019-11-30 20:24:40

As an aside, given you're starting this project, and are already using the rewrite documentation, make sure you're using the rewrite version. There are some questions on here about how to make sure, and how to get it if you're not, but it's better documented and easier to use. My answers below assume you are using

  1. Message.reactions is a list of Reactions. You could get a mapping of reactions to their counts with

    {react.emoji: react.count for react in message.reactions}
    
  2. You could react to the message immediately after posting it:

    @bot.command()
    async def poll(ctx, *, text):
        message = await ctx.send(text)
        for emoji in ('👍', '👎'):
            await message.add_reaction(emoji)
    
  3. You can use Message.pin: await message.pin()

I'm not sure what you mean by "user tags". Do you mean roles?

Edit 1:

I would write your command as

@bot.command()
async def create_poll(ctx, text, *emojis: discord.Emoji):
    msg = await ctx.send(text)
    for emoji in emojis:
        await msg.add_reaction(emoji)

Note that this will only work for custom emoji, the ones you have added to your own server (This is because discord.py treats unicode emoji and custom emoji differently.) This would accept commands like

!create_poll "Vote in the Primary!" :obamaemoji: :hillaryemoji:

assuming those two emoji were on the server you send the command in.

Edit 2:

With the new commands.Greedy converter, I would rewrite the above command like so:

@bot.command()
async def create_poll(ctx, emojis: Greedy[Emoji], *, text):
    msg = await ctx.send(text)
    for emoji in emojis:
        await msg.add_reaction(emoji)

So invocation would be a little more natural, without the quotes:

!create_poll :obamaemoji: :hillaryemoji: Vote in the Primary!
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!