Reputation: 11
I watched a youtube video as a reference and I did as he did in the video but I got an error and I cross-checked it many times but I couldn't find the error.
The main.js script is below
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = '.';
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('LaskiBOT is online!')
});
client.on('message', (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 === 'ping') {
client.commands.get('ping').execute(message, args);
} else if(command === 'youtube') {
client.commands.get('youtube').execute(message, args);
} else if(command === 'command') {
client.commands.get('command').execute(message, args, Discord);
} else if(command === 'clear') {
client.commands.get('clear').execute(message, args);
} else if(command === 'kick') {
client.commands.get('kick').execute(message, args);
} else if(command === 'ban') {
client.commands.get('ban').execute(message, args);
} else if(command === 'mute') {
client.commands.get('mute').execute(message, args);
}
});
client.login('Token');
and the error is in the mut.js file
module.exports = {
name: 'mute',
description: "This command mutes a member!",
execute(message, args) {
const target = message.mentions.users.first();
if (target){
let mainRole = message.guild.roles.cache.find(role => role.name === 'Member');
let muteRole = message.guild.roles.cache.find(role => role.name === 'mute');
let memberTarget = message.guild.members.cache.get(target.id);
memberTarget.roles.remove(mainRole.id);
memberTarget.roles.add(muteRole.id);
message.channel.send(`<@${memberTarget.user.id}> has been muted`)
} else{
message.channel.send('Cant find that member!');
}
}
}
The error comes while running this is
Upvotes: 1
Views: 449
Reputation: 736
It seems that the code has failed to find the muteRole on this line:
let muteRole = message.guild.roles.cache.find(role => role.name === 'mute');
Please check that the role is called mute
?
If it is, remove the above mentioned line and replace
memberTarget.roles.add(muteRole.id);
with
memberTarget.roles.add("ROLEIDGOESHERE");
Instead of ROLEIDGOESHERE
enter the ID of the mute role. You can do the following to get the role ID:
To get the ID of a role, you can either mention it with a \ before it, like \@rolename, or copy it from the role menu. If you mention it, the ID is the numbers between the <>. To get the ID of a role without mentioning it, enable developer mode in the Appearance section of your user settings, then go to the role menu in the server settings and right click on the role you want the ID of, then click "Copy ID".
This info was found here
Upvotes: 1