Discord PY Bot,根据特定消息的响应创建列表 [英] Discord PY Bot, Creating a list from reactions of a specific message

查看:47
本文介绍了Discord PY Bot,根据特定消息的响应创建列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个机器人,其中有一个命令可以对消息进行响应.我想知道如何创建所有单击特定反应的人员的列表.我不确定用于检索反应堆的变量.

I'm creating a bot, and in it there is a command that adds a reaction to a message. I'm wondering how to create a list of all those who clicked on the specific reaction. I have been unsure of the variable(s) to use to retrieve the reactors.

@client.command(pass_context=True)
@has_permissions(administrator=True)
async def reaction(ctx):
    msg = await ctx.send("**React '✅' to this message to sign up!**")
    reactions = ['✅']
    for emoji in reactions: 
        await msg.add_reaction(emoji)

这是反应消息的代码.不和谐有可能列出做出反应的人员吗?如果是这样,将如何做?抱歉,如果我在discord.py的文档中错过了它,那么我将找不到它.谢谢:)

Here is the code of the reaction message. Is it possible for discord to list the people who reacted? If so, how would it be done? Apologies if I missed it in the documentation of discord.py, I was unable to find it if so. Thank you :)

推荐答案

使用 on_reaction_add 将执行此操作.当然,这取决于您的漫游器的结构,但是有一个列表,您可以在其中添加对消息做出反应的所有用户.如果您还没有齿轮,我建议您使用齿轮,因为您需要将两个变量存储在 reaction 函数之外, some_list msg.您可以使用全局变量,但我建议您不要这样做.

Using on_reaction_add will do this. This of course depends on how your bot is structured, but have a list which you add all the users who reacted to the message to. I'd advise you to use cogs if you aren't already as you have two variables which you need to store outside of the reaction function, some_list and msg. You could use global variables but I advise against this.

下面是代码外观的一般概述,请注意,仅粘贴代码可能无法正常工作.

Below is a general outline of what your code would look like, be aware that this code may not work by just pasting it in.

some_list = []
msg = None

@client.command(pass_context=True)
@has_permissions(administrator=True)
async def reaction(ctx):
    msg = await ctx.send("**React '✅' to this message to sign up!**")
    reactions = ['✅']
    for emoji in reactions: 
        await msg.add_reaction(emoji)

@client.event
async def on_reaction_add(reaction, user):
    if reaction.message == msg:
        some_list.append(user)

这篇关于Discord PY Bot,根据特定消息的响应创建列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆