Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.0 kB
6
Indexable
Never
import json
import discord
from discord.ext import commands
from discord import app_commands

# Load the list of verified users from users.json file
with open("users.json", "r") as f:
    verified_users = json.load(f)

intents = discord.Intents.default()
intents.members = True

class CustomBot(commands.Bot):
    def __init__(self, *, intents: discord.Intents, command_prefix: str):
        super().__init__(intents=intents, command_prefix=command_prefix)
    async def setup_hook(self):
        self.tree.copy_global_to(guild=discord.Object(id=982865923356651550))
        await self.tree.sync(guild=discord.Object(id=982865923356651550))

bot = CustomBot(intents=intents, command_prefix="!")
class Confirm(discord.ui.View):
    def __init__(self):
        super().__init__()
        self.value = None

@bot.command()
async def sync(ctx) -> None:
  cmds = await ctx.bot.tree.sync()
  await ctx.send(f"Synced {len(cmds)} commands")

# Define a slash command for verification
@bot.tree.command(name="verify", description="Verify your account")
async def verify(interaction: discord.Interaction):
    # Check if the user is an admin
    if not interaction.user.guild_permissions.administrator:
        await interaction.response.send_message("Only admins can use this command.", ephemeral=True)
        return

    # Create an embedded message with a button to verify
    embed = discord.Embed(
        title="Verification",
        description="Click the button to verify your account.",
        color=0x00ff00,
    )
    verify_button = discord.ui.button(label='Verify',custom_id="verify_button", style=discord.ButtonStyle.green)
    async def confirm(self, interaction: discord.Interaction, button: discord.ui.Button):
        await interaction.response.send_message('Verifying', ephemeral=True)
        self.value = True
        self.stop()
    view = discord.ui.View()
    view.add_item(verify_button)
    await interaction.response.send_message(embed=embed, view=view)

    # Wait for the user to click the verify button
    interaction = await bot.wait_for(
        "button_click", check=lambda i: i.custom_id == "verify_button"
    )

    # Check if the user has already been verified
    user_id = str(interaction.user.id)
    if user_id in verified_users["uid"]:
        await interaction.response.send_message("You are already verified.", ephemeral=True)
        return

    # Store the user's information in the users.json file
    verified_users["username"].append(str(interaction.user))
    verified_users["uid"].append(user_id)
    with open("users.json", "w") as f:
        json.dump(verified_users, f, indent=4)

    # Grant the user the "verified" role
    role = discord.utils.get(interaction.guild.roles, name="verified")
    await interaction.user.add_roles(role)

    # Send a confirmation message to the user
    await interaction.response.send_message("You have been verified!", ephemeral=True)

# Run the bot
bot.run("MTAyMzk3NTA0Nzk0NzM2MjQwNA.GmlQkQ.pB-pB7EpF5v32sTBCuC6MpVwUHdshUYVtaW36w")