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);