Okay so I am having trouble trying to DM a user who was kicked from the server right now it DM's the person who kicked the member. I don't know what I did wrong but I want the bot to DM the user who was kicked so they know why they were kicked frokm the server
const { RichEmbed } = require("discord.js")
const { red_dark } = require("../../colors.json");
module.exports = {
name: "kick",
description: "Kick a user from the guild!",
usage: "!kick",
category: "moderation",
accessableby: "Moderator",
aliases: ["k"],
run: async (bot, message, args, user) => {
try{
if (message.member.hasPermission("KICK_MEMBERS")) {
if (message.mentions.users.size != 0) {
if (message.mentions.members.first().kickable) {
let reason = args.slice(1).join(" ")
if(!reason) return message.channel.send("No reason was provided!")
else {
message.member.send("This is a test message")
message.mentions.members.first().kick().then(m => {
message.channel.send(`**${m.user.username}** has been kicked from **${message.guild.name}**. Bye bye!`)
});
}
} else {
message.channel.send(`:x: **${message.mentions.user.first().username}** is too priveledged for me to kick.`);
}
} else {
message.channel.send(':x: Please tag the user you would like to kick.')
}
} else {
message.channel.send(`:x: **${message.author.username}**, You do not have permission to kick. You must have the \`Kick Members\` permission.`);
}
} catch (err) {
message.channel.send(`:x: Either I am unable to kick **${message.mentions.users.first().username},** or I do not have permission to kick members.`);
}
}
}
You currently send a the DM to message.member. What you would need to do it to send it to the same person you actually kick, which you currently do with message.mentions.members.first().kick().
So with that clarified, you need to do message.mentions.members.first().send("This is a test message")
Related
So I want to have a moderation bot that kicks all members with a certain role e.g. "unverified" from the server.
1, is this possible?
2, is this allowed, or would it possibly be a Discord API Breach?
I have a normal kick/ ban command and despite searching the web for ages I can't find any answers. Any help would be hugely appreciated. Thanks in advance.
Yes it is possible, you would just have to be able to group them somehow, (say the role you mentioned for instance) and then run a forEach() on it and kick.
Is it allowed, yes.
Is it a breach: unclear depends on how many you are kicking but these commands will only kick in small groups (5 per 5 seconds).
Example below:
regular command:
(prefix)purge RoleName Reason
const { Discord, Permissions } = require('discord.js')
module.exports.run = async (client, message, args) => {
if (!message.member.Permissions.has("ADMINISTRATOR")) {
//handle however if they are not admin
} else {
let kicked = []
const role = message.guild.roles.cache.find(r => r.name === args[0])
args.shift()
const kickReason = args.join(' ') || 'No Reason'
message.guild.members.forEach(member => {
if (member.roles.has(role)) {
kicked.push(member)
member.kick({
reason: kickReason
})
}
})
const completeEmbed = new Discord.MessageEmbed()
.setTitle('Purge')
.setDescription(`Members with the following role have been purged "${role.name}".`)
.addField({
name: `The members kicked were:`,
value: `${kicked.join('\n')}`
})
message.channel.send({
embeds: [completeEmbed],
ephemeral: true
})
}
}
module.exports.help = {
name: "purge",
description: "Kick members with a certain role",
usage: "(prefix)purge [RoleName] [Reason]"
}
And as a slash command (interaction): and can be built differently if needed.
/purge role: Rolename reason: reason
const { Discord, Permissions, SlashCommandBuilder } = require('discord.js')
module.exports = {
data: new SlashCommandBuilder()
.setName('purge')
.setDescription('Purge server of role')
.addRoleOption(option =>
option
.setName('role')
.setDescription('Which role to purge')
.setRequired(true))
.addStringOption(option =>
option
.setName('reason')
.setDescription('Reason for purge.')
.setRequired(true)),
async execute(client, interaction) {
const reason4Kick = interaction.options.getString('reason')
const role2Kick = interaction.options.getRole('role')
if (!interaction.member.Permission.has('ADMINISTRATOR')) {
// handle if user doesn't have permission to run
return
} else {
let kicked = []
interaction.guild.members.forEach(member => {
if (member.roles.has(role2Kick)) {
kicked.push(member)
member.kick({
reason: reason4Kick
})
}
})
const completeEmbed = new Discord.MessageEmbed()
.setTitle('Purge')
.setDescription(`Members with the following role have been purged "${role.name}".`)
.addField({
name: `The members kicked were:`,
value: `${kicked.join('\n')}`
})
interaction.channel.reply({
embeds: [completeEmbed],
ephemeral: true
})
}
}
}
It's a strange question about lockdown channel but why this is not working?
This is the script of my lock command msg.channel.guild.roles.everyone if that everyone define as #everyone? I've seen this script in documents of discord permissions. I tried it but it's not working. And there's no error too.
client.on('messageCreate', msg => {
if(msg.content.toLowerCase().startsWith(`${prefix}lock`)){
msg.channel.permissionOverwrites.create(msg.channel.guild.roles.everyone, { SEND_MESSAGES: false });
msg.channel.send('Channel Locked')
}else if(msg.content.toLowerCase().startsWith(`${prefix}unlock`)){
msg.channel.permissionOverwrites.create(msg.channel.guild.roles.everyone, { SEND_MESSAGES: true });
msg.channel.send('Channel Unlocked')
}
});
message.channel.updateOverwrite(message.guild.id, {
SEND_MESSAGES: false
});
Unlocked the channel use
message.channel.updateOverwrite(message.guild.id, {
SEND_MESSAGES: null
});
for example
client.on("message", async message => {
if (message.content.startsWith(prefix + "lock")) {
if (!message.member.hasPermission("MANAGE_CHANNELS")) return;
if (!message.guild.member(client.user).hasPermission("MANAGE_CHANNELS"))
return;
message.channel.updateOverwrite(message.guild.id, {
SEND_MESSAGES: false
});
const lock = new Discord.MessageEmbed()
.setColor("#00000")
.setDescription(
`🔒 | Locked Channel
❯ **Channel Name :** <#${message.channel.id}>
❯ **Locked By :** <#${message.author.id}>
`
)
.setThumbnail(message.author.avatarURL())
.setFooter(`${message.author.tag}`, message.author.avatarURL())
.setTimestamp()
message.chaneel.send(lock);
}
});
This is embed
Not sure how to get the id of my target because it keeps reading it as undefined. I may have set up my argument incorrectly but I'm fairly sure that's not the issue. My command to kick is !o kick #user kick reason if that helps.
const { message } = require("discord.js")
module.exports = {
name: 'kick',
description: 'This command kicks a member',
execute(message, args){
if (message.member.hasPermission(["KICK_MEMBERS"])) {
const target = message.mentions.members.first();
if(target){
let [target, ...reasonKick] = args;
[...reasonKick].join(' ');
message.guild.members.cache.find(target => target.id)
const memberTarget = message.guild.members.cache.get(target.id);
if (message.guild.me.hasPermission("KICK_MEMBERS")) {
if (message.author.id === memberTarget) {
message.reply('why would you want to kick yourself?');
}
else if (message.client.user.id === memberTarget) {
message.channel.send('Nice try, but you can\'t kick me.')
}
else if (message.member.roles.highest.position > message.guild.members.cache.get(memberTarget).roles.highest.position) {
memberTarget.kick()
message.channel.send(`**${target.tag}** has been kicked. Reason: **${reasonKick}**.`);
}
else {
message.reply(`I don\'t have the required permission to kick **${target.tag}**`);
}
} else {
message.reply('I don\'t have the required permission to kick members');
}
} else{
message.reply('you must mention the member you want to kick.')
.catch;
}
} else {
message.reply("you do not have the permission to do that.")
.catch;
}
},
};
// - someCollection.find('property', value);
// + someCollection.find(element => element.property === value)
A mention already returns a member object, theres no need to try and get a member based on the mention's id.
Replace all of your memberTarget, with target
How can I mention the user who reacted to my bot message?I want to send message like, "#user reacted to my message!", here is my code:
msg.awaitReactions((reaction, user) => user.id == user.id && (reaction.emoji.name == '👍'), { max: 1, time: 30000 }).then(collected => {
if (collected.first().emoji.name == '👍') {
//here I want to send the message with the mention
} else {
//I added it for case that I going to use yes or no react question
}
}).catch(() => {
//maybe I will add here message that says the time passed.
});
After reading articles and troubleshooting I came up with the following solution:
msg.awaitReactions((reaction, user) => user.id == user.id && (reaction.emoji.name == '👍'),
{ max: 1, time: 30000 }).then(collected => {
const reaction = collected.first();
if (collected.first().emoji.name == '👍') {
const member = reaction.users.cache.find((user) => !user.bot);
message.channel.send(`test is ${member}`)
} else {
//I added it for case that I gonna use yes or no react question
}
}).catch(() => {
//maybe I will add here message that says the time passed.
});
I'm using discord.js v12 and I'm trying to make a account that adds a role or removes it if the user already has the role but I get error SyntaxError: unexpected token "{" I tried to find what's wrong but couldn't find anything please help
module.exports = {
name: 'notifications',
description: 'Adds/removes the order ping from you',
aliases: ['notif'],
execute(message) {
pingrole = '809748975162359809'
if (message.member.roles.cache.some(c => c.id === "Cybers taco stand employee") {
if (message.member.roles.cache.some(r => r.name === "orders ping")) {
message.author.roles.add(pingrole)
message.channel.send("Added your orders ping")
} else {
message.author.roles.remove(pingrole)
message.channel.send("Removed your orders ping role")
}
} else {
message.channel.send('You are not an employee')
}
}
}
You didn't declare the variable and you were missing one ")" at the end of if statement.
module.exports = {
name: 'notifications',
description: 'Adds/removes the order ping from you',
aliases: ['notif'],
execute(message) {
let pingrole = '809748975162359809'
if (message.member.roles.cache.some(c => c.id === "Cybers taco stand employee")) {
if (message.member.roles.cache.some(r => r.name === "orders ping")) {
message.author.roles.add(pingrole)
message.channel.send("Added your orders ping")
} else {
message.author.roles.remove(pingrole)
message.channel.send("Removed your orders ping role")
}
} else {
message.channel.send('You are not an employee')
}
}
}