full

 avatar
hisoka
python
2 years ago
2.4 kB
6
Indexable
#####


class VerifyModal(discord.ui.Modal, title="Verification"):
    correctcode = ui.TextInput(
        label="Captcha",
        placeholder="Input Captcha Code",
        style=discord.TextStyle.short,
    )
    # MODAL SUBMIT WILL TRIGGER THIS
    async def on_submit(self, interaction: discord.Interaction):
        await interaction.response.edit_message(view=DisabledButton())
        # SUCCESS EMBED
        successembed = discord.Embed(
            title="Verification Success!",
            description=f"Congrats <@{interaction.user.id}>, you're human!\n\nAccess to `{interaction.guild.name}` has been granted.",
            color=0x8FCE00)
        # FAIL EMBED
        failembed = discord.Embed(
            title="Incorrect Code!",
            description="The code you submitted was incorrect, please try again.\n\n**Note**: This captcha is **case-sensitive.**",
            color=0xFF4040)
        # ERROR EMBED
        errorembed = discord.Embed(
            title="Verification Error!",
            description=f"An error has occured while attempting to verify in `{interaction.guild.name}`, please try again.\n\n **Note:** Error could be caused by high volume. Please remain patient.",
            color=0xFFC45F)
        # CHECKING THE USER INPUTTED TEXT AGAINST CAPTCHA
        try:
            # IF CODE IS CORRECT
            if self.correctcode.value == captchatext:
                print(" Correct code was submitted!")
                await interaction.member.add_roles(verifyrole)
                print(" Error adding role to user.")
                await interaction.edit_original_response(
                    embed=successembed, attachments=[], view=CasualButton()
                )
                print(" User has been granted the verified role.")
                return
            if self.correctcode.value != captchatext:
                print(" Inorrect code!")
                await interaction.edit_original_response(
                    embed=failembed, attachments=[], view=None
                )
                print(" Incorrect code has been submitted. 2")
                return
        except:
            await interaction.edit_original_response(
                embed=errorembed, attachments=[], view=None
            )
            print(" Captcha Code on_submit error")
            return


###########
Editor is loading...