【发布时间】:2021-10-02 11:46:18
【问题描述】:
所以我在 discord.py 中制作了一个验证码机器人,如果他们在特定时间内没有回答验证码,我会尝试踢用户,如果他们得到不正确的验证码或不输入。如果他们把它弄对了,它已经会打破循环,那部分就可以工作了。它只是时间问题,如果用户在给定时间内没有猜到验证码,它不会在特定时间后踢用户。我放了 10 秒只是为了测试。最后两行是他们的任何方式,如果他们在给定的时间内没有回答验证码,我可以在其中踢用户。顺便说一句,其他一切正常,他们没有错误**但是代码如下:
from discord.ext import commands
from discord.utils import get
import random
import time
import asyncio
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix="+", intents=intents)
@bot.command()
async def setup(ctx):
embed=discord.Embed(title="How to get verfiied",
description="1.Go to the verified channel and use the command $verify\n2.Then from there you should be able to get you role and come into the server.\n\n**YOU HAVE 3 tries and only 15 minutes to solve the captcha or else the bot will kick you. Plesae contact staff if you have any issues**", color=0x0000FF)
await ctx.send(embed=embed)
@bot.command(name='verify', pass_context = True)
async def verify(ctx):
def check(m):
return m.author == ctx.author and m.channel == ctx.message.channel
image = ("captcha 6.png","captcha10.png","captcha11.png","captcha2.png", "captcha3.png", "captcha4.png", "captcha5.png", "captcha7.png","captcha8.png", "captcha9.png")
image_random = random.choice(image)
number = ("b3xpn", "2yggg","ydg8n","pp546","fcne6","cdfen","4f8yp","m8m4x","pdyc8","55w5c","xwx7d")
await ctx.send(file=discord.File(image_random))
await ctx.send('Please solve the captcha image')
for i in range(0, 3):
guess = await bot.wait_for('message', check=check)
if guess.content in number:
await ctx.send('Correct Welcome!')
role = discord.utils.get(ctx.author.guild.roles, name="member")
await ctx.author.add_roles(role)
break
else:
await ctx.send("Incorrect")
else:
await ctx.send("Incorrect this is your 3rd try please rejoin and try again")
await asyncio.sleep(3)
await ctx.author.kick()
asyncio.sleep(5)
await ctx.author.kick()
【问题讨论】:
-
不是一个真正的大问题,但是如果用户响应/不响应,您的代码不会停止该功能,因此即使用户响应,最后两行也会始终运行并踢出用户
标签: python discord discord.py bots