Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.2 kB
3
Indexable
Never

import discord
import json
intents = discord.Intents.default()
intents.members = True
client = discord.Client(intents=intents)

@client.event
async def on_ready():
    print('Logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('/verify') and message.author.guild_permissions.administrator:
        embed = discord.Embed(
            title='Verification',
            description='Click the button below to verify',
            color=discord.Color.blue()
        )

        verify_button = discord.ui.Button(
            label='Verify',
            style=discord.ButtonStyle.green,
            custom_id='verify_button'
        )

        action_row = discord.ui.ActionRow(verify_button)

        verify_msg = await message.channel.send(embed=embed, components=[action_row])

        try:
            verify_interaction = await client.wait_for(
                'button_click',
                check=lambda inter: inter.message.id == verify_msg.id and inter.custom_id == 'verify_button',
                timeout=60.0
            )
            user_id = str(verify_interaction.user.id)
            user_name = verify_interaction.user.name + "#" + verify_interaction.user.discriminator

            with open('users.json', 'r+') as f:
                users = json.load(f)
                if user_id in users['uid']:
                    await verify_interaction.response.send_message('You are already verified', ephemeral=True)
                else:
                    users['username'].append(user_name)
                    users['uid'].append(user_id)
                    f.seek(0)
                    json.dump(users, f, indent=4)
                    f.truncate()
                    member = message.guild.get_member(int(user_id))
                    role = discord.utils.get(message.guild.roles, name='verified')
                    await member.add_roles(role)
                    await verify_interaction.response.send_message('You have been verified!', ephemeral=True)
        except asyncio.TimeoutError:
            await verify_msg.edit(components=[])

client.run('TOKEN')