Hello i wanted to mentions the user that are running the command but i am getting a Error
Here is the Code!
const Discord = require("discord.js")
module.exports = {
name: 'not-dropping',
description: 'sets the dropping status!',
execute(message, args) {
if (message.channel.id === '1059798572855476245') {
message.delete(1000);
const name = ("dropping-🔴")
message.channel.setName(name)
message.channel.send(`Successfully set the dropping status to **${name}**\n<#${msg.author.id}> is not Dropping anymore!\nDont Ping Him in your Ticket.`)
}
}
}
I do not understand waht the Problem is
As the error states "msg" is not defined.
In the code "{msg.author.id}" you are using msg while the actual variable is "message".
Change it to {message.author.id}
"msg" There is no such use
You should use "message"
I changed where you need to change in the code :)
const Discord = require("discord.js")
module.exports = {
name: 'not-dropping',
description: 'sets the dropping status!',
execute(message, args) {
if (message.channel.id === '1059798572855476245') {
message.delete(1000);
const name = ("dropping-🔴")
message.channel.setName(name)
message.channel.send(`Successfully set the dropping status to **${name}**\n<#${message.author.id}> is not Dropping anymore!\nDont Ping Him in your Ticket.`)
}
}
}
Related
I am making a administration bot in discord with discord.js. I am trying to make a command which gives the user a specific role. So I want to make it check first if that user has that specific role beforehand or not to avoid errors. The problem lies in the if statement which checks if the user has the role, its giving me a error "TypeError: Cannot read properties of undefined (reading 'has')". Please suggest me how to fix this.
const {
Role,
ThreadManager
} = require("discord.js");
const ms = require('ms');
module.exports = {
name: 'gulag',
description: "gulag",
execute(message, args) {
if (message.member.permissions.has("ADMINISTRATORS")) {
const target = message.mentions.users.first();
const check = message.mentions.users.first();
if (target) {
let gulagRole = message.guild.roles.cache.find(role => role.name === 'gulag');
let memberTarget = message.guild.members.cache.get(target.id);
if (check.roles.has(gulagRole.id)) {
message.reply(`<#${memberTarget.user.id}> is already in gulag.`)
} else {
memberTarget.roles.add(gulagRole.id);
message.channel.send(`<#${memberTarget.user.id}>`);
message.channel.send('https://tenor.com/view/gulag-warzone-call-of-duty-cod-battle-royale-gif-16853559');
}
}
}
}
}
I would go straight for message.mentions.members.first() because this will return GuildMember so it is easier to then check the roles
const target = message.mentions.members.first()
if(target){
if(target.roles.cache.find(r => r.name === 'gulag')){
//REST OF THE STUFF
}
}
If you are using v13 remember to declare Intents for your Client as well.
So I don't wanna make a mess out of my Main.js so I try to make every possible command through module.exports in other documents.js
Basically I need that if I send a command, the bot will delete my message and post a comment+embed on a specific channel.
This is what I have (making it simple):
module.exports = {
name: 'chtest',
execute(message, args, Discord) {
let chComment = 'Normal comment';
chComment += '\nLine2';
message.channel.send(chComment)
const chEmbed = blablaEmbedCode
message.channel.send(chEmbed)
message.delete();
},s
};
I've read another Questions and they use
client.channels.cache.get(`Channel_ID`).send('Text')
I tried using it but I got an error ReferenceError: client is not defined
I added Client to my execute line:
execute(client, message, args, Discord) {
And now I have another error TypeError: Cannot read property 'cache' of undefined
And... I don't know what to do now. Any solutions?
Thank you in advance.
Try this using the Message class' client property. Here are the docs for it.
module.exports = {
name: 'chtest',
execute(message, args, Discord) {
let channel = message.client.channels.cache.get('CHANNEL_ID');
//channel is now the channel, unless it could not be found.
channel.send('Message');
/*let chComment = 'Normal comment';
chComment += '\nLine2';
message.channel.send(chComment)
const chEmbed = blablaEmbedCode
message.channel.send(chEmbed)
message.delete();*/
},
};
I am making a nickname command for my Discord.JS bot. I want to make it so that if the bot or member has a lower role than the target, it returns an error message. I am using the Commando command handler. Here is my code:
const Commando = require('discord.js-commando')
module.exports = class NicknameCommand extends Commando.Command {
constructor(client) {
super(client, {
name: 'nickname',
aliases: ['nick'],
group: 'misc',
memberName: 'nickname',
userPermissions: [
'MANAGE_NICKNAMES',
'CHANGE_NICKNAME'
],
clientPermissions: [
'MANAGE_NICKNAMES',
'CHANGE_NICKNAME'
],
description: 'Changes the nickname of a user',
argsType: 'multiple'
})
}
run = (message, args) => {
const target = message.mentions.users.first()
if(!target) {
return message.reply('Please specify a valid member to change the nickname of')
}
if(message.member.roles.highest.position < target.roles.highest.position) {
return message.channel.send('You do not have a high enough role to change this member\'s nickname')
}
if(message.guild.me.roles.highest.position < target.roles.highest.position) {
return message.channel.send('I do not have a high enough role to change this member\'s nickname')
}
const member = message.guild.members.cache.get(target.id)
args.shift()
const nickname = args.join(' ')
if(nickname.length > 32) {
return message.reply('That nickname is too long! Please make it less than 32 characters')
}
member.setNickname(nickname)
message.reply(`Successfully changed the user's nickname to '${nickname}'`)
}
}
The Discord Commando makes it so it throws an error through a message in the bot, so I do not have a specific console log error, but the bot responded:
An error occurred while running the command: TypeError: Cannot read property 'highest' of undefined
The error appears to be around line 28. I know that the syntax for the highest role is not correct, but I don't know the correct one. Is there a fix to this? Thanks
I tried everything at it would give me errors such as
TypeError: Cannot read property 'setDeaf' of undefined
Please and thank you.
const Discord = require('discord.js');
const config = require('../config.json')
module.exports.run = async (bot, message, args, config) => {
if(message.author.id !== "247227873734295562") return message.channel.send("no perms")
const mUser = message.mentions.members.first() || message.guild.members.get(args[0]);
let isDeafened = false;
if(!mUser) {
message.channel.send("You need to mention a user!")
}
if(mUser) {
mUser.voice.setDeaf(true)
}
}
module.exports.help = {
name: "d",
description: "Server deafens a mentioned user forever",
usage: `${config.prefix}d <#mention>`,
ex: `${config.prefix}d <#247227873734295562>`
}
Looking at your code and you getting that error seems to show, that mUser doesn't have the property voice.
Which Discord.js version do you use?
mUser.voice.setDeaf(true) was added in v12. So, if you have an earlier version, you should use mUser.setDeaf(true) instead.
I'm working on a command where when you do the command, d!woa the following happens
A webhook gets created with a certain name, Then a role gets created with the channel name, after that the bot watches if there's a webhook with that certain name for the channel, and just sees if anyone sends a message in that channel. If it does, then the bot will add that role with the certain name.
The problem is that there's this error : TypeError: Cannot read property 'guild' of undefined
The error will most likely appear at the end of the code provided.
I've tried rearranging the code, defining guild, and defining message. It does not seem to work even after trying all of this. I only want it to rely off of the ID instead of Name to be accurate for this command.
const Discord = require('discord.js');
const commando = require('discord.js-commando');
class woa extends commando.Command
{
constructor(client) {
super(client, {
name: 'watchoveradd',
group: 'help',
memberName: 'watchoveradd',
description: 'placeholder',
aliases: ['woa'],
})
}
async run(message, args){
if (message.channel instanceof Discord.DMChannel) return message.channel.send('This command cannot be executed here.')
else
if(!message.member.guild.me.hasPermission(['MANAGE_WEBHOOKS'])) return message.channel.send('I don\'t have the permissions to make webhooks, please contact an admin or change my permissions!')
if(!message.member.guild.me.hasPermission(['MANAGE_ROLES'])) return message.channel.send('I don\'t have the permissions to make roles, please contact an admin or change my permissions!')
if (!message.member.hasPermission(['MANAGE_WEBHOOKS'])) return message.channel.send('You need to be an admin or webhook manager to use this command.')
if (!message.member.hasPermission(['MANAGE_ROLES'])) return message.channel.send('You need to be an admin or role manager to use this command.')
const avatar = `...`;
const name2 = "name-1.0WOCMD";
let woaID = message.mentions.channels.first();
if(!woaID) return message.channel.send("Channel is nonexistant or command was not formatted properly. Please do s!woa #(channelname)");
let specifiedchannel = message.guild.channels.find(t => t.id == woaID.id);;
specifiedchannel.send('test');
const hook = await woaID.createWebhook(name2, avatar).catch(error => console.log(error))
await hook.edit(name2, avatar).catch(error => console.log(error))
message.channel.send("Please do not tamper with the webhook or else the command implied before will no longer function with this channel.")
setTimeout(function(){
message.channel.send('Please wait...');
}, 10);
setTimeout(function(){
var role = message.guild.createRole({
name: `Name marker ${woaID.name} v1.0`,
color: 0xcc3b3b,}).catch(console.error);
if(role.name == "name marker") {
role.setMentionable(false, 'SBW Ping Set.')
role.setPosition(10)
role.setPermissions(['CREATE_INSTANT_INVITE', 'SEND_MESSAGES'])
.then(role => console.log(`Edited role`))
.catch(console.error)};
}, 20);
var sbwrID = member.guild.roles.find(`Synthibutworse marker ${woaID} v1.0`);
let specifiedrole = message.guild.roles.find(r => r.id == sbwrID.id)
setTimeout(function(){
message.channel.send('Created Role... Please wait.');
}, 100);
message.guild.specifiedchannel.replacePermissionOverwrites({
overwrites: [
{
id: specifiedrole,
denied: ['SEND_MESSAGES'],
allowed: ['VIEW_CHANNEL'],
},
],
reason: 'Needed to change permissions'
});
var member = client.user
var bot = message.client
bot.on('message', function(message) { {
if(message.channel.id == sbwrID.id) {
let bannedRole = message.guild.roles.find(role => role.id === specifiedrole);
message.member.addRole(bannedRole);
}
}})
}};
module.exports = woa;
I expect a command without the TypeError, and the command able to create a role and a webhook (for a marker), and the role is automatically set so that the user that has the role won't be able to speak in the channel, and whoever speaks in the channel will get the role.
The actual output is a TypeError: Cannot read property 'guild' of undefined but a role and webhook are created.
You have var sbwrID = member.guild...
You did not define member. Use message.member.guild...
You can setup a linter ( https://discordjs.guide/preparations/setting-up-a-linter.html ) to find these problems automatically.