I can't kick anyone with my discord bot because os this happening, idk why. This is what I get in my console:
ReferenceError: Discord is not defined at Object.execute (C:\Users\alber\OneDrive\Escritorio\Bot discord\mands\kick.js:17:21) at Client. (C:\Users\alber\OneDrive\Escritorio\Bot discord\index.js:34:15) at Client.emit (events.js:310:20) at MessageCreateAction.handle (C:\Users\alber\OneDrive\Escritorio\Bot discord\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14) ebsocket\handlers\MESSAGE_CREATE.js:4:32) at WebSocketManager.handlePacket (C:\Users\alber\OneDrive\Escritorio\Bot discord\node_modules\discord.js\src\client\websocket\WebSocketManager.js:386:31) at WebSocketShard.onPacket (C:\Users\alber\OneDrive\Escritorio\Bot discord\node_modules\discord.js\src\client\websocket\WebSocketShard.js:436:22) at WebSocketShard.onMessage (C:\Users\alber\OneDrive\Escritorio\Bot discord\node_modules\discord.js\src\client\websocket\WebSocketShard.js:293:10) at WebSocket.onMessage (C:\Users\alber\OneDrive\Escritorio\Bot discord\node_modules\ws\lib\event-target.js:120:16) at WebSocket.emit (events.js:310:20)
And this is part of the code:
const fs = require('fs');
const Discord = require('discord.js')
const { prefix, token } = require('./config.json');
const client = new Discord.Client();
clientmands = new Discord.Collection();
const mandFiles = fs.readdirSync('./mands').filter(file => file.endsWith('.js'));
for (const file of mandFiles) {
const mand = require(`./mands/${file}`);
clientmands.set(mand.name, mand);
}
And this is the kick mand that doesn't work (it only breaks when it should ban someone, the rest works):
module.exports = {
name: 'kick',
description: 'kicks the mentioned user',
execute(client, message, args){
var kickUser = message.guild.member(message.mentions.users.first() || message.guild.members.fetch(args[0]))
if(!kickUser){
return message.reply('¿no tageas a nadie? Kickear paraguayos es malardo.')
}
var kickReason = args.join(' ').slice(22)
if(!message.member.hasPermission(['KICK_MEMBERS'])){
return message.reply('enséñame los permisos que los vea yo que parece que no tienes.s')
}
if(kickUser.hasPermission(['KICK_MEMBERS'])){
return message.reply('no puedes echar a alguien con permisos de admin.')
}
var kickEmbed = new Discord.RichEmbed()
.setDescription('Kick')
.setColor('#35d4a7')
.addField('Server', guild.name)
.addField('Kickeado por', `@${message.author.id}`)
.addField('A las', message.createdTimestamp)
.addField('Motivo', kickReason)
message.guild.member(kickUser).kick(kickReason)
kickUser.send(kickEmbed)
},
};
I can't kick anyone with my discord bot because os this happening, idk why. This is what I get in my console:
ReferenceError: Discord is not defined at Object.execute (C:\Users\alber\OneDrive\Escritorio\Bot discord\mands\kick.js:17:21) at Client. (C:\Users\alber\OneDrive\Escritorio\Bot discord\index.js:34:15) at Client.emit (events.js:310:20) at MessageCreateAction.handle (C:\Users\alber\OneDrive\Escritorio\Bot discord\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14) ebsocket\handlers\MESSAGE_CREATE.js:4:32) at WebSocketManager.handlePacket (C:\Users\alber\OneDrive\Escritorio\Bot discord\node_modules\discord.js\src\client\websocket\WebSocketManager.js:386:31) at WebSocketShard.onPacket (C:\Users\alber\OneDrive\Escritorio\Bot discord\node_modules\discord.js\src\client\websocket\WebSocketShard.js:436:22) at WebSocketShard.onMessage (C:\Users\alber\OneDrive\Escritorio\Bot discord\node_modules\discord.js\src\client\websocket\WebSocketShard.js:293:10) at WebSocket.onMessage (C:\Users\alber\OneDrive\Escritorio\Bot discord\node_modules\ws\lib\event-target.js:120:16) at WebSocket.emit (events.js:310:20)
And this is part of the code:
const fs = require('fs');
const Discord = require('discord.js')
const { prefix, token } = require('./config.json');
const client = new Discord.Client();
client.mands = new Discord.Collection();
const mandFiles = fs.readdirSync('./mands').filter(file => file.endsWith('.js'));
for (const file of mandFiles) {
const mand = require(`./mands/${file}`);
client.mands.set(mand.name, mand);
}
And this is the kick mand that doesn't work (it only breaks when it should ban someone, the rest works):
module.exports = {
name: 'kick',
description: 'kicks the mentioned user',
execute(client, message, args){
var kickUser = message.guild.member(message.mentions.users.first() || message.guild.members.fetch(args[0]))
if(!kickUser){
return message.reply('¿no tageas a nadie? Kickear paraguayos es malardo.')
}
var kickReason = args.join(' ').slice(22)
if(!message.member.hasPermission(['KICK_MEMBERS'])){
return message.reply('enséñame los permisos que los vea yo que parece que no tienes.s')
}
if(kickUser.hasPermission(['KICK_MEMBERS'])){
return message.reply('no puedes echar a alguien con permisos de admin.')
}
var kickEmbed = new Discord.RichEmbed()
.setDescription('Kick')
.setColor('#35d4a7')
.addField('Server', guild.name)
.addField('Kickeado por', `@${message.author.id}`)
.addField('A las', message.createdTimestamp)
.addField('Motivo', kickReason)
message.guild.member(kickUser).kick(kickReason)
kickUser.send(kickEmbed)
},
};
Share
Improve this question
edited Jun 4, 2020 at 10:23
D. Pardal
6,5971 gold badge22 silver badges43 bronze badges
asked May 5, 2020 at 12:36
MrAlbolMrAlbol
11 gold badge1 silver badge1 bronze badge
3 Answers
Reset to default 2If you haven't redacted anything from the kick mand script, and copied it here as-is, you're missing the require statement for the Discord class.
Try importing it like const Discord = require('discord.js');
like you did in the first code block.
Try defining discord inside of the kick file,
const Discord = require("Discord")
module.exports..........
Or Call it in on exports.execute
module.exports = {
name: 'kick',
description: 'kicks the mentioned user',
execute(client, message, args, Discord){}
}
if you call it in the parameters you must also apply it to the mand handler
mand.execute(client, message, args, Discord)
Discord isn't defined in the mand file, as the other answers have said. If you want to save a few lines, just put this in your index.js
file.
global.Discord = require('discord.js')
I'm not sure what node version is required for this, but it should work if you are on the LTS. In this error, the error was pretty descriptive and stack overflow shouldn't be needed. Try reading the error and figuring it out next time. It clearly said it wasn't defined.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745064133a4609151.html
评论列表(0条)