Making a verify all command for discord

** WHAT IM TRYING TO MAKE **
As it says it in the name, im trying to make a discord to roblox bot… while i was making the commands, I wanted to make a verifyall command.

** THIS IS THE WHOLE PYTHON CODE **

import api
import discord
from discord import app_commands
import json
import os
import requests
import saveroblox
import verification
import discordroles
import asyncio

intents = discord.Intents.all()
client = discord.Client(intents=intents)
tree = app_commands.CommandTree(client)

#saveroblox.link(1081767981211717704, 59128361)
@tree.command(
  name="verify",
  description="Connect to a Roblox account.",
  guild=discord.Object(id=1153025753697501194)
)  # Add the guild ids in which the slash command will appear. If it should be in all, remove the argument, but note that it will take some time (up to an hour) to register the command if it's for all guilds.
async def verify_command(interaction: discord.Interaction,
                         roblox_userid: str):

  getsentence = verification.getSentenceForUserId(str(interaction.user.id))
  id = requests.get(
        f'https://users.roblox.com/v1/users/{roblox_userid}'
    )

  if id.status_code == 200:
    y = json.loads(id.content)
    userid = y["id"]
    if saveroblox.get(userid) == False:

      account = requests.get(f'https://users.roblox.com/v1/users/{userid}')
      if account.status_code == 200:
        accountresponse = json.loads(account.content)
        bio = accountresponse["description"]

        if getsentence in bio:
          
          await interaction.response.send_message(
            f'{interaction.user.mention} is now successfully verified!',
            ephemeral=False)
          saveroblox.link(interaction.user.id, userid)
        else:
          await interaction.response.send_message(
            f'Hello {y["name"]}, please put this code in your Roblox description: `{getsentence}`\n\nAfter doing so, run `/verify`.',
            ephemeral=True)
    else:
      await interaction.response.send_message(
        f'{interaction.user.mention} is already verified!', ephemeral=True)
  else:
    await interaction.response.send_message("Sorry, I can't find that user.",
                                            ephemeral=True)


@tree.command(
  name="verifyall",
  description="Verify all members in the server.",
  guild=discord.Object(id=1153025753697501194)
)
async def verify_all_command(interaction: discord.Interaction):
  guild = interaction.guild
  role = guild.get_role(1059209570846781561)

  # Fetch all members in the server
  members = await guild.fetch_members().flatten()

  for member in members:
      roblox_userid = "GET_THE_USER_ID"  # You need to replace this with your logic

      id = requests.get(f'https://users.roblox.com/v1/users/{roblox_userid}')

      if id.status_code == 200:
          y = json.loads(id.content)
          userid = y["id"]

          await member.add_roles(role)
          await interaction.response.send_message(
              f'{member.mention} is now successfully verified as **{y["name"]}**!',
              ephemeral=False)
          saveroblox.link(member.id, userid)
      else:
          await interaction.response.send_message(
              f"Sorry, I couldn't find the Roblox user for {member.display_name}.",
              ephemeral=True)

  await interaction.response.send_message(
      "Force verification process for all members completed!",
      ephemeral=True
  )
  
@tree.command(
  name="getcode",
  description="Get your verification code.",
  guild=discord.Object(id=1153025753697501194)
)  # Add the guild ids in which the slash command will appear. If it should be in all, remove the argument, but note that it will take some time (up to an hour) to register the command if it's for all guilds.
async def get_code(interaction: discord.Interaction):
  getsentence = verification.getSentenceForUserId(interaction.user.id)
  await interaction.response.send_message(
    f'Please put this code in your Roblox description: `{getsentence}`\n\nAfter doing so, run `/verify`.',
    ephemeral=True)


@tree.command(
  name="getlinkedacc",
  description="See linked account.",
  guild=discord.Object(id=1153025753697501194)
)  # Add the guild ids in which the slash command will appear. If it should be in all, remove the argument, but note that it will take some time (up to an hour) to register the command if it's for all guilds.
async def get_linked_acc(interaction: discord.Interaction):
  robloxid = saveroblox.get(interaction.user.id)
  if robloxid:
    await interaction.response.send_message(
      f'{interaction.user.mention} is linked to https://www.roblox.com/users/{robloxid}/profile.',
      ephemeral=True)


  

@tree.command(
  name="stats",
  description="see players leading stats",
  guild=discord.Object(id=1153025753697501194)
)
@app_commands.describe(statsheet='Stats To Choose From')
@app_commands.choices(statsheet=[
  discord.app_commands.Choice(name="wr", value = 1),
  discord.app_commands.Choice(name="qb", value = 2),
  discord.app_commands.Choice(name="rb", value = 3),
  discord.app_commands.Choice(name="cb", value = 4),
  discord.app_commands.Choice(name="te", value = 5),
  discord.app_commands.Choice(name="c", value = 6),
])
async def stats(interaction: discord.Interaction, statsheet: discord.app_commands.Choice[int]):
    await interaction.response.send_message(f'Stat Sheet Selected: {statsheet.name}',ephemeral=True)




@client.event
async def on_ready():
  await tree.sync(guild=discord.Object(id=1153025753697501194))
  print("Ready!")

def getroles(discorduser: int): #1153025753697501194
  guild = client.get_guild(1153025753697501194)
  user = guild.get_member(discorduser)

  if user:
    for role in user.roles:
      if str(role.id) in discordroles.getroles():
        return discordroles.getroles()[str(role.id)]

def getteamrole(discorduser: int): #1153025753697501194
  guild = client.get_guild(1153025753697501194)
  user = guild.get_member(discorduser)

  if user:
    for role in user.roles:
      if str(role.id) in discordroles.getTeamRoles():
        return discordroles.getTeamRoles()[str(role.id)]

def getbooster(discorduser: int): #1153025753697501194
  guild = client.get_guild(1153025753697501194)
  user = guild.get_member(discorduser)

  if user:
    for role in user.roles:
      if str(role.id) in discordroles.getSpecialRoles():
        return discordroles.getSpecialRoles()[str(role.id)]

def login():
  my_secret = os.environ['DISCORD_BOT_SECRET']
  client.run(my_secret)

All the commands work perfectly fine aside from the VerifyAll command, im also using replit if that helps aswell

1 Like

I quite dont understand what u mean,maybe u mean like this:

How to connect a discord bot to a roblox game

1 Like

Hey Baccon!

So to make the verifyall command functional, resolve how to obtain or associate a Roblox user ID with each Discord user in your server. Since you have a saveroblox.link function, it suggests you might already have some infrastructure for linking Discord and Roblox accounts.

Here are some steps to go through:

  1. Implement a Method to Retrieve Roblox User IDs
  2. Update the verify_all_command Function
  3. Consider Rate Limiting and API Calls
  4. Error Handling
  5. Command Feedback

All the bullets are brief to keep the message clear so if you have any questions or suggestions, let me know!

#Ditu