I need help with this code
const {
Client,
GatewayIntentBits,
REST,
Routes,
SlashCommandBuilder,
EmbedBuilder,
PermissionFlagsBits
} = require('discord.js');
require('dotenv').config(); // Load your token from .env file
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
// CONFIG
const TOKEN = process.env.TOKEN;
const CLIENT_ID = '1378861000748437565';
const GUILD_ID = '1361368496419897479';
const APPEAL_SERVER_ID = '1387182613571043359';
const REQUIRED_ROLE_ID = '1394360311900934256';
// Register slash command
const commands = [
new SlashCommandBuilder()
.setName('flag')
.setDescription('Globally flag and ban a user.')
.addStringOption(option =>
option.setName('userid')
.setDescription('The ID of the user to ban')
.setRequired(true))
.addStringOption(option =>
option.setName('reason')
.setDescription('Reason for ban')
.setRequired(true))
.addStringOption(option =>
option.setName('proof')
.setDescription('Proof URL (https://...)')
.setRequired(true))
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
.toJSON()
];
const rest = new REST({ version: '10' }).setToken(MTM3ODg2MTAwMDc0ODQzNzU2NQ.GPhsa4.7ndO848a9ByFxQdbsmJrtPORP5HWgP6zdcRDWU);
(async () => {
try {
console.log('Registering slash command...');
await rest.put(
Routes.applicationGuildCommands(1378861000748437565, 1361368496419897479),
{ body: commands }
);
console.log('Command registered.');
} catch (err) {
console.error('Failed to register command:', err);
}
})();
// Bot ready
client.once('ready', () => {
console.log(
✅ Logged in as ${client.user.tag});
});
// Handle command interaction
client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;
if (interaction.commandName === 'flag') {
const member = await interaction.guild.members.fetch(interaction.user.id);
// Check for the required role
if (!member.roles.cache.has(1394360313318604933)) {
return interaction.reply({
content: '❌ You do not have permission to use this command.',
ephemeral: true
});
}
const userId = interaction.options.getString('userid');
const reason = interaction.options.getString('reason');
const proof = interaction.options.getString('proof');
// Create embed
const embed = new EmbedBuilder()
.setTitle('🚫 Global Ban Issued')
.addFields(
{ name: 'User ID', value: userId, inline: true },
{ name: 'Banned By', value: <@${interaction.user.id}>, inline: true },
{ name: 'Reason', value: reason },
{ name: 'Proof', value: proof }
)
.setColor(0xff0000)
.setTimestamp();
try {
// Attempt ban on both servers
const mainGuild = await client.guilds.fetch(1361368496419897479);
const appealGuild = await client.guilds.fetch(1387182613571043359);
await mainGuild.members.ban(userId, { reason });
await appealGuild.members.ban(userId, { reason });
interaction.reply({ embeds: [embed] });
} catch (err) {
console.error(err);
interaction.reply({
content: ❌ Failed to ban user. Make sure the ID is correct and the bot has permission.,
ephemeral: true
});
}
}
});
client.login;(MTM3ODg2MTAwMDc0ODQzNzU2NQ.GPhsa4.7ndO848a9ByFxQdbsmJrtPORP5HWgP6zdcRDWU)14 Replies
Okay first of all you posted your token
Second, why is there a semi colon after login
I just copied the code
Third, the token isn't in a string
I have no clue
what you talking about
Do you know what a string is?
I am new
to bot dev
Okay well
#resources you should probably learn a little more js before trying to make a bot. Working with an API, even one managed by a library, can be pretty difficult
I recommend you take my answer and research what a string is in Javascript
Also you should reset your token in the dev portal... Like as soon as possible
I reseted it
chatgpt moment
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View