on_reaction_add()
可以使用on_ready()
发送的消息吗?
我试图让用户通过机器人启动时发送的消息上的反应来验证他们是人类。
async def on_ready():
#delete msgs from verify chan
channel = client.get_channel("32133132")
msg=[]
async for x in client.logs_from(channel, limit = 100):
msg.append(x)
await client.delete_messages(msg)
#send verification msg w/ reaction
await client.send_message(channel, "**Verify you are human**")
verifymsg2 = await client.send_message(channel, "React with ✅ to gain access to Hard Chats.")
await client.add_reaction(verifymsg2, "✅")
@client.event
async def on_reaction_add(reaction, user):
channel = client.get_channel('32133132')
if reaction.message.channel.id != channel:
return
else:
if reaction.emoji == "✅":
unverified = discord.utils.get(user.server.roles, id="567859230661541927")
verified = discord.utils.get(user.server.roles, id="567876192229785610")
await client.remove_roles(user, unverified)
await client.add_roles(user, verified)
在弄乱了这段代码之后,我继续这样做了。每次新人加入服务器时,它都会为每个频道添加未经验证的角色和受限制的权限。然后它将清除验证通道并发送验证消息。从那里它将等待反应。如果反应,则会删除未验证的角色并添加已验证的角色。
@client.event
async def on_member_join(member):
#-------------------------ADD UNVERIFIED ROLE----------------------------#
role = discord.utils.get(member.server.roles, id="123456789")
await client.add_roles(member, role)
#---------------DELETE MSG FROM VERIFY---------------#
channel = client.get_channel("0987654321")
msg=[]
async for x in client.logs_from(channel, limit = 100):
msg.append(x)
await client.delete_messages(msg)
#---------------SEND VERIFY MSG / REACT TO VERIFY MSG---------------#
await client.send_message(channel, "**Verify you are human**")
verifymsg2 = await client.send_message(channel, "React with ✅ to gain access to Hard Chats.")
await client.add_reaction(verifymsg2, "✅")
unverified = discord.utils.get(member.server.roles, name="unverified")
verified = discord.utils.get(member.server.roles, name="verified")
reaction = await client.wait_for_reaction(emoji="✅", message=verifymsg2,
check=lambda reaction, user: user != client.user)
if reaction:
await client.remove_roles(member, unverified)
await asyncio.sleep(0.5)
await client.add_roles(member, verified)