Discord.py验证系统



我正在制作一个验证系统,如果您键入!verify "1. John 2. Mr. Teacher 3. Somewhere 4. Freshman 5. The Cool Mascot",它将在通道中发送一个嵌入,如下所示:https://gyazo.com/ab808bafcd4a5f3ed05f63e007da20c1.如果有人对复选标记做出反应,我想dm用户说他们已经被接受,如果他们被拒绝,它会发送dm,说他们被拒绝了,但我在做出反应时似乎没有得到dm,他们之后没有得到成员角色,而且没有追溯。

代码:

@bot.command(pass_context=True)
async def verify(ctx, message):
logem = discord.Embed(color=discord.Color.red())
logem.set_author(name=f"Verification Request!")
logem.add_field(name="User", value=f"{ctx.author.mention}")
logem.add_field(name="Application", value=f"{message}")
logem.set_footer(text=f"React with ✅ to accept the application and ❌ to deny the application",
icon_url="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/Exclamation_mark_red.png/50px-Exclamation_mark_red.png")
logemlog = bot.get_channel(820840787645956123)
msg = await logemlog.send(embed=logem)
await msg.add_reaction('✅')
await msg.add_reaction('❌')
async def on_raw_reaction_add(payload):
msgid = await ctx.fetch_message(msgID)
ourMessageID = msgid
if ourMessageID == payload.message_id:
member = payload.member
guild = member.guild
emoji = payload.emoji.name
if emoji == '✅':
role = discord.utils.get(guild.roles, name="Member")
print ('Accepted Someones Application')
em = discord.Embed(color=discord.Color.red())
em.set_author(name="Verified!")
em.set_footer(text=f"You Have Been Accepted Into The Official WHS Discord Server!",
icon_url="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/Exclamation_mark_red.png/50px-Exclamation_mark_red.png")
await member.send("You have been accepted!")
await member.add_roles(role)
elif emoji == '❌':
em = discord.Embed(color=discord.Color.red())
em.add_field(name="Denied!", value=f"{message}")
em.set_footer(text=f"You Have Been Denied Access Into The Official WHS Discord Server!",
icon_url="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/Exclamation_mark_red.png/50px-Exclamation_mark_red.png")
await ctx.member.send("You have been Denied!")

使用此项而不是异步定义on_raw_reaction_add:

def check(reaction, user):
return reaction.emoji in ['✅', '❌'] and user == ctx.author
while True:
try:
reaction, user = await bot.wait_for('reaction_add', check=check)
except Exception as e:
print(e)
else:
if reaction.emoji == '✅':
role = discord.utils.get(guild.roles, name="Member")
print ('Accepted Someones Application')
em = discord.Embed(color=discord.Color.red())
em.set_author(name="Verified!")
em.set_footer(text=f"You Have Been Accepted Into The Official WHS Discord Server!",
icon_url="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/Exclamation_mark_red.png/50px-Exclamation_mark_red.png")
await member.send("You have been accepted!")
await member.add_roles(role)
if reaction.emoji == '❌':
em = discord.Embed(color=discord.Color.red())
em.add_field(name="Denied!", value=f"{message}")
em.set_footer(text=f"You Have Been Denied Access Into The Official WHS Discord Server!",
icon_url="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/Exclamation_mark_red.png/50px-Exclamation_mark_red.png")
await ctx.member.send("You have been Denied!")

测试一下,如果不起作用就告诉我。

最新更新