nightmare_crystal1

build a discord bot for spam report a roblox player with the command /report

Kodari AI
KodariOct 22 at 9:35 pm 1
RobloxReportBot
Discord bot that automates spam reporting of Roblox players via the /report command. Features a slash command interface for initiating reports, configurable report templates, rate limiting to prevent abuse, and logging of all submitted reports. Integrates with Discord's API to send formatted report messages to designated channels. Includes cooldown management, user verification, and admin controls for managing report frequency and targets. Provides real-time status updates and error handling for failed submissions.
  • Create a Discord.js bot configured with environment variables.

  • Register /report with a Roblox username, spam details, and optional evidence link.

  • Send reports to a configured moderator channel; the bot won’t automate Roblox’s reporting system.

Created the Discord bot with /report username details [evidence]. It forwards reports to the configured moderator channel for review; it does not submit reports to Roblox.

Set DISCORD_TOKEN, DISCORD_CLIENT_ID, and REPORT_CHANNEL_ID in the bot’s environment. DISCORD_GUILD_ID is optional and registers the command to one server for faster testing; without it, /report is registered globally. Invite the bot with the bot and applications.commands scopes, plus permission to view and send messages and embed links in the report channel.

Kodari can make mistakes. Review important code before using.
Files
index.js
package.json
Code
2 157
index.js
import {
  Client,
  EmbedBuilder,
  GatewayIntentBits,
  REST,
  Routes,
  SlashCommandBuilder
} from "discord.js";

const token = process.env.DISCORD_TOKEN;
const clientId = process.env.DISCORD_CLIENT_ID;
const guildId = process.env.DISCORD_GUILD_ID;
const reportChannelId = process.env.REPORT_CHANNEL_ID;

if (!token || !clientId) {
  throw new Error("Set DISCORD_TOKEN and DISCORD_CLIENT_ID before starting the bot.");
}

const reportCommand = new SlashCommandBuilder()
  .setName("report")
  .setDescription("Submit a spam report about a Roblox player")
  .addStringOption(option =>
    option
      .setName("username")
      .setDescription("The Roblox username of the player")
      .setRequired(true)
      .setMinLength(3)
      .setMaxLength(20)
  )
  .addStringOption(option =>
    option
      .setName("details")
      .setDescription("Describe the spam behavior")
      .setRequired(true)
      .setMaxLength(1000)
  )
  .addStringOption(option =>
    option
      .setName("evidence")
      .setDescription("Optional link to evidence (image, video, or message)")
      .setRequired(false)
      .setMaxLength(2048)
  );

const rest = new REST({ version: "10" }).setToken(token);
const commandRoute = guildId
  ? Routes.applicationGuildCommands(clientId, guildId)
  : Routes.applicationCommands(clientId);

await rest.put(commandRoute, { body: [reportCommand.toJSON()] });
console.log(`Registered /report ${guildId ? `for guild ${guildId}` : "globally"}.`);

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.once("ready", readyClient => {
  console.log(`Logged in as ${readyClient.user.tag}.`);
  if (!reportChannelId) {
    console.warn("REPORT_CHANNEL_ID is not set; reports cannot be delivered yet.");
  }
});

client.on("interactionCreate", async interaction => {
  if (!interaction.isChatInputCommand() || interaction.commandName !== "report") return;

  if (!interaction.inGuild()) {
    await interaction.reply({ content: "Use /report in a server.", ephemeral: true });
    return;
  }

  const username = interaction.options.getString("username", true).trim();
  const details = interaction.options.getString("details", true).trim();
  const evidence = interaction.options.getString("evidence")?.trim();

  if (!/^[A-Za-z0-9_]{3,20}$/.test(username)) {
    await interaction.reply({
      content: "Enter a valid Roblox username (3–20 letters, numbers, or underscores).",
      ephemeral: true
    });
    return;
  }

  if (!details) {
    await interaction.reply({ content: "Add details about the spam in your report.", ephemeral: true });
    return;
  }

  let evidenceUrl;
  if (evidence) {
    try {
      evidenceUrl = new URL(evidence);
      if (evidenceUrl.protocol !== "http:" && evidenceUrl.protocol !== "https:") {
        throw new Error("Unsupported URL protocol");
      }
    } catch {
      await interaction.reply({
        content: "Evidence must be a valid http or https link.",
        ephemeral: true
      });
      return;
    }
  }

  if (!reportChannelId) {
    await interaction.reply({
      content: "Reports aren’t configured yet. Ask a server moderator to set REPORT_CHANNEL_ID.",
      ephemeral: true
    });
    return;
  }

  await interaction.deferReply({ ephemeral: true });

  try {
    const channel = await client.channels.fetch(reportChannelId);
    if (!channel?.isTextBased() || !channel.send) {
      throw new Error("Configured report channel is not a text channel.");
    }

    const embed = new EmbedBuilder()
      .setColor(0xe74c3c)
      .setTitle("Roblox Spam Report")
      .addFields(
        { name: "Roblox username", value: username, inline: true },
        { name: "Reported by", value: `${interaction.user.tag} (${interaction.user.id})`, inline: true },
        { name: "Server", value: `${interaction.guild.name} (${interaction.guild.id})` },
        { name: "Spam details", value: details }
      )
      .setTimestamp();

    if (evidenceUrl) {
      embed.addFields({ name: "Evidence", value: evidenceUrl.toString() });
    }

    await channel.send({ embeds: [embed] });
    await interaction.editReply("Your report has been sent to this server’s moderators for review. It has not been submitted to Roblox.");
  } catch (error) {
    console.error("Could not deliver Roblox spam report:", error);
    await interaction.editReply("The report could not be delivered. Please contact a server moderator.");
  }
});

await client.login(token);