'discord is not defined discord.js 13 problem with ban.js
I know this is basic error but someone can help me with it? I'm too dumb for it...
I would like to make ban command but something wrong with the code, I code for like 2 weeks so please be understanding, Thank you.
This is my main file
const Discord = require('discord.js');
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES" , "GUILD_MESSAGE_REACTIONS" , "DIRECT_MESSAGE_REACTIONS" , "GUILD_MEMBERS"] , partials: ["MESSAGE" , "CHANNEL" , "REACTION"] });
const prefix = '-';
const welcome = require('./commands/welcome'); // Add This
const fs = require('fs');
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', () => {
console.log('BOT is online!');
setInterval(() => {
const statuses = [
`-HELLO`,
`TEST2 `,
]
const status = statuses[Math.floor(Math.random() * statuses.length)]
client.user.setActivity(status, { type: "WATCHING"}) // Can Be WATCHING, STREAMING, LISTENING
}, 2000) // Second You Want to Change Status, This Cahnges Every 2 Seconds
welcome(client)
});
client.on('messageCreate' , message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'TEST') {
client.commands.get('TEST').execute(message, args, Discord);
} else if (command === 'rr') {
client.commands.get('rr').execute(message, args, Discord, client);
} else if (command === 'ban') {
client.commands.get('ban').execute(message, args, Discord, client, Discord.CommandInteraction);
}
});
client.login('my token')
This is my ban file
const {Client, CommandInteraction, MessageEmbed} = require(discord.js);
module.exports = {
name: "ban",
description: "BAN",
permission: "ADMIN",
options: [
{
name: "target",
description: "b",
type: "user",
required: true,
},
{
name: "reason",
description: "b",
type: "STRING",
required: true,
},
{
name: "messages",
description: "t",
type: "STRING",
required: true,
choises: [
{
name: "7 days",
value: "7",
}
]
},
],
/**
*
* @param {Client} client
* @param {CommandInteraction} interaction
*/
execute(client, interaction) {
const Target =interaction.options.getMember('target');
const Amount = interaction.options.getString('messages')
Target.ban({ days: Amount, reason: reason })
interaction.followUp({ embeds: [new MessageEmbed().setColor("GREEN").setDescription(`😇 **$${Target.user.username}**bye`)] })
}
}
Here error:
const { Client, CommandInteraction, MessageEmbed } = require(discord.js);
^
ReferenceError: discord is not defined
I would be grateful if someone wrote me what I did wrong and also told me what I should add / remove / replace. I'm too beginner to get answers like "Forgot to add ... so add it" Please let me know what exactly should I add and where, thank you for your patient and help!
Solution 1:[1]
Javascript is interpreting discord as an object in the require statement as you have not already defined it as a string, it must be a string to be properly required and imported.
change
const { Client, CommandInteraction, MessageEmbed } = require(discord.js);
to
const { Client, CommandInteraction, MessageEmbed } = require('discord.js');
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Finbar |
