const {Command} = require('../../lib.js') const {EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle} = require('discord.js'); const channelM = require('../../models/channels'); class setfreegameschannel extends Command{ constructor(client){ super(client, { name: 'setFreegamesChannel', aliases:['freegamesc','freec'], description: 'Sets the channel that will receive the free games/deals updates.', needsAdmin:true, }) } async run(message, args) { //Check admin privilege if(args.length>0) { if(typeof args[0]=='string' && !isNaN(parseInt(args[0])) && args[0].length>17) { var newName = message.guild.channels.cache.get(args[0]).name; addChannel(args[0], newName); } else { sendMessage(2); } } else { sendMessage(2); } //Message sending function async function sendMessage(modifier, name) { const embed = new EmbedBuilder() embed.setFooter({text:'Rem-chan on ', iconURL:"https://i.imgur.com/g6FSNhL.png"}) embed.setAuthor({name:"Rem-chan", iconURL:"https://i.imgur.com/g6FSNhL.png",url:'https://rem.wordfights.com/addtodiscord'}); embed.setColor(0x110809); embed.setTimestamp() switch (modifier) { case 0: embed.setTitle(`Channel ${name} defined.`) break; case 1: embed.setTitle('Error'); embed.setDescription('You do not have the required permissions') break; case 2: embed.setTitle('Error'); embed.setDescription('Verify the arguments used.') break; default: break; } const row = new ActionRowBuilder() .addComponents( new ButtonBuilder() .setCustomId('RemoveRustCommitsNewChannelMessage') .setLabel('Remove this.') .setStyle(ButtonStyle.Primary), ); const filter = i => i.customId === 'RemoveRustCommitsNewChannelMessage'; const Message = await message.channel.send({ephemeral: true, embeds: [embed], components: [row] }); const collector = message.channel.createMessageComponentCollector({ filter, time: 60000 }); collector.on('collect', async m => { collector.stop(); message.delete(); m.message.delete() }); collector.on('end', async ()=> { Message.edit({ components: [] }); }) } function addChannel(id, name) { var channel = new channelM(); channel.name = name; channel.cID = id; channel.for = 'freegames'; channel.save(err=> { if(err)console.log(err); sendMessage(0, name); }) } } }module.exports = setfreegameschannel;