【问题标题】:Discord bot function stops working when in a guild with other specific bots与其他特定机器人在公会中时,Discord 机器人功能停止工作
【发布时间】:2021-09-08 07:14:21
【问题描述】:

好的,所以..我为我的机器人制作了一个公会加入验证码。以您认为的方式工作。用户加入,获得带有验证码的 DM,用户完成验证码,他们获得访问权限/角色。他们没有通过验证码,它会重新生成一个新的验证码并说再试一次。

以下代码可以完美运行且没有错误,除非它无法 DM 用户(不是我需要帮助的问题)。 但是,如果这与我的代码或不和谐意图或我的机器人所在的同一台服务器中的其他不和谐机器人有任何关系,我想知道。但是当机器人单独在没有其他机器人的服务器中时,它可以完美地使用所有功能。例如,当我使用 Welcomer bot 将 bot 安装在服务器中时。它生成验证码,将其发送给用户,然后什么都没有……没有响应,我这边没有错误。根本不值一提。用户可以发送他们想要的所有验证码答案,但他们没有得到响应、没有角色、没有错误或新的验证码。其余的机器人命令和代码仍然有效,并且机器人保持在线。

我完全了解代码的工作原理和功能,因为我刚刚与包括我自己在内的许多不同的人对其进行了多次测试。

只有当它与其他机器人位于同一服务器时,它才会停止工作。有些机器人不会干扰,但其他机器人会干扰,直到我开始踢它们,直到我找到阻止我的机器人 DM 验证码工作的那个,我才知道。就像欢迎机器人一样。我知道这听起来很奇怪,但这是真的。我已经花了数周的时间来测试这一点,而这正是我所发现的。老实说,我没有想法..

就像我说的,如果它与不和谐机器人的意图或我的代码有任何关系,我想知道。我希望这里有人能给出答案或解释。

这就是我的机器人意图。

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

你的猜测和我的一样好。这一直是我的一个问题,现在一个月了..

感谢任何帮助。

【问题讨论】:

    标签: python-3.x discord bots


    【解决方案1】:

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

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

    if msg.author.bot: 
                return #Ignores bots
    

    被触发

    请注意,您是在返回而不是通过,所以它会返回,然后您的 wait_for 就变得无用了

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

    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
    

    【讨论】:

      猜你喜欢
      • 2020-10-30
      • 2021-07-30
      • 2021-11-10
      • 2019-08-14
      • 2019-11-09
      • 1970-01-01
      • 1970-01-01
      • 2021-03-24
      • 2021-09-04
      相关资源
      最近更新 更多