DiscordTickets/commands/remove.js

76 lines
2.5 KiB
JavaScript
Raw Normal View History

2019-05-04 18:09:05 +03:00
const Discord = require('discord.js');
const config = require('../config.json');
2019-05-06 19:18:43 +03:00
const log = require(`leekslazylogger`);
2020-08-03 18:39:39 +03:00
2019-05-04 18:09:05 +03:00
module.exports = {
name: 'remove',
description: 'Remove a member from a ticket',
usage: '<@member>',
aliases: ['kick'],
example: 'remove @exampleUser',
args: true,
2019-05-04 18:09:05 +03:00
cooldown: config.cooldown,
guildOnly: true,
execute(message, args) {
const client = message.client;
// command starts here
message.delete();
2020-08-03 18:39:39 +03:00
if (!message.channel.name.startsWith('ticket-')) {
if (config.useEmbeds) {
const notTicket = new Discord.RichEmbed()
.setColor("#E74C3C")
.setDescription(`:x: **This command can only be used within a ticket channel**`)
return message.channel.send(notTicket);
} else {
return message.channel.send(`:x: **This command can only be used within a ticket channel**`)
}
}
2019-05-04 18:09:05 +03:00
let user = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
2020-08-03 18:39:39 +03:00
if (!user) {
if (config.useEmbeds) {
const err1 = new Discord.RichEmbed()
.setColor("#E74C3C")
.setDescription(`:x: **Unknown user.** Please mention a valid user.`)
return message.channel.send(err1);
} else {
return message.channel.send(`:x: **Unknown user.** Please mention a valid user.`);
}
}
try {
message.channel.overwritePermissions(user, {
SEND_MESSAGES: false,
READ_MESSAGES: false
});
2020-08-03 18:39:39 +03:00
if (config.useEmbeds) {
const removed = new Discord.RichEmbed()
.setColor(config.colour)
.setDescription(`${user} has been removed.`)
message.channel.send(removed);
} else {
message.channel.send(`${user} has been removed.`);
}
// log
2020-08-03 18:39:39 +03:00
if (config.useEmbeds) {
const embed = new Discord.RichEmbed()
.setAuthor(`${client.user.username} / Ticket Log`, client.user.avatarURL)
.setTitle("User Removed")
.setColor(config.colour)
.addField("Username", user, true)
.addField("Removed by", message.author, true)
.addField("Channel", message.channel, true)
.setFooter(`DiscordTickets`)
.setTimestamp();
2020-08-03 18:39:39 +03:00
client.channels.get(config.logChannel).send(embed);
} else {
client.channels.get(config.logChannel).send(`User removed to a ticket by **${message.author.tag} (${message.author.id})**`);
}
log.info(`${message.author.tag} removed a user to a ticket (#${message.channel})`)
} catch(error) {
log.error(error);
}
2019-05-04 18:09:05 +03:00
// command ends here
},
};