提问者:小点点

与其他特定机器人在公会中时,不和谐机器人功能停止工作


好的,所以…我已经为我的机器人做了一个公会加入验证码。按照你认为的方式工作。用户加入,用验证码获得DM,用户完成验证码,他们获得访问/角色。他们失败了验证码,它会重新获得一个新的验证码,并说再试一次。

下面的代码可以完美地工作,没有错误,除非它不能DM用户(不是我需要帮助的问题)。然而,如果这与我的代码或不和谐意图或我的机器人所在的同一服务器中的其他不和谐机器人有任何关系…但是当机器人单独在服务器中而没有其他机器人时,可以完美地使用所有功能。当我在服务器中使用Welcomer机器人时。它生成验证码,将其发送给用户,然后什么都没有…没有响应,我这边没有错误。什么都没有。用户可以随心所欲地发送验证码答案,但他们没有得到响应、没有角色、没有错误或新的验证码。其余的机器人命令和代码仍然可以工作,机器人仍然在线。

我完全知道代码可以工作和运行,因为我刚刚与包括我自己在内的许多不同的人多次测试了它。

只是当它和其他机器人在同一个服务器上时,它就停止了工作。有些机器人不会干扰,但其他机器人会干扰,我无从分辨,直到我开始踢它们,直到我找到那个阻止我的机器人DM验证码工作的机器人。就像欢迎机器人。我知道这听起来很奇怪,但这是真的。我花了几个星期的时间来测试这个,这就是我所发现的。老实说,我没有想法了…

就像我说的,如果它与不和谐机器人的意图或我的代码有关,请idk。我希望这里有人能有答案或解释。

这就是我的机器人意图。

intents = discord.Intents.default()
intents.members = True
BOT_Prefix=("t.", "T.")
eye = commands.Bot(command_prefix=BOT_Prefix, intents=intents) #eye replaces Client. So instead of @Client.command/event it's @eye.command/event.

这是验证码/函数。

@eye.event
async def on_member_join(user: discord.Member):

    while True:
        verified = discord.utils.get(user.guild.roles, id=649739504940351489)
        res = r.get("https://captcha.manx7.net/insecure/new", headers={"captcha-length":"5"}).json();
        if res['error']:
            print(res['error'] + " - Manx7 Error")
            user.send("Something went wrong while trying to set-up a captcha session, please contact `" + bot_author + "` for help.")
            return
        captcha_answer = res['response']['code']
        embed = discord.Embed(title="Server Captcha", description=f"```fix\nHello {user.name},\nYou will not be able to gain access to the server until you complete this captcha.\nPlease Type The Follwoing Below To Verify!!\n\nNotes:\n1)The letters are case sensitive and are the big colorful ones.\n\n2)DM " + bot_author + " if the bot breaks or if you encounter any bugs!!\n\n-----------------------------\nCaptchca API - https://captcha.manx7.net/```")
        embed.set_footer(text=f"{botver} by Ori", icon_url='https://cdn.discordapp.com/attachments/850592305420697620/850595192641683476/orio.png')
        embed.set_image(url=res['response']['image'])
        await user.send(embed=embed)
        #Everything above this line/message works fine every time. 
        msg = await eye.wait_for("message")
        if msg.author.id == eye.user.id:
            return #Ignores itself (Used to send captcha, error then send it again when a user joined. This stops that.)
        if msg.author.bot: 
            return #Ignores bots
        if msg.content == captcha_answer:
            embed2 = discord.Embed(title="Verified!", description=f":white_check_mark: Thank you for verifying!. You have now been given access to the server!", color=discord.Color.green())
            embed2.set_footer(text=f"{botver} by Ori", icon_url='https://cdn.discordapp.com/attachments/850592305420697620/850595192641683476/orio.png')
            await user.send(embed=embed2)
            await user.add_roles(verified, reason="None")
            break
        else:
            embed3 = discord.Embed(title="Error!", description="\n\n__Captcha Failed, Please Try Again__\n\n", color=discord.Color.red())
            await user.send(embed=embed3)
            pass

你的猜测和我的一样好。这是我几周来的问题,现在已经持续了一个月…

感谢任何帮助。


共1个答案

匿名用户

由于您的wait_for中没有提供checkkwarg,因此它将接受所有用户的输入,包括机器人可见的任何通道中的机器人。

因此,当用户加入并欢迎者在频道中发布其欢迎消息时

if msg.author.bot: 
            return #Ignores bots

被触发

请注意,您正在返回而不是通过,因此它返回,之后您的wait_for变得无用

定义一个检查函数,并在wait_for构造函数中使用以下checkkwarg

def check(m):
            return m.author == user and m.channel == x.channel

所以你的代码现在变成了:

@eye.event
async def on_member_join(user): # you need not typecast in an event, it by default knows that user is a discord.Member object

    while True:
        verified = discord.utils.get(user.guild.roles, id=649739504940351489)
        res = r.get("https://captcha.manx7.net/insecure/new", headers={"captcha-length":"5"}).json();
        if res['error']:
            print(res['error'] + " - Manx7 Error")
            user.send("Something went wrong while trying to set-up a captcha session, please contact `" + bot_author + "` for help.")
            return
        captcha_answer = res['response']['code']
        embed = discord.Embed(title="Server Captcha", description=f"```fix\nHello {user.name},\nYou will not be able to gain access to the server until you complete this captcha.\nPlease Type The Follwoing Below To Verify!!\n\nNotes:\n1)The letters are case sensitive and are the big colorful ones.\n\n2)DM " + bot_author + " if the bot breaks or if you encounter any bugs!!\n\n-----------------------------\nCaptchca API - https://captcha.manx7.net/```")
        embed.set_footer(text=f"{botver} by Ori", icon_url='https://cdn.discordapp.com/attachments/850592305420697620/850595192641683476/orio.png')
        embed.set_image(url=res['response']['image'])
        x = await user.send(embed=embed)
        #Everything above this line/message works fine every time. 
        def check(m): # m is a Message object 
            return m.author == user and m.channel == x.channel # return only if the user responded in bot's dms and user is the person who triggered the event
        msg = await eye.wait_for("message", check=check)
        if msg.author.id == eye.user.id:
            return #Ignores itself (Used to send captcha, error then send it again when a user joined. This stops that.)
        if msg.content == captcha_answer:
            embed2 = discord.Embed(title="Verified!", description=f":white_check_mark: Thank you for verifying!. You have now been given access to the server!", color=discord.Color.green())
            embed2.set_footer(text=f"{botver} by Ori", icon_url='https://cdn.discordapp.com/attachments/850592305420697620/850595192641683476/orio.png')
            await user.send(embed=embed2)
            await user.add_roles(verified, reason="None")
            break
        else:
            embed3 = discord.Embed(title="Error!", description="\n\n__Captcha Failed, Please Try Again__\n\n", color=discord.Color.red())
            await user.send(embed=embed3)
            pass