diff --git a/docs/Archive/ClearQueue.ts b/docs/Archive/ClearQueue.ts new file mode 100644 index 0000000..774ab9c --- /dev/null +++ b/docs/Archive/ClearQueue.ts @@ -0,0 +1,46 @@ +import { + ApplicationCommandDataResolvable, + CommandInteraction, + CacheType, + EmbedBuilder, + GuildMember, +} from 'discord.js'; +import { Bot } from '../Bot'; +import { colorCheck } from '../resources/embedColorCheck'; +import { SlashCommand } from './SlashCommand'; + +export class ClearQueue implements SlashCommand { + name: string = 'clearqueue'; + description = 'Clear the music queue'; + options = []; + requiredPermissions: bigint[] = []; + async run(bot: Bot, interaction: CommandInteraction): Promise { + try { + const embed = new EmbedBuilder().setColor(colorCheck(interaction.guild!.id,true)); + + let queue = bot.player.getQueue(interaction.guild!.id); + if (!queue || !queue.playing) { + embed.setDescription( + 'There are no songs in the queue or the player is not playing' + ); + interaction.reply({ embeds: [embed], ephemeral: true }); + return; + } + queue.clear(); + embed.setDescription(`Queue has been cleared by ${interaction.user}`); + interaction.reply({ embeds: [embed] }); + return; + } catch (err) { + bot.logger.commandError(interaction.channel!.id, this.name, err); + interaction.reply({ + content: 'Error: contact a developer to investigate', + ephemeral: true, + }); + return; + } + } + guildRequired?: boolean | undefined = true; + managerRequired?: boolean | undefined; + blockSilenced?: boolean | undefined = true; + musicCommand?: boolean | undefined = true; +} diff --git a/src/resources/CustomPlayer.ts b/docs/Archive/CustomPlayer.ts similarity index 100% rename from src/resources/CustomPlayer.ts rename to docs/Archive/CustomPlayer.ts diff --git a/docs/Archive/DestroyQueue.ts b/docs/Archive/DestroyQueue.ts new file mode 100644 index 0000000..252fa8c --- /dev/null +++ b/docs/Archive/DestroyQueue.ts @@ -0,0 +1,32 @@ +import { CommandInteraction, CacheType } from 'discord.js'; +import { Bot } from '../Bot'; +import { Option, Subcommand } from './Option'; +import { SlashCommand } from './SlashCommand'; + +export class DestroyQueue implements SlashCommand { + name: string = 'destroyqueue'; + description: string = 'Empty and destroy the queue, will reset the music player entirely'; + options: (Option | Subcommand)[] = []; + requiredPermissions: bigint[] = []; + run(bot: Bot, interaction: CommandInteraction): Promise { + try { + let queue = bot.player.getQueue(interaction.guild!.id); + if (queue) { + queue.destroy(); + } + interaction.reply('Reset the queue'); + return; + } catch (err) { + bot.logger.commandError(interaction.channel!.id, this.name, err); + interaction.reply({ + content: 'Error: contact a developer to investigate', + ephemeral: true, + }); + return; + } + } + guildRequired?: boolean | undefined = true; + managerRequired?: boolean | undefined; + blockSilenced?: boolean | undefined = true; + musicCommand?: boolean | undefined = true; +} diff --git a/docs/Archive/Loop.ts b/docs/Archive/Loop.ts new file mode 100644 index 0000000..bd89625 --- /dev/null +++ b/docs/Archive/Loop.ts @@ -0,0 +1,45 @@ +import { QueueRepeatMode, Track } from "discord-player"; +import { CommandInteraction, CacheType, EmbedBuilder } from "discord.js"; +import { Bot } from "../Bot"; +import { colorCheck } from "../resources/embedColorCheck"; +import { Option, Subcommand } from "./Option"; +import { SlashCommand } from "./SlashCommand"; + +export class Loop implements SlashCommand{ + name: string = 'loop'; + description: string = 'Loop the song that is currently playing'; + options: (Option | Subcommand)[] = []; + requiredPermissions: bigint[] = []; + run(bot: Bot, interaction: CommandInteraction): Promise { + try { + const embed = new EmbedBuilder().setColor(colorCheck(interaction.guild!.id)); + + let queue = bot.player.getQueue(interaction.guild!.id); + if(!queue || !queue.playing) { + embed.setDescription('There is no music playing!'); + interaction.reply({embeds: [embed]}); + return; + } + if(queue.repeatMode){ + embed.setDescription('Stopped looping'); + queue.setRepeatMode(QueueRepeatMode.OFF); + return interaction.reply({embeds: [embed]}); + } + queue.setRepeatMode(QueueRepeatMode.TRACK); + embed.setDescription(`Now looping **${queue.nowPlaying().title}** by *${queue.nowPlaying().author}*. Use \`/skip\` to continue the queue`); + return interaction.reply({embeds:[embed]}); + } + catch (err) { + bot.logger.commandError(interaction.channel!.id, this.name, err); + return interaction.reply({ + content: 'Error: contact a developer to investigate', + ephemeral: true, + }); + } + } + guildRequired?: boolean | undefined = true; + managerRequired?: boolean | undefined; + blockSilenced?: boolean | undefined = true; + musicCommand?: boolean | undefined = true; + +} \ No newline at end of file diff --git a/src/slashcommands/NowPlaying.ts b/docs/Archive/NowPlaying.ts similarity index 94% rename from src/slashcommands/NowPlaying.ts rename to docs/Archive/NowPlaying.ts index bc5d8d7..be9979b 100644 --- a/src/slashcommands/NowPlaying.ts +++ b/docs/Archive/NowPlaying.ts @@ -2,7 +2,7 @@ import { ApplicationCommandDataResolvable, CommandInteraction, CacheType, - MessageEmbed, + EmbedBuilder, GuildMember, } from 'discord.js'; import { Bot } from '../Bot'; @@ -16,7 +16,7 @@ export class NowPlaying implements SlashCommand { requiredPermissions: bigint[] = []; run(bot: Bot, interaction: CommandInteraction): Promise { try { - const embed = new MessageEmbed().setColor(colorCheck(interaction.guild!.id,true)); + const embed = new EmbedBuilder().setColor(colorCheck(interaction.guild!.id,true)); let queue = bot.player.getQueue(interaction.guild!.id); if (!queue || !queue.playing) { diff --git a/docs/Archive/Pause.ts b/docs/Archive/Pause.ts new file mode 100644 index 0000000..d8c2617 --- /dev/null +++ b/docs/Archive/Pause.ts @@ -0,0 +1,47 @@ +import { + CommandInteraction, + CacheType, + EmbedBuilder, +} from 'discord.js'; +import { Bot } from '../Bot'; +import { colorCheck } from '../resources/embedColorCheck'; +import { SlashCommand } from './SlashCommand'; + + +export class Pause implements SlashCommand { + name: string = 'pause'; + description: string = 'Pause the music player'; + options = []; + requiredPermissions: bigint[] = []; + async run( + bot: Bot, + interaction: CommandInteraction + ): Promise { + try { + const embed = new EmbedBuilder().setColor(colorCheck(interaction.guild!.id,true)); + + + let queue = bot.player.getQueue(interaction.guild!.id); + if (!queue || !queue.playing) { + embed.setDescription('There is no music playing!'); + interaction.reply({ embeds: [embed], ephemeral: true }); + return; + } + queue.setPaused(true); + embed.setDescription(`Music was paused by ${interaction.user}`); + interaction.reply({ embeds: [embed] }); + return; + } catch (err) { + bot.logger.commandError(interaction.channel!.id, this.name, err); + interaction.reply({ + content: 'Error: contact a developer to investigate', + ephemeral: true, + }); + return; + } + } + guildRequired?: boolean | undefined = true; + managerRequired?: boolean | undefined; + blockSilenced?: boolean | undefined = true; + musicCommand?: boolean | undefined = true; +} diff --git a/src/slashcommands/Play.ts b/docs/Archive/Play.ts similarity index 94% rename from src/slashcommands/Play.ts rename to docs/Archive/Play.ts index 27cce8a..4b61d84 100644 --- a/src/slashcommands/Play.ts +++ b/docs/Archive/Play.ts @@ -2,10 +2,10 @@ import { ApplicationCommandDataResolvable, CommandInteraction, CacheType, - MessageEmbed, + EmbedBuilder, GuildMember, + ApplicationCommandOptionType, } from 'discord.js'; -import { ApplicationCommandOptionTypes } from 'discord.js/typings/enums'; import { Bot } from '../Bot'; import { SlashCommand } from './SlashCommand'; import { QueryType } from 'discord-player'; @@ -20,7 +20,7 @@ export class Play implements SlashCommand { new Option( 'query', 'The song or playlist you want to queue', - ApplicationCommandOptionTypes.STRING, + ApplicationCommandOptionType.String, true ), ]; @@ -30,7 +30,7 @@ export class Play implements SlashCommand { interaction: CommandInteraction ): Promise { try { - const embed = new MessageEmbed().setColor(colorCheck(interaction.guild!.id,true)); + const embed = new EmbedBuilder().setColor(colorCheck(interaction.guild!.id,true)); let member = interaction.member as GuildMember; //need this for later diff --git a/src/slashcommands/PlayNext.ts b/docs/Archive/PlayNext.ts similarity index 97% rename from src/slashcommands/PlayNext.ts rename to docs/Archive/PlayNext.ts index 6b30341..f2e2cfb 100644 --- a/src/slashcommands/PlayNext.ts +++ b/docs/Archive/PlayNext.ts @@ -1,7 +1,7 @@ import { CommandInteraction, CacheType, - MessageEmbed, + EmbedBuilder, GuildMember, } from 'discord.js'; import { Bot } from '../Bot'; @@ -23,7 +23,7 @@ export class PlayNext implements SlashCommand { interaction: CommandInteraction ): Promise { try { - const embed = new MessageEmbed().setColor(colorCheck(interaction.guild!.id,true)); + const embed = new EmbedBuilder().setColor(colorCheck(interaction.guild!.id,true)); let member = interaction.member as GuildMember; diff --git a/src/slashcommands/Queue.ts b/docs/Archive/Queue.ts similarity index 97% rename from src/slashcommands/Queue.ts rename to docs/Archive/Queue.ts index 3cde599..aceb428 100644 --- a/src/slashcommands/Queue.ts +++ b/docs/Archive/Queue.ts @@ -3,7 +3,7 @@ import { CommandInteraction, CacheType, Message, - MessageEmbed, + EmbedBuilder, GuildMember, } from 'discord.js'; import { Bot } from '../Bot'; @@ -17,7 +17,7 @@ export class Queue implements SlashCommand { requiredPermissions: bigint[] = []; run(bot: Bot, interaction: CommandInteraction): Promise { try { - const embed = new MessageEmbed().setColor(colorCheck(interaction.guild!.id,true)); + const embed = new EmbedBuilder().setColor(colorCheck(interaction.guild!.id,true)); let queue = bot.player.getQueue(interaction.guild!.id); if (!queue || !queue.playing || queue.tracks.length == 0) diff --git a/docs/Archive/Resume.ts b/docs/Archive/Resume.ts new file mode 100644 index 0000000..45e4e2a --- /dev/null +++ b/docs/Archive/Resume.ts @@ -0,0 +1,45 @@ +import { + ApplicationCommandDataResolvable, + CommandInteraction, + CacheType, + EmbedBuilder, + GuildMember, +} from 'discord.js'; +import { Bot } from '../Bot'; +import { colorCheck } from '../resources/embedColorCheck'; +import { SlashCommand } from './SlashCommand'; + +export class Resume implements SlashCommand { + name: string = 'resume'; + description = 'Resume the music player'; + options = []; + requiredPermissions: bigint[] = []; + async run( + bot: Bot, + interaction: CommandInteraction + ): Promise { + try { + const embed = new EmbedBuilder().setColor(colorCheck(interaction.guild!.id,true)); + + let queue = bot.player.getQueue(interaction.guild!.id); + if (!queue || !queue.playing) { + embed.setDescription('There is no music playing!'); + return interaction.reply({ embeds: [embed], ephemeral: true }); + } + queue.setPaused(false); + embed.setDescription(`Track was resumed by ${interaction.user}`); + return interaction.reply({ embeds: [embed] }); + } catch (err) { + bot.logger.commandError(interaction.channel!.id, this.name, err); + interaction.reply({ + content: 'Error: contact a developer to investigate', + ephemeral: true, + }); + return; + } + } + guildRequired?: boolean | undefined = true; + managerRequired?: boolean | undefined; + blockSilenced?: boolean | undefined = true; + musicCommand?: boolean | undefined = true; +} diff --git a/src/messagecommands/SendUpdate.ts b/docs/Archive/SendUpdate.ts similarity index 86% rename from src/messagecommands/SendUpdate.ts rename to docs/Archive/SendUpdate.ts index f08c571..a34e048 100644 --- a/src/messagecommands/SendUpdate.ts +++ b/docs/Archive/SendUpdate.ts @@ -1,4 +1,4 @@ -import { Message, Permissions, MessageEmbed, TextChannel } from 'discord.js'; +import { Message, EmbedBuilder, TextChannel, PermissionsBitField } from 'discord.js'; import { Bot } from '../Bot'; import { MessageCommand } from './MessageCommand'; import config from '../../config.json'; @@ -6,7 +6,7 @@ import { updateChannels } from '../slashcommands/Update'; export class SendUpdate implements MessageCommand { name: string = 'sendupdate'; - requiredPermissions: bigint[] = [Permissions.FLAGS.SEND_MESSAGES]; + requiredPermissions: bigint[] = [PermissionsBitField.Flags.SendMessages]; async run( bot: Bot, message: Message, @@ -18,7 +18,7 @@ export class SendUpdate implements MessageCommand { return; //we dont need to respond because as far as anyone cares this command does not matter } let content = message.content.slice(12); //cuts out "$sendupdate " - let embed = new MessageEmbed() + let embed = new EmbedBuilder() .setColor('#FFFFFF') .setTitle( ':mirror: **__Mirror Update!__** <:homies:863998146589360158>' diff --git a/src/slashcommands/Shuffle.ts b/docs/Archive/Shuffle.ts similarity index 84% rename from src/slashcommands/Shuffle.ts rename to docs/Archive/Shuffle.ts index cde5ab9..ad7d0b9 100644 --- a/src/slashcommands/Shuffle.ts +++ b/docs/Archive/Shuffle.ts @@ -2,7 +2,7 @@ import { ApplicationCommandDataResolvable, CommandInteraction, CacheType, - MessageEmbed, + EmbedBuilder, GuildMember, } from 'discord.js'; import { Bot } from '../Bot'; @@ -19,16 +19,18 @@ export class Shuffle implements SlashCommand { interaction: CommandInteraction ): Promise { try { - const embed = new MessageEmbed().setColor(colorCheck(interaction.guild!.id,true)); + const embed = new EmbedBuilder().setColor(colorCheck(interaction.guild!.id,true)); let queue = bot.player.getQueue(interaction.guild!.id); if (!queue || !queue.playing) { embed.setDescription('There is no music playing!'); - return interaction.reply({ embeds: [embed], ephemeral: true }); + interaction.reply({ embeds: [embed], ephemeral: true }); + return; } await queue.shuffle(); embed.setDescription(`Queue has been shuffled by ${interaction.user}`); - return interaction.reply({ embeds: [embed] }); + interaction.reply({ embeds: [embed] }); + return; } catch (err) { bot.logger.commandError(interaction.channel!.id, this.name, err); interaction.reply({ diff --git a/src/slashcommands/Skip.ts b/docs/Archive/Skip.ts similarity index 91% rename from src/slashcommands/Skip.ts rename to docs/Archive/Skip.ts index ce3efc8..ebd16d8 100644 --- a/src/slashcommands/Skip.ts +++ b/docs/Archive/Skip.ts @@ -2,10 +2,10 @@ import { ApplicationCommandDataResolvable, CommandInteraction, CacheType, - MessageEmbed, + EmbedBuilder, GuildMember, } from 'discord.js'; -import { ApplicationCommandOptionTypes } from 'discord.js/typings/enums'; +import { ApplicationCommandOptionType } from 'discord.js/typings/enums'; import { Bot } from '../Bot'; import { SlashCommand } from './SlashCommand'; import { Option } from './Option'; @@ -19,7 +19,7 @@ export class Skip implements SlashCommand { new Option( 'number', 'How many tracks you want to skip in the queue', - ApplicationCommandOptionTypes.INTEGER, + ApplicationCommandOptionType.INTEGER, false ) ]; @@ -29,7 +29,7 @@ export class Skip implements SlashCommand { interaction: CommandInteraction ): Promise { try { - const embed = new MessageEmbed().setColor(colorCheck(interaction.guild!.id,true)); + const embed = new EmbedBuilder().setColor(colorCheck(interaction.guild!.id,true)); let queue = bot.player.getQueue(interaction.guild!.id); if (!queue || !queue.playing) { diff --git a/src/slashcommands/Update.ts b/docs/Archive/Update.ts similarity index 91% rename from src/slashcommands/Update.ts rename to docs/Archive/Update.ts index cae52b6..1336ce5 100644 --- a/src/slashcommands/Update.ts +++ b/docs/Archive/Update.ts @@ -6,14 +6,14 @@ import { GuildMember, TextChannel, Guild, - MessageEmbed, + EmbedBuilder, Options, } from 'discord.js'; import { SlashCommand } from './SlashCommand'; import config from '../../config.json'; import Enmap from 'enmap'; import { Option, Subcommand } from './Option'; -import { ApplicationCommandOptionTypes } from 'discord.js/typings/enums'; +import { ApplicationCommandOptionType } from 'discord.js/typings/enums'; import { colorCheck } from '../resources/embedColorCheck'; export let updateChannels = new Enmap({ name: 'updateChannels' }); @@ -26,11 +26,11 @@ export class Update implements SlashCommand { new Option( 'channel', 'The channel you wish to recieve update messages', - ApplicationCommandOptionTypes.CHANNEL, + ApplicationCommandOptionType.CHANNEL, true ), ]; - public requiredPermissions = [Permissions.FLAGS.SEND_MESSAGES]; + public requiredPermissions = [PermissionsBitField.Flags.SEND_MESSAGES]; public async run( bot: Bot, @@ -74,7 +74,7 @@ export class Update implements SlashCommand { }); //var enmapChannel = updateChannels.ensure(interaction.guild.id, ''); updateChannels.set(interaction.guild.id, channel?.id); - let embed = new MessageEmbed() + let embed = new EmbedBuilder() .setColor(colorCheck(interaction.guild!.id)) .setDescription( `Sucessfully updated your development messages to ${channel}` diff --git a/src/slashcommands/ClearQueue.ts b/docs/retiredslashcommands/ClearQueue.ts similarity index 100% rename from src/slashcommands/ClearQueue.ts rename to docs/retiredslashcommands/ClearQueue.ts diff --git a/src/slashcommands/DestroyQueue.ts b/docs/retiredslashcommands/DestroyQueue.ts similarity index 100% rename from src/slashcommands/DestroyQueue.ts rename to docs/retiredslashcommands/DestroyQueue.ts diff --git a/src/slashcommands/Loop.ts b/docs/retiredslashcommands/Loop.ts similarity index 100% rename from src/slashcommands/Loop.ts rename to docs/retiredslashcommands/Loop.ts diff --git a/src/slashcommands/Pause.ts b/docs/retiredslashcommands/Pause.ts similarity index 100% rename from src/slashcommands/Pause.ts rename to docs/retiredslashcommands/Pause.ts diff --git a/src/slashcommands/Resume.ts b/docs/retiredslashcommands/Resume.ts similarity index 100% rename from src/slashcommands/Resume.ts rename to docs/retiredslashcommands/Resume.ts diff --git a/package.json b/package.json index 7b61704..aa4033e 100644 --- a/package.json +++ b/package.json @@ -10,28 +10,29 @@ "author": "Ford Friedel", "license": "ISC", "dependencies": { - "@discordjs/opus": "^0.8.0", + "@discordjs/opus": "latest", "@discordjs/voice": "latest", "chrono-node": "latest", "cron": "latest", "discord-player": "latest", - "discord.js": "latest", + "discord.js": "^14.8.0", "enmap": "latest", "ffmpeg": "latest", "ffmpeg-static": "^4.4.1", "geo-tz": "latest", "mkdirp": "latest", "node-cron": "latest", - "node-fetch": "^2.6.1", + "node-fetch": "^2.7.0", "pm2": "^5.2.0", "tslog": "^3.3.2", "tweetnacl": "latest", - "typescript": "^4.5.5", + "typescript": "^5.2.2", "ytdl": "latest", "ytdl-core": "^4.10.0" }, "devDependencies": { "@types/mkdirp": "^1.0.2", - "@types/node-cron": "^3.0.1" + "@types/node-cron": "^3.0.1", + "@types/node-fetch": "^2.6.7" } } diff --git a/src/Bot.ts b/src/Bot.ts index d592795..f6a209d 100644 --- a/src/Bot.ts +++ b/src/Bot.ts @@ -1,4 +1,4 @@ -import { Client, Guild, MessageEmbed, TextChannel } from 'discord.js'; +import { Client, Guild, EmbedBuilder, TextChannel } from 'discord.js'; import { CustomLogger } from './CustomLogger'; import { TLogLevelName } from 'tslog'; import { permissionsCheck } from './resources/permissionsCheck'; @@ -13,11 +13,9 @@ import { } from './resources/dynamicImports'; import Enmap from 'enmap'; import { registerEvents } from './resources/registerEvents'; -import { CustomPlayer } from './resources/CustomPlayer'; export class Bot { public logger: CustomLogger; - public player = new CustomPlayer(this); //helper functions public permissionsCheck = permissionsCheck; @@ -57,6 +55,5 @@ export class Bot { await importMessageCommands(this); await importKeywords(this); this.client.login(this.token); - this.player.registerPlayerEvents(); } } diff --git a/src/CustomLogger.ts b/src/CustomLogger.ts index 6f6c1f2..0d25963 100644 --- a/src/CustomLogger.ts +++ b/src/CustomLogger.ts @@ -1,9 +1,9 @@ import { ILogObject, Logger, TLogLevelName } from 'tslog'; import { appendFile } from 'fs'; -import mkdirp from 'mkdirp'; +import { mkdirp } from 'mkdirp'; import path from 'path'; import { Bot } from './Bot'; -import { AnyChannel, MessageEmbed, TextChannel } from 'discord.js'; +import { Channel, EmbedBuilder, TextChannel } from 'discord.js'; import config from '../config.json'; export class CustomLogger extends Logger { @@ -50,15 +50,15 @@ export class CustomLogger extends Logger { ...args: unknown[] ): ILogObject { if (commandName) { - var errorChannel: AnyChannel; + var errorChannel: TextChannel; - const embed = new MessageEmbed() + const embed = new EmbedBuilder() .setTitle(`Error in command: __${commandName.toUpperCase()}__`) - .setColor('RED'); + .setColor('Red'); if (channelId) { errorChannel = this.bot.client.channels.cache.get( channelId - ) as AnyChannel; + ) as TextChannel; embed.setDescription( `Error Message: ${args.join(' ')}\n\n Channel: ${errorChannel}` ); diff --git a/src/events/GuildCreate.ts b/src/events/GuildCreate.ts index 513cf7a..cfb2246 100644 --- a/src/events/GuildCreate.ts +++ b/src/events/GuildCreate.ts @@ -2,25 +2,27 @@ import { EventHandler } from './EventHandler'; import { Bot } from '../Bot'; import { Guild, - MessageEmbed, + EmbedBuilder, TextChannel, Permissions, GuildChannel, NonThreadGuildBasedChannel, + BaseGuildTextChannel, + ChannelType, } from 'discord.js'; export class GuildCreate implements EventHandler { eventName = 'guildCreate'; async process(bot: Bot, guild: Guild): Promise { - let embed = new MessageEmbed() + let embed = new EmbedBuilder() .setTitle('**:mirror: Mirror has arrived!**') .setDescription( 'Thanks for inviting Mirror to your server! \n\n To get started with Mirror use **`/help`** for more information about commands and functionality\n\nUse **`/config`** to see what else you can do before Mirror is fully functional' ) .setColor('#FFFFFF'); if(guild.systemChannel){ - if(guild.systemChannel.permissionsFor(guild.me!).has('VIEW_CHANNEL') && - guild.systemChannel.permissionsFor(guild.me!).has('SEND_MESSAGES')){ + if(guild.systemChannel.permissionsFor(guild.members.me!).has('ViewChannel') && + guild.systemChannel.permissionsFor(guild.members.me!).has('SendMessages')){ await guild.systemChannel.send({embeds: [embed]}); return; } @@ -28,9 +30,9 @@ export class GuildCreate implements EventHandler { let channelList = await guild.channels.fetch(); for (let channel of channelList) { if ( - channel[1].permissionsFor(guild.me!).has('VIEW_CHANNEL') && - channel[1].permissionsFor(guild.me!).has('SEND_MESSAGES') && - channel[1].type == 'GUILD_TEXT' + channel[1]!.permissionsFor(guild.members.me!).has('ViewChannel') && + channel[1]!.permissionsFor(guild.members.me!).has('SendMessages') && + channel[1]!.type == ChannelType.GuildText ) { let newChannel = channel[1] as TextChannel; await newChannel.send({ embeds: [embed] }); diff --git a/src/events/InteractionCreate.ts b/src/events/InteractionCreate.ts index ce938ab..4f1bb57 100644 --- a/src/events/InteractionCreate.ts +++ b/src/events/InteractionCreate.ts @@ -1,5 +1,5 @@ import { joinVoiceChannel } from '@discordjs/voice'; -import { CommandInteraction, GuildMember, MessageEmbed, TextChannel, TextBasedChannel, GuildChannel } from 'discord.js'; +import { CommandInteraction, GuildMember, EmbedBuilder, TextChannel, TextBasedChannel, GuildChannel, Interaction, ChatInputCommandInteraction } from 'discord.js'; import { Bot } from '../Bot'; import { managerCheck } from '../resources/managerCheck'; import { voiceCommandCheck } from '../resources/voiceCommandCheck'; @@ -9,9 +9,12 @@ import { EventHandler } from './EventHandler'; export class InteractionCreate implements EventHandler { eventName = 'interactionCreate'; - async process(bot: Bot, interaction: CommandInteraction) { + async process(bot: Bot, interaction: Interaction) { if (!interaction.isCommand()) return; + //if its not a chatInputCommandInteraction, exit + if(!interaction.isChatInputCommand()) return; + //attempt to find the command from the array of all of them let command = bot.slashCommands.find( (command) => command.name === interaction.commandName @@ -30,20 +33,22 @@ export class InteractionCreate implements EventHandler { } if (command.managerRequired) { if (!(await managerCheck(interaction))) { - return interaction.reply({ + interaction.reply({ content: 'This command can only be used by designated managers or admininstrators', ephemeral: true, }); + return; } } if(command.blockSilenced) { if(await silenceCheck(interaction)){ - return interaction.reply({ + interaction.reply({ content: 'This command cannot be used by silenced members', ephemeral: true, }); + return; } } if(command.musicCommand){ @@ -75,6 +80,6 @@ export class InteractionCreate implements EventHandler { return; } } - command.run(bot, interaction); + command.run(bot, interaction as ChatInputCommandInteraction); } } diff --git a/src/events/Ready.ts b/src/events/Ready.ts index 52ece2b..feca357 100644 --- a/src/events/Ready.ts +++ b/src/events/Ready.ts @@ -5,7 +5,7 @@ import { birthdayTimer } from '../resources/birthdayTimer'; import { registerSlashCommands } from '../resources/registerSlashCommands'; import { launchVoice } from '../slashcommands/DefaultVc'; import config from '../../config.json'; -import { TextChannel } from 'discord.js'; +import { ActivityType, TextChannel } from 'discord.js'; export class Ready implements EventHandler { eventName = 'ready'; @@ -13,7 +13,7 @@ export class Ready implements EventHandler { bot.logger.info('Logged in'); await registerSlashCommands(bot); bot.client.user?.setActivity(config.message, { - type: 'LISTENING', + type: ActivityType.Listening, }); bdayTimes.forEach(async (info, guild) => { birthdayTimer(guild.toString(), bot); diff --git a/src/events/VoiceStateUpdate.ts b/src/events/VoiceStateUpdate.ts index d2635bb..7ffa905 100644 --- a/src/events/VoiceStateUpdate.ts +++ b/src/events/VoiceStateUpdate.ts @@ -16,22 +16,22 @@ export class VoiceStateUpdate implements EventHandler { oldState: VoiceState, newState: VoiceState ): Promise { - if (newState.member!.user.bot){ - if(newState.member?.user.id == newState.guild.me!.id){ - if(!newState.channelId){ - if(bot.player.getQueue(newState.guild)){ - bot.player.getQueue(newState.guild).destroy(); - return; //if mirror disconnects, destroy the queue. the player.on('disconnect') event is not reliable - } - } - } - return; //ignores bots - } - let ourId = newState.guild.me!.voice.channelId; //checks the voice channel id that mirror is sitting in + // if (newState.member!.user.bot){ + // if(newState.member?.user.id == newState.guild.members.me!.id){ + // if(!newState.channelId){ + // return + // //if(bot.player.getQueue(newState.guild)){ + // // bot.player.getQueue(newState.guild).destroy(); + // // return; //if mirror disconnects, destroy the queue. the player.on('disconnect') event is not reliable + // } + // } + // } + // return; //ignores bots + // } + let ourId = newState.guild.members.me!.voice.channelId; //checks the voice channel id that mirror is sitting in if (newState.channelId != ourId) return; //if the new channel of the user doesnt match mirrors, end if (oldState.channelId == newState.channelId) return; //if the new channel and the old channel are the same, end if (newState.serverMute == true || newState.serverDeaf == true) return; //if the user is server muted or server deafened, end - if (bot.player.getQueue(newState.guild)) return; //if there is a player queue available, end TODO? we may want to remove this later let userArray = silencedUsers.ensure(newState.guild!.id, []); if (userArray.includes(newState.member!.id)) return; //if the user is silenced, end let connection = getVoiceConnection(newState.guild.id); diff --git a/src/events/test.xlxs b/src/events/test.xlxs new file mode 100644 index 0000000..e69de29 diff --git a/src/index.ts b/src/index.ts index d6f5689..ef5b458 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,16 +1,16 @@ -import { Client, Intents } from 'discord.js'; +import { Client, IntentsBitField } from 'discord.js'; import { Bot } from './Bot'; //@ts-ignore:next-line import config from '../config.json'; let options = { intents: [ - Intents.FLAGS.GUILDS, - Intents.FLAGS.GUILD_MESSAGES, - Intents.FLAGS.GUILD_MESSAGE_REACTIONS, - Intents.FLAGS.GUILD_VOICE_STATES, - Intents.FLAGS.DIRECT_MESSAGES, - Intents.FLAGS.GUILD_MEMBERS + IntentsBitField.Flags.Guilds, + IntentsBitField.Flags.GuildMessages, + IntentsBitField.Flags.GuildMessageReactions, + IntentsBitField.Flags.GuildVoiceStates, + IntentsBitField.Flags.DirectMessages, + IntentsBitField.Flags.GuildMembers ], }; let bot = new Bot( diff --git a/src/keywords/Cringe.ts b/src/keywords/Cringe.ts index 788f60f..eb2ca16 100644 --- a/src/keywords/Cringe.ts +++ b/src/keywords/Cringe.ts @@ -13,15 +13,15 @@ let cringeDict = [ 'https://tenor.com/view/shrek-frog-dies-from-cringe-gif-21051437', ]; //frog -import { Message, Permissions } from 'discord.js'; +import { Message, PermissionsBitField } from 'discord.js'; import { Bot } from '../Bot'; import { Keyword } from './Keyword'; export class Cringe implements Keyword { name: string = 'cringe'; requiredPermissions: bigint[] = [ - Permissions.FLAGS.SEND_MESSAGES, - Permissions.FLAGS.EMBED_LINKS, + PermissionsBitField.Flags.SendMessages, + PermissionsBitField.Flags.EmbedLinks, ]; async run( bot: Bot, diff --git a/src/keywords/Fortbush.ts b/src/keywords/Fortbush.ts index 1585c3a..72cd583 100644 --- a/src/keywords/Fortbush.ts +++ b/src/keywords/Fortbush.ts @@ -1,15 +1,15 @@ //keyword: fortbush emoji; //Reacts to the fortbush with a fortbush :D -import { Message, Permissions } from 'discord.js'; +import { Message, PermissionsBitField } from 'discord.js'; import { Bot } from '../Bot'; import { Keyword } from './Keyword'; export class Fortbush implements Keyword { name: string = '<:fortbush:816549663812485151>'; requiredPermissions: bigint[] = [ - Permissions.FLAGS.ADD_REACTIONS, - Permissions.FLAGS.USE_EXTERNAL_EMOJIS, + PermissionsBitField.Flags.AddReactions, + PermissionsBitField.Flags.UseExternalEmojis, ]; async run( bot: Bot, diff --git a/src/keywords/Mirror.ts b/src/keywords/Mirror.ts index d8ee374..2bebdda 100644 --- a/src/keywords/Mirror.ts +++ b/src/keywords/Mirror.ts @@ -1,13 +1,13 @@ //Keyword: mirror //Reacts to the keyword with the eyes emoji -import { Message, Permissions } from 'discord.js'; +import { Message, Permissions, PermissionsBitField } from 'discord.js'; import { Bot } from '../Bot'; import { Keyword } from './Keyword'; export class Mirror implements Keyword { name: string = 'mirror'; - requiredPermissions: bigint[] = [Permissions.FLAGS.ADD_REACTIONS]; + requiredPermissions: bigint[] = [PermissionsBitField.Flags.AddReactions]; async run( bot: Bot, message: Message, diff --git a/src/keywords/MirrorEmoji.ts b/src/keywords/MirrorEmoji.ts index fd4a3fd..73f5b0c 100644 --- a/src/keywords/MirrorEmoji.ts +++ b/src/keywords/MirrorEmoji.ts @@ -1,13 +1,13 @@ //Keyword: Mirror emoji //Reacts to the Mirror Emoji with the Mirror Emoji -import { Message, Permissions } from 'discord.js'; +import { Message, PermissionsBitField } from 'discord.js'; import { Bot } from '../Bot'; import { Keyword } from './Keyword'; export class MirrorEmoji implements Keyword { name: string = '🪞'; - requiredPermissions: bigint[] = [Permissions.FLAGS.ADD_REACTIONS]; + requiredPermissions: bigint[] = [PermissionsBitField.Flags.AddReactions]; async run( bot: Bot, message: Message, diff --git a/src/keywords/Pog.ts b/src/keywords/Pog.ts index 72e5944..358556e 100644 --- a/src/keywords/Pog.ts +++ b/src/keywords/Pog.ts @@ -1,15 +1,15 @@ //Keyword: pog //Reacts to the keyword with JamesChamp -import { Message, Permissions } from 'discord.js'; +import { Message, PermissionsBitField } from 'discord.js'; import { Bot } from '../Bot'; import { Keyword } from './Keyword'; export class Pog implements Keyword { name: string = 'pog'; requiredPermissions: bigint[] = [ - Permissions.FLAGS.ADD_REACTIONS, - Permissions.FLAGS.USE_EXTERNAL_EMOJIS, + PermissionsBitField.Flags.AddReactions, + PermissionsBitField.Flags.UseExternalEmojis, ]; async run( bot: Bot, diff --git a/src/keywords/PogChamp.ts b/src/keywords/PogChamp.ts index 2951469..1de9c48 100644 --- a/src/keywords/PogChamp.ts +++ b/src/keywords/PogChamp.ts @@ -1,15 +1,15 @@ //Keyword: pogchamp //Reacts to the keyword with JamesChamp -import { Message, Permissions } from 'discord.js'; +import { Message, PermissionsBitField } from 'discord.js'; import { Bot } from '../Bot'; import { Keyword } from './Keyword'; export class PogChamp implements Keyword { name: string = 'pogchamp'; requiredPermissions: bigint[] = [ - Permissions.FLAGS.ADD_REACTIONS, - Permissions.FLAGS.USE_EXTERNAL_EMOJIS, + PermissionsBitField.Flags.AddReactions, + PermissionsBitField.Flags.UseExternalEmojis, ]; async run( bot: Bot, diff --git a/src/keywords/Poggers.ts b/src/keywords/Poggers.ts index 6ebd9e7..2bf8782 100644 --- a/src/keywords/Poggers.ts +++ b/src/keywords/Poggers.ts @@ -1,15 +1,15 @@ //Keyword: poggers //Reacts to the keyword with JamesChamp -import { Message, Permissions } from 'discord.js'; +import { Message, PermissionsBitField } from 'discord.js'; import { Bot } from '../Bot'; import { Keyword } from './Keyword'; export class Poggers implements Keyword { name: string = 'poggers'; requiredPermissions: bigint[] = [ - Permissions.FLAGS.ADD_REACTIONS, - Permissions.FLAGS.USE_EXTERNAL_EMOJIS, + PermissionsBitField.Flags.AddReactions, + PermissionsBitField.Flags.UseExternalEmojis, ]; async run( bot: Bot, diff --git a/src/keywords/SevenTwentySeven.ts b/src/keywords/SevenTwentySeven.ts index 681dcd0..7f511da 100644 --- a/src/keywords/SevenTwentySeven.ts +++ b/src/keywords/SevenTwentySeven.ts @@ -1,17 +1,17 @@ //Keyword: 727 //Reacts to the keyword with WYSI embed -import { Message, Permissions, MessageEmbed } from 'discord.js'; +import { Message, PermissionsBitField, EmbedBuilder } from 'discord.js'; import { Bot } from '../Bot'; import { Keyword } from './Keyword'; export class SevenTwentySeven implements Keyword { name: string = '727'; requiredPermissions: bigint[] = [ - Permissions.FLAGS.MANAGE_MESSAGES, - Permissions.FLAGS.USE_EXTERNAL_EMOJIS, - Permissions.FLAGS.SEND_MESSAGES, - Permissions.FLAGS.EMBED_LINKS, + PermissionsBitField.Flags.ManageMessages, + PermissionsBitField.Flags.UseExternalEmojis, + PermissionsBitField.Flags.SendMessages, + PermissionsBitField.Flags.EmbedLinks, ]; async run( bot: Bot, @@ -20,7 +20,7 @@ export class SevenTwentySeven implements Keyword { ): Promise { try { await message.delete(); - let embed = new MessageEmbed() + let embed = new EmbedBuilder() .setColor('#ff66aa') .setImage('https://c.tenor.com/zbPLwrk_K44AAAAC/wysi.gif') .setTitle('**__WHEN YOU FUCKING SEE IT__**'); diff --git a/src/keywords/Warn.ts b/src/keywords/Warn.ts index 65cb98a..912fe56 100644 --- a/src/keywords/Warn.ts +++ b/src/keywords/Warn.ts @@ -1,10 +1,10 @@ -import { Message, Permissions } from 'discord.js'; +import { Message, PermissionsBitField } from 'discord.js'; import { Bot } from '../Bot'; import { Keyword } from './Keyword'; export class Warn implements Keyword { name: string = '!warn'; - requiredPermissions: bigint[] = [Permissions.FLAGS.SEND_MESSAGES]; + requiredPermissions: bigint[] = [PermissionsBitField.Flags.SendMessages]; async run( bot: Bot, message: Message, diff --git a/src/keywords/whydidntitalktoher.ts b/src/keywords/whydidntitalktoher.ts index eda3f55..0e713b2 100644 --- a/src/keywords/whydidntitalktoher.ts +++ b/src/keywords/whydidntitalktoher.ts @@ -2,13 +2,13 @@ //man.... //what could have been -import { Message, Permissions } from 'discord.js'; +import { Message, Permissions, PermissionsBitField } from 'discord.js'; import { Bot } from '../Bot'; import { Keyword } from './Keyword'; export class whydidntitalktoher implements Keyword { name: string = 'whydidntitalktoher'; - requiredPermissions: bigint[] = [Permissions.FLAGS.ADD_REACTIONS]; + requiredPermissions: bigint[] = [PermissionsBitField.Flags.AddReactions]; async run( bot: Bot, message: Message, diff --git a/src/messagecommands/Cringe.ts b/src/messagecommands/Cringe.ts index 25ef914..ad02979 100644 --- a/src/messagecommands/Cringe.ts +++ b/src/messagecommands/Cringe.ts @@ -1,12 +1,12 @@ -import { Message, Permissions } from 'discord.js'; +import { Message, PermissionsBitField } from 'discord.js'; import { Bot } from '../Bot'; import { MessageCommand } from './MessageCommand'; export class Cringe implements MessageCommand { name: string = 'cringe'; requiredPermissions: bigint[] = [ - Permissions.FLAGS.SEND_MESSAGES, - Permissions.FLAGS.EMBED_LINKS, + PermissionsBitField.Flags.SendMessages, + PermissionsBitField.Flags.EmbedLinks, ]; async run( bot: Bot, diff --git a/src/messagecommands/Cum.ts b/src/messagecommands/Cum.ts index 71da69b..8e068de 100644 --- a/src/messagecommands/Cum.ts +++ b/src/messagecommands/Cum.ts @@ -1,5 +1,5 @@ //penis pie makes the chicken cry -import { Message, Permissions } from 'discord.js'; +import { Message, PermissionsBitField } from 'discord.js'; import { Bot } from '../Bot'; import { MessageCommand } from './MessageCommand'; @@ -8,8 +8,8 @@ import { nsfw } from '../slashcommands/Nsfw'; export class Cum implements MessageCommand { name: string = 'cum'; requiredPermissions: bigint[] = [ - Permissions.FLAGS.SEND_MESSAGES, - Permissions.FLAGS.EMBED_LINKS, + PermissionsBitField.Flags.SendMessages, + PermissionsBitField.Flags.EmbedLinks, ]; async run( bot: Bot, diff --git a/src/messagecommands/Scurvy.ts b/src/messagecommands/Scurvy.ts index 2c5bdc1..21335a2 100644 --- a/src/messagecommands/Scurvy.ts +++ b/src/messagecommands/Scurvy.ts @@ -1,15 +1,16 @@ //Hidden command $scurvy, pretty lit -import { Message, Permissions } from 'discord.js'; +import { Message, PermissionsBitField } from 'discord.js'; import { Bot } from '../Bot'; import { MessageCommand } from './MessageCommand'; export class Scurvy implements MessageCommand { name: string = 'scurvy'; requiredPermissions: bigint[] = [ - Permissions.FLAGS.SEND_MESSAGES, - Permissions.FLAGS.EMBED_LINKS, - Permissions.FLAGS.MANAGE_MESSAGES, + PermissionsBitField.Flags.SendMessages, + PermissionsBitField.Flags.EmbedLinks, + PermissionsBitField.Flags.ManageMessages, + ]; async run( bot: Bot, diff --git a/src/messagecommands/Superidol.ts b/src/messagecommands/Superidol.ts index 69b08a7..ce8a1cb 100644 --- a/src/messagecommands/Superidol.ts +++ b/src/messagecommands/Superidol.ts @@ -7,16 +7,16 @@ import { createAudioResource, joinVoiceChannel, } from '@discordjs/voice'; -import { Message, Permissions, TextChannel } from 'discord.js'; +import { Message, PermissionsBitField, TextChannel } from 'discord.js'; import { Bot } from '../Bot'; import { MessageCommand } from './MessageCommand'; export class Superidol implements MessageCommand { name: string = 'superidol105'; requiredPermissions: bigint[] = [ - Permissions.FLAGS.MANAGE_MESSAGES, - Permissions.FLAGS.SPEAK, - Permissions.FLAGS.CONNECT, + PermissionsBitField.Flags.ManageMessages, + PermissionsBitField.Flags.Speak, + PermissionsBitField.Flags.Connect, ]; async run( bot: Bot, diff --git a/src/messagecommands/fuckimissheralready.ts b/src/messagecommands/fuckimissheralready.ts index b5034d3..fa132c9 100644 --- a/src/messagecommands/fuckimissheralready.ts +++ b/src/messagecommands/fuckimissheralready.ts @@ -6,7 +6,7 @@ //actually rent free //got me so depressed im actually doing school work, thats a new low -import { Message, Permissions, MessageEmbed } from 'discord.js'; +import { Message, PermissionsBitField, EmbedBuilder } from 'discord.js'; import { Bot } from '../Bot'; import { MessageCommand } from './MessageCommand'; import fetch from 'node-fetch'; @@ -17,9 +17,9 @@ import { nsfw } from '../slashcommands/Nsfw'; export class fuckimissheralready implements MessageCommand { name: string = 'fuckimissheralready'; requiredPermissions: bigint[] = [ - Permissions.FLAGS.MANAGE_MESSAGES, - Permissions.FLAGS.SEND_MESSAGES, - Permissions.FLAGS.EMBED_LINKS, + PermissionsBitField.Flags.SendMessages, + PermissionsBitField.Flags.EmbedLinks, + PermissionsBitField.Flags.ManageMessages, ]; async run( bot: Bot, @@ -31,7 +31,7 @@ export class fuckimissheralready implements MessageCommand { if (nsfw.get(message.guild!.id) != 'on') return; let res = await fetch(`https://nekos.best/api/v1/cry`); let jsonData = await res.json(); - let embed = new MessageEmbed() + let embed = new EmbedBuilder() .setColor('#0071b6') .setImage(jsonData.url) .setFooter({ text: 'I feel you bro' }); diff --git a/src/resources/birthdayTimer.ts b/src/resources/birthdayTimer.ts index 8095984..0402ab5 100644 --- a/src/resources/birthdayTimer.ts +++ b/src/resources/birthdayTimer.ts @@ -1,7 +1,7 @@ import { bdayDates } from '../slashcommands/Birthday'; import cron from 'node-cron'; import { Bot } from '../Bot'; -import { MessageEmbed, TextChannel, User } from 'discord.js'; +import { EmbedBuilder, TextChannel, User } from 'discord.js'; import Enmap from 'enmap'; import { bdayChannels, bdayTimes } from '../slashcommands/BirthdayConfig'; import { silencedUsers } from '../slashcommands/SilenceMember'; @@ -58,10 +58,10 @@ export async function birthdayTimer(guild: string, bot: Bot): Promise { let targetChannel = bot.client.channels!.cache.get( bdayChannels.get(guild) ) as TextChannel; - if (!targetChannel) return; + if (!targetChannel) return; //TODO, remove channel and send a log //create embed and send - const bdayEmbed = new MessageEmbed() + const bdayEmbed = new EmbedBuilder() .setDescription(`**:birthday: Happy Birthday <@${userId}> :tada:**`) .setColor(member.displayHexColor) .setFooter({ diff --git a/src/resources/embedColorCheck.ts b/src/resources/embedColorCheck.ts index ffbb80e..d4e7b69 100644 --- a/src/resources/embedColorCheck.ts +++ b/src/resources/embedColorCheck.ts @@ -4,7 +4,7 @@ import { serverColors } from "../slashcommands/ServerColor"; export function colorCheck(guildID: string, music?: boolean): ColorResolvable { let color = serverColors.get(guildID); if(!color){ - if(music) return'BLUE'; + if(music) return 'Blue'; return '#FFFFFF'; } return color; diff --git a/src/resources/managerCheck.ts b/src/resources/managerCheck.ts index 879bf3e..9a2537b 100644 --- a/src/resources/managerCheck.ts +++ b/src/resources/managerCheck.ts @@ -3,7 +3,7 @@ import { managerRoles } from '../slashcommands/ManagerRole'; export async function managerCheck(interaction: Interaction): Promise { let member = interaction.guild!.members.cache.get(interaction.user.id); - if (member?.permissions.toArray().includes('ADMINISTRATOR')) return true; + if (member?.permissions.toArray().includes('Administrator')) return true; let roleArray = managerRoles.ensure(interaction.guild!.id, []); for (let role of roleArray) { if (member?.roles.cache.has(role)) { diff --git a/src/resources/msgPermCheck.ts b/src/resources/msgPermCheck.ts index 7e75b24..5e6a176 100644 --- a/src/resources/msgPermCheck.ts +++ b/src/resources/msgPermCheck.ts @@ -4,7 +4,7 @@ import { Client, Message, TextChannel, GuildMember } from 'discord.js'; import { Bot } from '../Bot'; -//Permissions.FLAGS properties are all bigints, thus we take an array of them for permissionsToCheck +//PermissionsBitField.Flags properties are all bigints, thus we take an array of them for permissionsToCheck export async function msgPermsCheck( bot: Bot, message: Message, diff --git a/src/resources/permissionsCheck.ts b/src/resources/permissionsCheck.ts index 974cae5..4fa577a 100644 --- a/src/resources/permissionsCheck.ts +++ b/src/resources/permissionsCheck.ts @@ -2,7 +2,7 @@ import { Interaction, TextChannel } from 'discord.js'; import { Bot } from '../Bot'; -//Permissions.FLAGS properties are all bigints, thus we take an array of them for permissionsToCheck +//PermissionsBitField.Flags properties are all bigints, thus we take an array of them for permissionsToCheck export async function permissionsCheck( bot: Bot, interaction: Interaction, diff --git a/src/resources/voiceCommandCheck.ts b/src/resources/voiceCommandCheck.ts index 6ae4e64..d3d4eaa 100644 --- a/src/resources/voiceCommandCheck.ts +++ b/src/resources/voiceCommandCheck.ts @@ -1,5 +1,5 @@ import { joinVoiceChannel } from "@discordjs/voice"; -import { CommandInteraction, GuildMember, MessageEmbed } from "discord.js"; +import { CommandInteraction, GuildMember, EmbedBuilder } from "discord.js"; import { transpileModule } from "typescript"; import { Bot } from "../Bot"; import { colorCheck } from "./embedColorCheck"; @@ -7,7 +7,7 @@ import { colorCheck } from "./embedColorCheck"; export function voiceCommandCheck(bot: Bot, interaction: CommandInteraction): boolean { let member = interaction.member as GuildMember; let state = member.voice.channel; - var embed = new MessageEmbed().setColor(colorCheck(interaction.guild!.id,true)); + var embed = new EmbedBuilder().setColor(colorCheck(interaction.guild!.id,true)); //if user is not connected if (!state) { @@ -17,7 +17,7 @@ export function voiceCommandCheck(bot: Bot, interaction: CommandInteraction): bo } //if mirror is not connected to voice - if (!interaction.guild!.me?.voice.channel) { + if (!interaction.guild!.members.me?.voice.channel) { const cmdCatches = ["play","playNext","join","sicko"]; if(cmdCatches.includes(interaction.commandName)){ joinVoiceChannel({ @@ -34,7 +34,7 @@ export function voiceCommandCheck(bot: Bot, interaction: CommandInteraction): bo } } //if the user is not connected to the correct voice, end - else if (interaction.guild!.me?.voice.channel!.id != state.id) { + else if (interaction.guild!.members.me?.voice.channel!.id != state.id) { embed.setDescription( 'Mirror is not in your voice channel! To use voice commands join the channel mirror is sitting in, or use `join` to move it to your call' ); diff --git a/src/slashcommands/Birthday.ts b/src/slashcommands/Birthday.ts index e28f81b..5fc82ed 100644 --- a/src/slashcommands/Birthday.ts +++ b/src/slashcommands/Birthday.ts @@ -1,10 +1,10 @@ import { CommandInteraction, + CommandInteractionOptionResolver, CacheType, - MessageEmbed, - ApplicationCommandDataResolvable, + EmbedBuilder, + ApplicationCommandOptionType, } from 'discord.js'; -import { ApplicationCommandOptionTypes } from 'discord.js/typings/enums'; import Enmap from 'enmap'; import { Bot } from '../Bot'; import { colorCheck } from '../resources/embedColorCheck'; @@ -104,15 +104,15 @@ export class Birthday implements SlashCommand { new Option( 'month', 'Your Birth Month', - ApplicationCommandOptionTypes.STRING, + ApplicationCommandOptionType.String, true, 'may', - months + months, ), new Option( 'day', 'The date of your birthday', - ApplicationCommandOptionTypes.INTEGER, + ApplicationCommandOptionType.Integer, true ), ]; @@ -124,36 +124,41 @@ export class Birthday implements SlashCommand { try { let userArray = silencedUsers.ensure(interaction.guild!.id, []); if (userArray.includes(interaction.user.id)) { - return interaction.reply({ + interaction.reply({ content: 'Silenced users cannot use this command', ephemeral: true, }); + return; } + //Manually typecasting to avoid errors TODO: test this + var options = interaction.options as CommandInteractionOptionResolver; if ( - interaction.options.getInteger('day')! > - dayCap[interaction.options.getString('month')!] || - interaction.options.getInteger('day')! < 1 + options.getInteger('day')! > + dayCap[options.getString('month')!] || + options.getInteger('day')! < 1 ) { - return interaction.reply({ + interaction.reply({ content: 'Please enter a valid date', ephemeral: true, }); + return; } //store the date of birth in numerical form DD-MM - let formattedBirthday = `${interaction.options.getInteger('day')}-${ - monthCode[interaction.options.getString('month')!] + let formattedBirthday = `${options.getInteger('day')}-${ + monthCode[options.getString('month')!] }`; + //set the new birthday into the enmap bdayDates.set(interaction.user.id, formattedBirthday); let monthCap = - interaction.options.getString('month')!.charAt(0).toUpperCase() + - interaction.options.getString('month')!.slice(1); - let embed = new MessageEmbed() + options.getString('month')!.charAt(0).toUpperCase() + + options.getString('month')!.slice(1); + let embed = new EmbedBuilder() .setDescription( - `Successfully set your birthday to: ${monthCap} ${interaction.options.getInteger( + `Successfully set your birthday to: ${monthCap} ${options.getInteger( 'day' )}` ) diff --git a/src/slashcommands/BirthdayConfig.ts b/src/slashcommands/BirthdayConfig.ts index 1b92fde..9e9b6f9 100644 --- a/src/slashcommands/BirthdayConfig.ts +++ b/src/slashcommands/BirthdayConfig.ts @@ -5,9 +5,11 @@ import { GuildMember, TextChannel, GuildChannel, - MessageEmbed, + EmbedBuilder, + ApplicationCommandOptionType, + CommandInteractionOptionResolver, + ChannelType, } from 'discord.js'; -import { ApplicationCommandOptionTypes } from 'discord.js/typings/enums'; import { Bot } from '../Bot'; import { SlashCommand } from './SlashCommand'; import { Option } from './Option'; @@ -46,25 +48,25 @@ export class BirthdayConfig implements SlashCommand { new Option( 'channel', 'Set the channel where the birthday messages are sent to', - ApplicationCommandOptionTypes.CHANNEL, + ApplicationCommandOptionType.Channel, true ), new Option( 'hour', 'The hour you want to send Birthday messages in local time, military format (0-23)', - ApplicationCommandOptionTypes.INTEGER, + ApplicationCommandOptionType.Integer, true ), new Option( 'minute', 'The minute you want to send Birthday messages', - ApplicationCommandOptionTypes.INTEGER, + ApplicationCommandOptionType.Integer, true ), new Option( 'timezone', 'Your local timezone', - ApplicationCommandOptionTypes.STRING, + ApplicationCommandOptionType.String, true, 'cst', timezones @@ -82,7 +84,7 @@ export class BirthdayConfig implements SlashCommand { interaction.reply('Command must be used in a server'); return; } - if (!member.permissionsIn(interaction.channel).has('ADMINISTRATOR')) { + if (!member.permissionsIn(interaction.channel).has('Administrator')) { interaction.reply({ content: 'This command is only for people with Administrator permissions', @@ -91,11 +93,13 @@ export class BirthdayConfig implements SlashCommand { return; } + //Manually Typecast + var options = interaction.options as CommandInteractionOptionResolver; //recieve the provided channel and check if its a text channel - var guildChannel = interaction.options.getChannel( + var guildChannel = options.getChannel( 'channel' ) as GuildChannel; - if (guildChannel.type != 'GUILD_TEXT') { + if (guildChannel.type != ChannelType.GuildText) { interaction.reply({ content: 'Please enter a valid text channel', ephemeral: true, @@ -107,25 +111,27 @@ export class BirthdayConfig implements SlashCommand { bdayChannels.set(interaction.guild!.id, guildChannel.id); //get the hour and ensure that it is valid - let hour = interaction.options.getInteger('hour')!; + let hour = options.getInteger('hour')!; if (hour > 23 || hour < 0) { - return interaction.reply({ + interaction.reply({ content: 'Invalid hour, please use military format (0-23) where 0 represents midnight.', ephemeral: true, }); + return; } //get the minute and ensure that it is valid - let minute = interaction.options.getInteger('minute')!; + let minute = options.getInteger('minute')!; if (minute > 60 || minute < 0) { - return interaction.reply({ + interaction.reply({ content: 'Invalid minute, please provide an integer between 0 and 60', ephemeral: true, }); + return; } //get the timezone and modify the time to create parity with CST - let timezone = interaction.options.getString('timezone')!; + let timezone = options.getString('timezone')!; let tzChange = timezoneCode[timezone]; let cst = hour + tzChange; @@ -150,10 +156,10 @@ export class BirthdayConfig implements SlashCommand { let minuteText = minute.toString(); if (hour < 10) hourText = '0' + hourText; if (minute < 10) minuteText = '0' + minuteText; - let embed = new MessageEmbed() + let embed = new EmbedBuilder() .setColor(colorCheck(interaction.guild!.id)) .setDescription( - `Successfully scheduled your birthday timer for **\`${hourText}:${minuteText}\` \`${timezone.toUpperCase()}\`** in ${interaction.options.getChannel( + `Successfully scheduled your birthday timer for **\`${hourText}:${minuteText}\` \`${timezone.toUpperCase()}\`** in ${options.getChannel( 'channel' )}` ); diff --git a/src/slashcommands/BirthdayList.ts b/src/slashcommands/BirthdayList.ts index 6199b0c..d124b02 100644 --- a/src/slashcommands/BirthdayList.ts +++ b/src/slashcommands/BirthdayList.ts @@ -1,4 +1,4 @@ -import { CommandInteraction, CacheType, MessageEmbed, Message, User, MessageReaction } from 'discord.js'; +import { CommandInteraction, CacheType, EmbedBuilder, Message, User, MessageReaction } from 'discord.js'; import { Bot } from '../Bot'; import { Option, Subcommand } from './Option'; import { SlashCommand} from './SlashCommand'; @@ -41,7 +41,7 @@ export class BirthdayList implements SlashCommand { let currentPage = 1; let initialPage = populatePage(1,list); - let embed = new MessageEmbed() + let embed = new EmbedBuilder() .setTitle(`Birthday List for ${interaction.guild!.name}`) .setFooter({text: `Page ${currentPage} of ${pages}`}) .addFields( @@ -55,7 +55,6 @@ export class BirthdayList implements SlashCommand { inline: true, } ) - let index = 0; let message = await interaction.editReply({ embeds: [embed]}) as Message; diff --git a/src/slashcommands/Config.ts b/src/slashcommands/Config.ts index e6e46c7..be902f9 100644 --- a/src/slashcommands/Config.ts +++ b/src/slashcommands/Config.ts @@ -2,18 +2,18 @@ import { ApplicationCommandDataResolvable, CommandInteraction, CacheType, - MessageEmbed, + EmbedBuilder, Permissions, GuildChannel, GuildChannelResolvable, PermissionOverwriteManager, PermissionResolvable, + PermissionsBitField, } from 'discord.js'; import { Bot } from '../Bot'; import { SlashCommand } from './SlashCommand'; import { bdayChannels } from './BirthdayConfig'; import { defaultVc } from './DefaultVc'; -import { updateChannels } from './Update'; import { nsfw } from './Nsfw'; import { managerRoles } from './ManagerRole'; import { silencedRole } from './SilenceRole'; @@ -21,24 +21,24 @@ import { serverColors } from './ServerColor'; import { colorCheck } from '../resources/embedColorCheck'; const permList = [ - ['ADD_REACTIONS', Permissions.FLAGS.ADD_REACTIONS], - ['CONNECT', Permissions.FLAGS.CONNECT], - ['EMBED_LINKS', Permissions.FLAGS.EMBED_LINKS], - ['MANAGE_MESSAGES',Permissions.FLAGS.MANAGE_MESSAGES], - ['MOVE_MEMBERS', Permissions.FLAGS.MOVE_MEMBERS], - ['SEND_MESSAGES', Permissions.FLAGS.SEND_MESSAGES], - ['SPEAK', Permissions.FLAGS.SPEAK], - ['USE_EXTERNAL_EMOJIS',Permissions.FLAGS.USE_EXTERNAL_EMOJIS], - ['VIEW_CHANNEL',Permissions.FLAGS.VIEW_CHANNEL]] + ['ADD_REACTIONS', PermissionsBitField.Flags.AddReactions], + ['CONNECT', PermissionsBitField.Flags.Connect], + ['EMBED_LINKS', PermissionsBitField.Flags.EmbedLinks], + ['MANAGE_MESSAGES',PermissionsBitField.Flags.ManageMessages], + ['MOVE_MEMBERS', PermissionsBitField.Flags.MoveMembers], + ['SEND_MESSAGES', PermissionsBitField.Flags.SendMessages], + ['SPEAK', PermissionsBitField.Flags.Speak], + ['USE_EXTERNAL_EMOJIS',PermissionsBitField.Flags.UseExternalEmojis], + ['VIEW_CHANNEL',PermissionsBitField.Flags.ViewChannel]] export class Config implements SlashCommand { name: string = 'config'; description = 'See the configuration settings for this server'; options = []; - requiredPermissions: bigint[] = [Permissions.FLAGS.SEND_MESSAGES]; + requiredPermissions: bigint[] = [PermissionsBitField.Flags.SendMessages]; async run(bot: Bot, interaction: CommandInteraction): Promise { try { - let embed = new MessageEmbed() + let embed = new EmbedBuilder() .setTitle(`:gear: Server Settings for ${interaction.guild?.name}`) .setColor(colorCheck(interaction.guild!.id)); let lines: any[][] = [ @@ -51,14 +51,9 @@ export class Config implements SlashCommand { ]; let bday = bdayChannels.get(interaction.guild!.id); let defaultVoice = defaultVc.get(interaction.guild!.id); - let update = updateChannels.get(interaction.guild!.id); let nsfwToggle = nsfw.get(interaction.guild!.id); let silence = silencedRole.get(interaction.guild!.id); let serverColor = serverColors.get(interaction.guild!.id); - if (update) { - update = bot.client.channels.cache.get(update); - lines[1][2] = update; - } if (bday) { bday = bot.client.channels.cache.get(bday); lines[2][2] = bday; @@ -133,14 +128,19 @@ export class Config implements SlashCommand { } permString += '\n' + 'Assign mirror the missing permissions to ensure full functionality' } - embed.addField('Permissions', permString); - return interaction.reply({ embeds: [embed] }); + embed.addFields({ + name:'Permissions', + value:permString + }); + interaction.reply({ embeds: [embed] }); + return; } catch (err) { bot.logger.commandError(interaction.channel!.id, this.name, err); - return interaction.reply({ + interaction.reply({ content: 'Error detected, contact an admin to investigate.', ephemeral: true, }); + return; } } guildRequired?: boolean | undefined = true; diff --git a/src/slashcommands/DefaultVc.ts b/src/slashcommands/DefaultVc.ts index 9fb206a..5f200ff 100644 --- a/src/slashcommands/DefaultVc.ts +++ b/src/slashcommands/DefaultVc.ts @@ -6,10 +6,11 @@ import { VoiceChannel, GuildMember, TextChannel, - MessageEmbed, + EmbedBuilder, Guild, + ApplicationCommandOptionType, + CommandInteractionOptionResolver, } from 'discord.js'; -import { ApplicationCommandOptionTypes } from 'discord.js/typings/enums'; import Enmap from 'enmap'; import { Bot } from '../Bot'; import { colorCheck } from '../resources/embedColorCheck'; @@ -26,7 +27,7 @@ export class DefaultVc implements SlashCommand { new Option( 'channel', 'The channel you wish to designate as the default', - ApplicationCommandOptionTypes.CHANNEL, + ApplicationCommandOptionType.Channel, true ), ]; @@ -39,7 +40,7 @@ export class DefaultVc implements SlashCommand { let member = interaction.member as GuildMember; if ( !(interaction.channel instanceof TextChannel) || - !member.permissionsIn(interaction.channel!).has('ADMINISTRATOR') + !member.permissionsIn(interaction.channel!).has('Administrator') ) { interaction.reply({ content: @@ -48,7 +49,9 @@ export class DefaultVc implements SlashCommand { }); return; } - let channel = interaction.options.getChannel('channel'); + + var options = interaction.options as CommandInteractionOptionResolver; + let channel = options.getChannel('channel'); if (!(channel instanceof VoiceChannel)) { interaction.reply({ content: 'Channel must be a voice channel', @@ -56,7 +59,7 @@ export class DefaultVc implements SlashCommand { }); return; } - if (!interaction.guild?.me?.permissionsIn(channel.id).has('CONNECT')) { + if (!interaction.guild!.members!.me?.permissionsIn(channel.id).has('Connect')) { interaction.reply({ content: 'I do not have permission to Connect to that VC', ephemeral: true, @@ -64,7 +67,7 @@ export class DefaultVc implements SlashCommand { return; } defaultVc.set(interaction.guild!.id, channel.id); - let embed = new MessageEmbed() + let embed = new EmbedBuilder() .setColor(colorCheck(interaction.guild!.id)) .setDescription( `Sucessfully updated your default voice channel to ${channel}` diff --git a/src/slashcommands/Gavin.ts b/src/slashcommands/Gavin.ts index bb96db6..a1ac5b7 100644 --- a/src/slashcommands/Gavin.ts +++ b/src/slashcommands/Gavin.ts @@ -5,11 +5,12 @@ import { ChatInputApplicationCommandData, CommandInteraction, - Permissions, - MessageEmbed, + PermissionsBitField, + EmbedBuilder, Options, + ApplicationCommandOptionType, + CommandInteractionOptionResolver, } from 'discord.js'; -import { ApplicationCommandOptionTypes } from 'discord.js/typings/enums'; import Enmap from 'enmap'; import { Bot } from '../Bot'; import { colorCheck } from '../resources/embedColorCheck'; @@ -43,7 +44,7 @@ export class Gavin implements SlashCommand { new Option( 'lifttype', 'the lift to display', - ApplicationCommandOptionTypes.STRING, + ApplicationCommandOptionType.String, true, 'deadlift', liftChoices @@ -53,7 +54,7 @@ export class Gavin implements SlashCommand { new Option( 'lifttype', 'the lift to set', - ApplicationCommandOptionTypes.STRING, + ApplicationCommandOptionType.String, true, 'deadlift', liftChoices @@ -61,25 +62,25 @@ export class Gavin implements SlashCommand { new Option( 'lift', 'the lift record', - ApplicationCommandOptionTypes.NUMBER, + ApplicationCommandOptionType.Number, true, 1 ), ]), ]; requiredPermissions: bigint[] = [ - Permissions.FLAGS.SEND_MESSAGES, - Permissions.FLAGS.EMBED_LINKS, + PermissionsBitField.Flags.EmbedLinks, + PermissionsBitField.Flags.SendMessages ]; async run(bot: Bot, interaction: CommandInteraction): Promise { try { - const options = interaction.options; + const options = interaction.options as CommandInteractionOptionResolver; if (options.getSubcommand() == 'all') { // subcommand for printing all the data let bench = gav_records.ensure('bench', 365); let squat = gav_records.ensure('squat', 445); let deadlift = gav_records.ensure('deadlift', 605); - const embed = new MessageEmbed() + const embed = new EmbedBuilder() .setColor(colorCheck(interaction.guild!.id)) .setDescription( `GAVIN'S CURRENT PRS:\n BENCH: ${bench} LB \n SQUAT: ${squat} LB \n DEADLIFT: ${deadlift} LB \n` @@ -100,7 +101,7 @@ export class Gavin implements SlashCommand { interaction.reply('INVALID LOOKUP'); return; } - const embed = new MessageEmbed() + const embed = new EmbedBuilder() .setColor(colorCheck(interaction.guild!.id)) .setDescription(`GAVIN'S ${type!.toUpperCase()} PR: ${toprint}`); interaction.reply({ embeds: [embed] }); @@ -114,7 +115,7 @@ export class Gavin implements SlashCommand { if (type == 'squat') gav_records.set('squat', lift); if (type == 'deadlift') gav_records.set('deadlift', lift); - const embed = new MessageEmbed() + const embed = new EmbedBuilder() .setColor(colorCheck(interaction.guild!.id)) .setDescription( `UPDATED GAVIN'S ${type!.toUpperCase()} PR TO: ${lift}\nGOOD JOB SOLDIER` diff --git a/src/slashcommands/Github.ts b/src/slashcommands/Github.ts index e010f25..fc6e747 100644 --- a/src/slashcommands/Github.ts +++ b/src/slashcommands/Github.ts @@ -2,7 +2,7 @@ import { ChatInputApplicationCommandData, CommandInteraction, CacheType, - MessageEmbed, + EmbedBuilder, } from 'discord.js'; import { Bot } from '../Bot'; import { SlashCommand } from './SlashCommand'; @@ -17,7 +17,7 @@ export class Github implements SlashCommand { interaction: CommandInteraction ): Promise { try { - const embed = new MessageEmbed() + const embed = new EmbedBuilder() .setColor('#FFFFFF') .setTitle(':lock: __Mirror-TS Codebase and Privacy__') .setDescription( diff --git a/src/slashcommands/Help.ts b/src/slashcommands/Help.ts index 057561b..7dabe0b 100644 --- a/src/slashcommands/Help.ts +++ b/src/slashcommands/Help.ts @@ -5,10 +5,11 @@ import { CommandInteraction, CommandOptionChannelResolvableType, Message, - MessageEmbed, + EmbedBuilder, MessageReaction, Permissions, User, + PermissionsBitField, } from 'discord.js'; import { Bot } from '../Bot'; import { colorCheck } from '../resources/embedColorCheck'; @@ -19,10 +20,10 @@ export class Help implements SlashCommand { description: string = 'Information about the bot'; options = []; requiredPermissions: bigint[] = [ - Permissions.FLAGS.SEND_MESSAGES, - Permissions.FLAGS.EMBED_LINKS, - Permissions.FLAGS.MANAGE_MESSAGES, - Permissions.FLAGS.ADD_REACTIONS, + PermissionsBitField.Flags.SendMessages, + PermissionsBitField.Flags.EmbedLinks, + PermissionsBitField.Flags.ManageMessages, + PermissionsBitField.Flags.AddReactions, ]; async run(bot: Bot, interaction: CommandInteraction): Promise { try { @@ -31,7 +32,7 @@ export class Help implements SlashCommand { bot.slashCommands.forEach((command)=>{ cmds[command.name] = command.description; }) - const page1 = new MessageEmbed() + const page1 = new EmbedBuilder() .setColor(colorCheck(interaction.guild!.id)) .setTitle(':mirror: **__Mirror__**') .setDescription('Informational and fun discord bot created by Ford, Zac, and Marty') @@ -53,7 +54,7 @@ export class Help implements SlashCommand { } ) .setFooter({ text: 'Page 1 of 5' }); - const page2 = new MessageEmbed() + const page2 = new EmbedBuilder() .setColor(colorCheck(interaction.guild!.id)) .setTitle(':sound: **__Voice Commands__**') .setDescription( @@ -82,7 +83,7 @@ export class Help implements SlashCommand { inline:false }) .setFooter({ text: 'Page 2 of 5' }); - const page3 = new MessageEmbed() + const page3 = new EmbedBuilder() .setColor(colorCheck(interaction.guild!.id)) .addFields({ name: 'Informative Commands', @@ -102,7 +103,7 @@ export class Help implements SlashCommand { `\`/roll\` ${cmds.roll}\n` }) .setFooter({ text: 'Page 3 of 5' }); - const page4 = new MessageEmbed() + const page4 = new EmbedBuilder() .setColor(colorCheck(interaction.guild!.id)) .setTitle(':bell: **__Server Configuration__**') .setDescription( @@ -119,7 +120,7 @@ export class Help implements SlashCommand { `\`/removeintro\` ${cmds.removeintro}\n` ) .setFooter({ text: 'Page 4 of 5' }); - const page5 = new MessageEmbed() + const page5 = new EmbedBuilder() .setColor(colorCheck(interaction.guild!.id)) .setTitle(':bell: **__Other Information__**') .addFields({ diff --git a/src/slashcommands/Intro.ts b/src/slashcommands/Intro.ts index c8c917e..e07c1b4 100644 --- a/src/slashcommands/Intro.ts +++ b/src/slashcommands/Intro.ts @@ -4,15 +4,16 @@ import { CacheType, ChatInputApplicationCommandData, CommandInteraction, + ApplicationCommandOptionType, + CommandInteractionOptionResolver, } from 'discord.js'; import fs from 'fs'; import ytdl from 'ytdl-core'; -import mkdirp from 'mkdirp'; +import { mkdirp } from 'mkdirp'; import { SlashCommand } from './SlashCommand'; import { Bot } from '../Bot'; import { silencedUsers } from './SilenceMember'; import { Option, Subcommand } from './Option'; -import { ApplicationCommandOptionTypes } from 'discord.js/typings/enums'; interface Format { approxDurationMs: number; @@ -25,7 +26,7 @@ export class Intro implements SlashCommand { new Option( 'video', 'Youtube link to intro', - ApplicationCommandOptionTypes.STRING, + ApplicationCommandOptionType.String, true ), ]; @@ -37,13 +38,15 @@ export class Intro implements SlashCommand { try { let userArray = silencedUsers.ensure(interaction.guild!.id, []); if (userArray.includes(interaction.user.id)) { - return interaction.reply({ + interaction.reply({ content: 'Silenced users cannot use this command', ephemeral: true, }); + return; } await interaction.deferReply({ ephemeral: true }); - const url = interaction.options.getString('video'); + var options = interaction.options as CommandInteractionOptionResolver; + const url = options.getString('video'); //TODO: validate the correct videos. const info = await ytdl.getInfo(url!); let format = info.player_response.streamingData.formats[0] as Format; diff --git a/src/slashcommands/Invite.ts b/src/slashcommands/Invite.ts index bc80ee7..41c9de9 100644 --- a/src/slashcommands/Invite.ts +++ b/src/slashcommands/Invite.ts @@ -2,8 +2,9 @@ import { CacheType, ChatInputApplicationCommandData, CommandInteraction, - MessageEmbed, + EmbedBuilder, Permissions, + PermissionsBitField, } from 'discord.js'; import { Bot } from '../Bot'; import { Option, Subcommand } from './Option'; @@ -14,15 +15,15 @@ export class Invite implements SlashCommand { description: string = 'Invite link for mirror'; options: (Option | Subcommand)[] = []; requiredPermissions: bigint[] = [ - Permissions.FLAGS.SEND_MESSAGES, - Permissions.FLAGS.EMBED_LINKS, + PermissionsBitField.Flags.SendMessages, + PermissionsBitField.Flags.EmbedLinks, ]; async run( bot: Bot, interaction: CommandInteraction ): Promise { try { - const embed = new MessageEmbed() + const embed = new EmbedBuilder() .setDescription( 'Want to invite Mirror to your own server? Click [here](https://discord.com/api/oauth2/authorize?client_id=887766414923022377&permissions=139606649936&scope=bot%20applications.commands).' ) diff --git a/src/slashcommands/Join.ts b/src/slashcommands/Join.ts index 58c8107..e4ff79d 100644 --- a/src/slashcommands/Join.ts +++ b/src/slashcommands/Join.ts @@ -12,6 +12,7 @@ import { CommandInteraction, GuildMember, Permissions, + PermissionsBitField, } from 'discord.js'; import { Bot } from '../Bot'; import { Option, Subcommand } from './Option'; @@ -21,7 +22,7 @@ export class Join implements SlashCommand { name: string = 'join'; description: string = 'Have Mirror join your voice channel'; options: (Option | Subcommand)[] = []; - requiredPermissions: bigint[] = [Permissions.FLAGS.SEND_MESSAGES]; + requiredPermissions: bigint[] = [PermissionsBitField.Flags.SendMessages]; async run( bot: Bot, interaction: CommandInteraction diff --git a/src/slashcommands/Kanye.ts b/src/slashcommands/Kanye.ts index c45b747..5a7cbaa 100644 --- a/src/slashcommands/Kanye.ts +++ b/src/slashcommands/Kanye.ts @@ -4,8 +4,9 @@ import { CacheType, ChatInputApplicationCommandData, CommandInteraction, - MessageEmbed, + EmbedBuilder, Permissions, + PermissionsBitField, } from 'discord.js'; import fetch from 'node-fetch'; import { Bot } from '../Bot'; @@ -17,8 +18,8 @@ export class Kanye implements SlashCommand { description: string = 'Kanye'; options = []; requiredPermissions: bigint[] = [ - Permissions.FLAGS.SEND_MESSAGES, - Permissions.FLAGS.EMBED_LINKS, + PermissionsBitField.Flags.SendMessages, + PermissionsBitField.Flags.EmbedLinks, ]; async run( bot: Bot, @@ -27,7 +28,7 @@ export class Kanye implements SlashCommand { try { let res = await fetch(`https://api.kanye.rest/`); let jsonData = await res.json(); - const embed = new MessageEmbed() + const embed = new EmbedBuilder() .setColor(colorCheck(interaction.guild!.id)) .setDescription(`**${jsonData.quote}**`) .setFooter({ diff --git a/src/slashcommands/Kawaii.ts b/src/slashcommands/Kawaii.ts index e0c41e1..9e454c4 100644 --- a/src/slashcommands/Kawaii.ts +++ b/src/slashcommands/Kawaii.ts @@ -4,8 +4,9 @@ import { CacheType, ChatInputApplicationCommandData, CommandInteraction, - MessageEmbed, + EmbedBuilder, Permissions, + PermissionsBitField, } from 'discord.js'; import fetch from 'node-fetch'; import { Bot } from '../Bot'; @@ -18,8 +19,8 @@ export class Kawaii implements SlashCommand { description: string = 'Wink, wink'; options: (Option | Subcommand)[] = []; requiredPermissions: bigint[] = [ - Permissions.FLAGS.SEND_MESSAGES, - Permissions.FLAGS.EMBED_LINKS, + PermissionsBitField.Flags.SendMessages, + PermissionsBitField.Flags.EmbedLinks, ]; async run( bot: Bot, @@ -29,7 +30,7 @@ export class Kawaii implements SlashCommand { //fetches the nekos.best api let res = await fetch(`https://nekos.best/api/v2/wink`); let jsonData = await res.json(); - let embed = new MessageEmbed().setColor(colorCheck(interaction.guild!.id)).setImage(jsonData.results[0].url); + let embed = new EmbedBuilder().setColor(colorCheck(interaction.guild!.id)).setImage(jsonData.results[0].url); interaction.reply({ embeds: [embed] }); } catch (err) { bot.logger.commandError(interaction.channel!.id, this.name, err); diff --git a/src/slashcommands/Leave.ts b/src/slashcommands/Leave.ts index b2b745f..6c0d1d1 100644 --- a/src/slashcommands/Leave.ts +++ b/src/slashcommands/Leave.ts @@ -5,6 +5,7 @@ import { ChatInputApplicationCommandData, CommandInteraction, Permissions, + PermissionsBitField, } from 'discord.js'; import { Bot } from '../Bot'; import { Option, Subcommand } from './Option'; @@ -15,15 +16,15 @@ export class Leave implements SlashCommand { description: string = 'Have Mirror leave your voice channel'; options: (Option | Subcommand)[] = []; requiredPermissions: bigint[] = [ - Permissions.FLAGS.SEND_MESSAGES, - Permissions.FLAGS.MOVE_MEMBERS, + PermissionsBitField.Flags.SendMessages, + PermissionsBitField.Flags.MoveMembers, ]; async run( bot: Bot, interaction: CommandInteraction ): Promise { try { - let mirrorVoice = interaction.guild!.me!.voice; + let mirrorVoice = interaction.guild!.members.me!.voice; if (!mirrorVoice.channel) { interaction.reply({ content: 'Not in a voice channel', diff --git a/src/slashcommands/ManagerRole.ts b/src/slashcommands/ManagerRole.ts index d2f106e..b2ce1cb 100644 --- a/src/slashcommands/ManagerRole.ts +++ b/src/slashcommands/ManagerRole.ts @@ -5,8 +5,9 @@ import { TextChannel, GuildMember, Role, + ApplicationCommandOptionType, + CommandInteractionOptionResolver, } from 'discord.js'; -import { ApplicationCommandOptionTypes } from 'discord.js/typings/enums'; import Enmap from 'enmap'; import { Bot } from '../Bot'; import { Option, Subcommand } from './Option'; @@ -21,7 +22,7 @@ export class ManagerRole implements SlashCommand { new Option( 'role', 'The role you want to add or remove as a manager', - ApplicationCommandOptionTypes.ROLE, + ApplicationCommandOptionType.Role, true ), ]; @@ -30,39 +31,44 @@ export class ManagerRole implements SlashCommand { bot: Bot, interaction: CommandInteraction ): Promise { - let role = interaction.options.getRole('role') as Role; + var options = interaction.options as CommandInteractionOptionResolver; + let role = options.getRole('role') as Role; if (role.managed) { - return interaction.reply({ + interaction.reply({ content: 'Cannot set externally managed roles, or bot roles as Mirror Managers', ephemeral: true, }); + return; } let roleArray = managerRoles.ensure(interaction.guild!.id, []); if (roleArray.includes(role.id)) { let ptr = roleArray.indexOf(role.id); roleArray.splice(ptr); managerRoles.set(interaction.guild!.id, roleArray); - return interaction.reply({ + interaction.reply({ content: `Successfully removed ${role} as a Mirror Manager`, ephemeral: true, }); + return; } //I fully expect us to never need this but if someone is just needlessly adding we should stop it if (roleArray.length > 15) { - return interaction.reply({ + interaction.reply({ content: 'Mirror limits servers to 15 manager roles. Please remove manager roles before adding more. If this is not possible contact a developer for more options', ephemeral: true, }); + return; } roleArray.push(role.id); managerRoles.set(interaction.guild!.id, roleArray); - return interaction.reply({ + interaction.reply({ content: `Successfully added ${role} as a Mirror Manager`, ephemeral: true, }); + return; } guildRequired?: boolean | undefined = true; managerRequired?: boolean | undefined = true; diff --git a/src/slashcommands/Mirror.ts b/src/slashcommands/Mirror.ts index b5716a9..e476362 100644 --- a/src/slashcommands/Mirror.ts +++ b/src/slashcommands/Mirror.ts @@ -5,7 +5,7 @@ import { ChatInputApplicationCommandData, CommandInteraction, CacheType, - Permissions, + PermissionsBitField, } from 'discord.js'; import { Bot } from '../Bot'; import { Option, Subcommand } from './Option'; @@ -15,7 +15,7 @@ export class Mirror implements SlashCommand { name: string = 'mirror'; description: string = 'Mirror go brrrr'; options: (Option | Subcommand)[] = []; - requiredPermissions: bigint[] = [Permissions.FLAGS.SEND_MESSAGES]; + requiredPermissions: bigint[] = [PermissionsBitField.Flags.SendMessages]; async run( bot: Bot, interaction: CommandInteraction diff --git a/src/slashcommands/Nasa.ts b/src/slashcommands/Nasa.ts index dd9c772..230544e 100644 --- a/src/slashcommands/Nasa.ts +++ b/src/slashcommands/Nasa.ts @@ -4,8 +4,8 @@ import { CacheType, ChatInputApplicationCommandData, CommandInteraction, - MessageEmbed, - Permissions, + EmbedBuilder, + PermissionsBitField, } from 'discord.js'; import fetch from 'node-fetch'; import { Bot } from '../Bot'; @@ -19,8 +19,8 @@ export class Nasa implements SlashCommand { description: string = 'NASA\'s astronomy picture of the day'; options: (Option | Subcommand)[] = []; requiredPermissions: bigint[] = [ - Permissions.FLAGS.SEND_MESSAGES, - Permissions.FLAGS.EMBED_LINKS, + PermissionsBitField.Flags.SendMessages, + PermissionsBitField.Flags.EmbedLinks, ]; async run( bot: Bot, @@ -34,7 +34,7 @@ export class Nasa implements SlashCommand { let jsonData = await res.json(); let footer = `${jsonData.date} NASA Astronomy Picture of the day`; //we need this for the deprecation error we are getting with .setFooter() bot.logger.debug(jsonData); // <- remove eventually; - var embed = new MessageEmbed() + var embed = new EmbedBuilder() .setColor(colorCheck(interaction.guild!.id)) .setDescription(`${jsonData.explanation.substr(0, 200)}...`) .setFooter({ text: footer }) diff --git a/src/slashcommands/Nsfw.ts b/src/slashcommands/Nsfw.ts index 13280cd..729f758 100644 --- a/src/slashcommands/Nsfw.ts +++ b/src/slashcommands/Nsfw.ts @@ -4,12 +4,15 @@ import { CacheType, ChatInputApplicationCommandData, Permissions, - MessageEmbed, + EmbedBuilder, GuildMember, GuildChannel, TextChannel, + ApplicationCommandOptionType, + PermissionsBitField, + CommandInteractionOption, + CommandInteractionOptionResolver, } from 'discord.js'; -import { ApplicationCommandOptionTypes } from 'discord.js/typings/enums'; import Enmap from 'enmap'; import { Bot } from '../Bot'; import { SlashCommand } from './SlashCommand'; @@ -36,13 +39,13 @@ export class Nsfw implements SlashCommand { new Option( 'toggle', 'Switch your servers NSFW status to ON or OFF', - ApplicationCommandOptionTypes.STRING, + ApplicationCommandOptionType.String, false, 'off', choices ), ]; - requiredPermissions: bigint[] = [Permissions.FLAGS.SEND_MESSAGES]; + requiredPermissions: bigint[] = [PermissionsBitField.Flags.SendMessages]; async run( bot: Bot, interaction: CommandInteraction @@ -53,7 +56,7 @@ export class Nsfw implements SlashCommand { interaction.reply('Command must be used in a server'); return; } - if (!member.permissionsIn(interaction.channel!).has('ADMINISTRATOR')) { + if (!member.permissionsIn(interaction.channel!).has('Administrator')) { interaction.reply({ content: 'This command is only for people with Administrator permissions', @@ -62,14 +65,15 @@ export class Nsfw implements SlashCommand { return; } var setting = nsfw.ensure(interaction.guild!.id, 'off'); - const embed = new MessageEmbed(); - if (interaction.options.getString('toggle') == 'on') { + const embed = new EmbedBuilder(); + const options = interaction.options as CommandInteractionOptionResolver; + if (options.getString('toggle') == 'on') { nsfw.set(interaction.guild!.id, 'on'); embed.setDescription('NSFW has been toggled `ON`'); interaction.reply({ embeds: [embed] }); return; } - if (interaction.options.getString('toggle') == 'off') { + if (options.getString('toggle') == 'off') { nsfw.set(interaction.guild!.id, 'off'); embed.setDescription('NSFW has been toggled `OFF`'); interaction.reply({ embeds: [embed] }); diff --git a/src/slashcommands/Nut.ts b/src/slashcommands/Nut.ts index 8724ad4..d84b771 100644 --- a/src/slashcommands/Nut.ts +++ b/src/slashcommands/Nut.ts @@ -1,5 +1,4 @@ -import { CommandInteraction, CacheType, MessageEmbed, User } from 'discord.js'; -import { ApplicationCommandOptionTypes } from 'discord.js/typings/enums'; +import { CommandInteraction, CacheType, EmbedBuilder, ApplicationCommandOptionType, CommandInteractionOptionResolver } from 'discord.js'; import Enmap from 'enmap'; import { Bot } from '../Bot'; import { Option, Subcommand } from './Option'; @@ -22,13 +21,13 @@ export class Nut implements SlashCommand { new Option( 'change', 'how many nuts to add', - ApplicationCommandOptionTypes.INTEGER, + ApplicationCommandOptionType.Integer, false ), new Option( 'user', 'whos jar to add nuts to', - ApplicationCommandOptionTypes.USER, + ApplicationCommandOptionType.User, false ), ]), @@ -36,13 +35,13 @@ export class Nut implements SlashCommand { new Option( 'change', 'How many nuts to remove', - ApplicationCommandOptionTypes.INTEGER, + ApplicationCommandOptionType.Integer, false ), new Option( 'user', 'whos jar to subtract nuts from', - ApplicationCommandOptionTypes.USER, + ApplicationCommandOptionType.User, false ), ]), @@ -51,7 +50,7 @@ export class Nut implements SlashCommand { requiredPermissions: bigint[] = []; async run(bot: Bot, interaction: CommandInteraction): Promise { try { - const embed = new MessageEmbed().setColor('#FDA50F'); + const embed = new EmbedBuilder().setColor('#FDA50F'); if ( Math.random() == 0.69 || Math.random() == 0.42 || @@ -62,10 +61,11 @@ export class Nut implements SlashCommand { embed.setImage(gifArray[index]); } - if (interaction.options.getSubcommand() == 'add') { + const options = interaction.options as CommandInteractionOptionResolver; + if (options.getSubcommand() == 'add') { let messageContent = true; - let change = interaction.options.getInteger('change'); - let jarUser = interaction.options.getUser('user'); + let change = options.getInteger('change'); + let jarUser = interaction.options.getUser('user'); //TODO, why does this work if (!change) change = 1; //if no change is provided, set to one. if (!jarUser) { //if no user is provided, set it to the user. @@ -80,12 +80,13 @@ export class Nut implements SlashCommand { messageContent ? `${jarUser}'s` : 'your' } jar, the new total is ${storage}` ); - return interaction.reply({ embeds: [embed] }); + interaction.reply({ embeds: [embed] }); + return; } - if (interaction.options.getSubcommand() == 'subtract') { + if (options.getSubcommand() == 'subtract') { let messageContent = true; - let change = interaction.options.getInteger('change'); + let change = options.getInteger('change'); let jarUser = interaction.options.getUser('user'); if (!change) change = 1; //if no change is provided, set to one. if (!jarUser) { @@ -101,16 +102,18 @@ export class Nut implements SlashCommand { messageContent ? `${jarUser}'s` : 'your' } jar, the new total is ${storage}` ); - return interaction.reply({ embeds: [embed] }); + interaction.reply({ embeds: [embed] }); + return; } - if (interaction.options.getSubcommand() == 'reset') { + if (options.getSubcommand() == 'reset') { nuts.set(interaction.user.id, 0); embed .setDescription('Your jar has been emptied') .setImage('https://c.tenor.com/injWPZSrCK0AAAAC/bear.gif'); - return interaction.reply({ embeds: [embed] }); + interaction.reply({ embeds: [embed] }); + return; } - if(interaction.options.getSubcommand() == 'leaderboard'){ + if(options.getSubcommand() == 'leaderboard'){ nuts.fetchEverything(); let guild = interaction.guild!; let leaderboard: any[][] = []; @@ -149,10 +152,11 @@ export class Nut implements SlashCommand { }; } catch (err) { bot.logger.commandError(interaction.channel!.id, this.name, err); - return interaction.reply({ + interaction.reply({ content: 'Error: contact a developer to investigate', ephemeral: true, }); + return; } } diff --git a/src/slashcommands/Option.ts b/src/slashcommands/Option.ts index d392841..cd3f499 100644 --- a/src/slashcommands/Option.ts +++ b/src/slashcommands/Option.ts @@ -1,4 +1,4 @@ -import { ApplicationCommandOptionTypes } from 'discord.js/typings/enums'; +import { ApplicationCommandOptionType } from 'discord.js'; type Choices = { name: string; @@ -18,7 +18,7 @@ export class Option { _name: string; //Description of the option _description: string; - //type of the option, you can use the ApplicationCommandOptionTypes class to make code more readable. + //type of the option, you can use the ApplicationCommandOptionType class to make code more readable. _type: number; //whether or not it's a required option _required: boolean; @@ -65,7 +65,7 @@ export class Subcommand { _name: string; _description: string; _options: Array