Ori
Ori

Reputation: 31

Discord bot function stops working when in a guild with other specific bots

Ok, So..I have made an on guild join captcha for my bot. Works how you'd think it would work. User joins, gets a DM with a captcha, user completes the captcha, they get access/a role. They fail the captcha, it regens a new one and says try again.

The following code works flawlessly and without error except for when it can't DM a user (not my issue that I need help with). HOWEVER, and idk if this has anything to do with my code or discord intents or other discord bots in the same server my bot is in..but when the bot is in a server alone with no other bots, works flawlessly with all functionality. The moment I have the bot in the server with Welcomer bot for example. It generates the captcha, sends it to the user, then nothing.. no response, no error on my end. Just nothing. The user can send the captcha answer all they want but they get no response, no role, no error or new captcha. The rest of the bots commands and code still work and the bot remains online.

I know the code works and functions fully because I just tested it multiple times with many different people including myself.

It's just when it is in the same server with other bots that it just stops working. Some bots don't interfere but others do and I have no way of telling until I start kicking them until I find the one stopping my bots DM captcha stuff from working. Like welcomer bot. I know it sounds weird but it's true. I've spent literal weeks testing this out and this is all just what I've found out. I am honestly out of ideas..

Like I said, idk if it has anything to do with the discord bots intents or my code. I was hoping someone here could have answers or an explanation.

This is what I have for my bots intents.

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.

And this is the captcha code/function.

@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

Your guess is as good as mine. This has been an issue of mine for weeks now going on a month..

Any help is appreciated.

Upvotes: 0

Views: 319

Answers (1)

Pizerite
Pizerite

Reputation: 59

Since no check kwarg was provided in your wait_for, it will take input from all users, including bots + in any channel visible to the bot.

So, when a user joins and welcomer post its welcome message in a channel

if msg.author.bot: 
            return #Ignores bots

is triggered

Do notice, you are returning and not passing so it returns and after that your wait_for becomes useless

define a check function and use the following check kwarg inside your wait_for constructor

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

so your code now becomes:

@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

Upvotes: 1

Related Questions