From 7143bdead23a35db87f54dad6697ccfc6307b993 Mon Sep 17 00:00:00 2001 From: "Isaac (eartharoid)" Date: Wed, 14 Oct 2020 17:58:42 +0100 Subject: [PATCH] Create transfer.js Co-Authored-By: iFusion <31099360+iFusionFr@users.noreply.github.com> --- src/commands/transfer.js | 87 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/commands/transfer.js diff --git a/src/commands/transfer.js b/src/commands/transfer.js new file mode 100644 index 0000000..28cd670 --- /dev/null +++ b/src/commands/transfer.js @@ -0,0 +1,87 @@ +/** + * + * @name DiscordTickets + * @author eartharoid + * @license GNU-GPLv3 + * + */ + +const { MessageEmbed } = require('discord.js'); + +module.exports = { + name: 'transfer', + description: 'Transfer ownership of a ticket channel', + usage: '<@member>', + aliases: ['none'], + example: 'transfer @user', + args: true, + async execute(client, message, args, { config, Ticket }) { + const guild = client.guilds.cache.get(config.guild); + + let ticket = await Ticket.findOne({ + where: { + channel: message.channel.id + } + }); + + if (!ticket) { + return message.channel.send( + new MessageEmbed() + .setColor(config.err_colour) + .setAuthor(message.author.username, message.author.displayAvatarURL()) + .setTitle(':x: **This isn\'t a ticket channel**') + .setDescription('Use this command in the ticket channel you want to change owner.') + .addField('Usage', `\`${config.prefix}${this.name} ${this.usage}\`\n`) + .addField('Help', `Type \`${config.prefix}help ${this.name}\` for more information`) + .setFooter(guild.name, guild.iconURL()) + ); + } + + if (!message.member.roles.cache.has(config.staff_role)) + return message.channel.send( + new MessageEmbed() + .setColor(config.err_colour) + .setAuthor(message.author.username, message.author.displayAvatarURL()) + .setTitle(':x: **No permission**') + .setDescription('You don\'t have permission to change ownership of this channel as you are not staff.') + .addField('Usage', `\`${config.prefix}${this.name} ${this.usage}\`\n`) + .addField('Help', `Type \`${config.prefix}help ${this.name}\` for more information`) + .setFooter(guild.name, guild.iconURL()) + ); + + let member = guild.member(message.mentions.users.first() || guild.members.cache.get(args[0])); + + if (!member) { + return message.channel.send( + new MessageEmbed() + .setColor(config.err_colour) + .setAuthor(message.author.username, message.author.displayAvatarURL()) + .setTitle(':x: **Unknown member**') + .setDescription('Please mention a valid member.') + .addField('Usage', `\`${config.prefix}${this.name} ${this.usage}\`\n`) + .addField('Help', `Type \`${config.prefix}help ${this.name}\` for more information`) + .setFooter(guild.name, guild.iconURL()) + ); + } + + + message.channel.setTopic(`${member} | ${ticket.topic}`); + + Ticket.update({ + creator: member.user.id + }, { + where: { + channel: message.channel.id + } + }); + + message.channel.send( + new MessageEmbed() + .setColor(config.colour) + .setAuthor(message.author.username, message.author.displayAvatarURL()) + .setTitle(':white_check_mark: **Ticket transferred**') + .setDescription(`Ownership of this ticket has been transferred to ${member}.`) + .setFooter(client.user.username, client.user.displayAvatarURL()) + ); + } +};