【发布时间】:2019-08-10 05:27:31
【问题描述】:
您好,这是一个 cog thats 功能,机器人发送消息 on_member_join 并允许用户对机器人为用户添加特定角色的帖子做出反应,在这种情况下它是 Members。我在添加支票时遇到问题。
我想让机器人在用户对帖子做出反应之前设置一个竖起大拇指的表情符号,而不应用用户角色。
这种方法似乎存在一个缺陷,它允许包括机器人在内的任何人对竖起大拇指表情符号做出反应,并赋予加入用户成员角色,而不是用户自己。似乎需要检查以仅注册加入用户已使用竖起大拇指的反应。
这可能吗?
这是我正在使用的:
我已经在代码块中引用了带有 # 的待办事项来给你一个想法。
thumbs_up = "\N{THUMBS UP SIGN}"
def react_check(user, msg, emoji):
def check(reaction, user):
return user==user and reaction.message.id==msg.id and
reaction.emoji==emoji
return check
class Welcome(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_member_join(self, user: discord.Member):
guildName = user.guild.name
channel = self.bot.get_channel(555844758778544160)
embed = discord.Embed(colour=discord.Color(random.randint(0x000000, 0xFFFFFF)))
embed.title = "Hello {}, welcome to {}!".format(user, guildName)
embed.description = "Before you continue we just want to make sure you have read up on our all important group guidelines. if you haven't you can find them in <#546694486391128066>. Once you're satified with them go ahead and give my message a :thumbsup:."
embed.set_image(url='')
msg = await channel.send(embed=embed)
await msg.add_reaction(thumbs_up) # todo: make bot set a thumbs_up emoji but only set members role when the user mentioned reacts.
await self.bot.wait_for('reaction_add', check=react_check(user, msg, thumbs_up))
role = get(user.guild.roles, name="Members")
if self.bot: #supposed check to see if the bot
pass
else:
await user.add_roles(role)
await channel.send(':thumbsup: Awesome! you\'re now set to go. If you would like to add some roles head over to <#555913791615926302> for more details. ')# Check
def setup(bot):
bot.add_cog(Welcome(bot))
【问题讨论】:
-
您应该在此问题中添加
react_check代码。react_check是否为user以外的对msg做出反应的用户返回True?只有在给出满足react_check标准的反应时,它才应该继续协程。 -
@PatrickHaugh 我们昨天在另一个问题中谈到了确切的代码。我已经继续并在我的问题中添加了
react_check代码。理想情况下,我希望机器人在不向用户添加成员角色的情况下添加对帖子的反应,除非用户添加到该反应中。 IE。机器人首先做出反应,但用户第二个做出反应,将角色应用于该用户。
标签: python-3.x discord discord.py discord.py-rewrite