I need help making my bot do something if the user mentioned already has the role specified Im getting an error that it can define get and it wont execute my if statement my code is here
module.exports = {
name: 'jail',
description: "This command mutes a member a member!",
execute(message, args, Discord) {
let target = message.mentions.users.first();
let memberTarget = message.guild.members.cache.get(target.id);
let test = GuildMember.roles.get(role => role.name === 'Jailed')
if (message.author.id === memberTarget.id) {
message.reply('You cant jail yourself dummy'); return;
} else {
}
if (memberTarget === test) {
message.channel.send('e'); return;
} else {
message.channel.send('jailed user')
}
}
The main problem is here
if (memberTarget === test) {
message.channel.send('e'); return;
} else {
message.channel.send('jailed user')
}
Any help is awesome
Note. Debugger said nothing wrong but there is cause my bot shuts down when i execute the command do to an error as it can define get
My problem is i cant get the role and execute my if statement
module.exports = {
name: 'jail',
description: "This command mutes a member a member!",
execute(message, args, Discord) {
let target = message.mentions.users.first();
let test = message.guild.roles.cache.find(role => role.name === 'Jailed');
if (message.author.id === target.id) {
return message.reply('You cant jail yourself dummy');
}
if (message.guild.member(target).roles.cache.some(role => role.name === test.name)) {
return message.channel.send('e');
} else {
message.guild.member(target).roles.add(test);
message.channel.send('jailed user')
}
}
I've made some changes in your code. I removed memberTarget
, because target
is sufficient in this case. test
finds the Jailed
role on the current guild. In the if-statement where we ask if target
already has the role, I've used a GuildMember Object for target
. .some()
returns true
or false
. So it searches inside the GuildMember Object of target
for the Jailed
role ( test.name
). If it was found on the Object it returns true
and goes inside the statement. Otherwise it goes to else
, where the GuildMember target
gets added to the role Jailed
( test
).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.