const { Client,ChannelType, Interaction, ApplicationCommandOptionType, PermissionFlagsBits,PermissionsBitField,EmbedBuilder,ActionRowBuilder,ButtonBuilder, ButtonStyle,SlashCommandBuilder, ComponentType, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, Embed, } = require('discord.js'); const Parser = require(`rss-parser`); const notifyYtschema = require(`/Java Script Coding/Rudi Bot/schemas/notifyYtschema`); const parser = new Parser(); module.exports = { data: new SlashCommandBuilder() .setName(`youtube-notifier`) .setDescription( 'Configure your yt notifying system') .addSubcommand(command => command.setName(`add`).setDescription(`Set up the yt notifying system`).addStringOption(option => option.setName(`channel-id`).setDescription(`The ID of your youtube channel`).setRequired(true)).addChannelOption(option => option.setName(`channel`).setDescription(`The channel to send notifications in`).setRequired(true).addChannelTypes(ChannelType.GuildText)).addStringOption(option => option.setName(`message`).setDescription(`A custom message for your notification. Use {author}, {link} and {title}`).setRequired(false)).addRoleOption(option => option.setName(`role`).setDescription(`The role you want to be pinged`).setRequired(false))) .addSubcommand(command => command.setName(`remove`).setDescription(`Remove a channel from the yt notifying system`).addStringOption(option => option.setName(`channel-id`).setDescription(`The ID of the youtube channel you want to remove`).setRequired(true))), async execute(interaction,client) { const {options} = interaction; if (!interaction.member.roles.cache.has(`1126442435954876506`)) return await interaction.reply({content:`You don't have permissions to use this command!`,ephemeral:true}); const sub = options.getSubcommand(); const data = await notifyYtschema.find({Guild: interaction.guild.id}); switch (sub) { case `add`: if(data.length) { if (data.length >=5) { return await interaction.reply({content:`You can only have 5 active notifications at once`, ephemeral:true}) } } const ID = options.getString(`channel-id`); const channel = options.getChannel(`channel`) const pingrole = options.getRole(`role`) const message = options.getString(`message`); let role = `non`; if (pingrole) { role = pingrole.id; } let checkdata = await notifyYtschema.findOne({Guil: interaction.guild, ID: ID}); if (checkdata) { await interaction.deferReply({ephemeral:true}) let author = ''; const videodata = await parser.parseURL(`https://youtube.com/feeds/videos.xml?channel_id=${ID}`) if (videodata) { author = videodata.items[0].author; } else { author = "Unknown" } return await interaction.editReply({content: `You already have a youtube notifying system for **${author}**`, ephemeral:true}); } else { await interaction.deferReply({ephemeral:true}); } try { const videodata = await parser.parseURL(`https://youtube.com/feeds/videos.xml?channel_id=${ID}`); let author = ''; if (videodata) { author = videodata.items[0].author; } else { author = "Unknown" } const sendhe = new EmbedBuilder() .setColor(`Green`) .setTitle(`Youtube notifying system enabled!`) .addFields({name: "Channel",value: `**${author}**`}) .addFields({name: `Notify channel`,value:`**${channel}**`}) .setDescription(`From now on, when a new video is uploaded on that YT channel, it will be sent in the channel below`) if (pingrole) { sendhe.addFields({name: `Ping role`, value: `${pingrole}`}); } if (message) { sendhe.addFields({name:`Message`, value: `${message.replace('{author}', 'Channel ').replace(`{link}`,`youtube.com`).replace(`{title}`, `your title`)}`}); } await interaction.editReply({embeds: [sendhe], ephemeral:true}) } catch { return await interaction.editReply({content:`The channel with the ID of ${ID} does not exists!`,ephemeral:true}) } await notifyYtschema.create({ Guild: interaction.guild.id, Channel: channel.id, ID: ID, Latest: 'none', Message: message || '', PingRole: role || '' }); break; case "remove": if (!data) return await interaction.reply({content: `You do not have the YT notify system yet`, ephemeral:true}) else { const ID = options.getString(`channel-id`); let checkdata = await notifyYtschema.findOne({Guild: interaction.guild.id, ID: ID}); if (!checkdata) return await interaction.reply({content: `The Youtube modifier does not exists here!`, ephemeral:true}); const embed2 = new EmbedBuilder() .setColor(`Red`) .setDescription(`⚠️ Your YT notify system has been removed for the creator ${ID}`) await interaction.reply({embeds: [embed2], ephemeral:true}); await notifyYtschema.deleteMany({Guild:interaction.guild.id,ID: ID}); } } }}