Untitled
unknown
plain_text
a year ago
2.2 kB
2
Indexable
Never
import json import discord from discord.ext import commands import requests # 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 bot = commands.Bot(intents=intents) @discord.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 @discord.app_command(name="verify", description="Verify your account") async def verify(ctx: discord.SlashContext): # Check if the user is an admin if not ctx.author.guild_permissions.administrator: await ctx.send("Only admins can use this command.") 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, ) view = discord.ui.View() view.add_item(verify_button) await ctx.send(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.") 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(ctx.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!") # Run the bot bot.run("token")