Skip to content

Commit

Permalink
deps: upgrade discord.js to v14
Browse files Browse the repository at this point in the history
  • Loading branch information
markokajzer committed Mar 26, 2023
1 parent da4c032 commit e7eebd9
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 96 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"dependencies": {
"@discordjs/opus": "^0.9.0",
"@discordjs/voice": "^0.15.0",
"discord.js": "^13.13.1",
"discord.js": "^14.8.0",
"fluent-ffmpeg": "^2.1.2",
"i18n": "0.13.2",
"lodash": "4.17.21",
Expand Down
41 changes: 18 additions & 23 deletions src/bot/SoundBot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { Client, Guild, Message, TextChannel, VoiceState } from 'discord.js';
import {
ChannelType,
Client,
GatewayIntentBits,
Guild,
Message,
PermissionFlagsBits,
TextChannel,
VoiceState
} from 'discord.js';

import Config from '~/config/Config';
import QueueItem from '~/queue/QueueItem';
Expand All @@ -24,27 +33,13 @@ export default class SoundBot extends Client {
messageHandler: MessageHandler,
queue: SoundQueue
) {
// | 'GUILDS'
// | 'GUILD_MEMBERS'
// | 'GUILD_BANS'
// | 'GUILD_EMOJIS_AND_STICKERS'
// | 'GUILD_INTEGRATIONS'
// | 'GUILD_WEBHOOKS'
// | 'GUILD_INVITES'
// | 'GUILD_VOICE_STATES'
// | 'GUILD_PRESENCES'
// | 'GUILD_MESSAGES'
// | 'GUILD_MESSAGE_REACTIONS'
// | 'GUILD_MESSAGE_TYPING'
// | 'DIRECT_MESSAGES'
// | 'DIRECT_MESSAGE_REACTIONS'
// | 'DIRECT_MESSAGE_TYPING'
// | 'MESSAGE_CONTENT'
// | 'GUILD_SCHEDULED_EVENTS'
// | 'AUTO_MODERATION_CONFIGURATION'
// | 'AUTO_MODERATION_EXECUTION';
super({
intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_VOICE_STATES', 'MESSAGE_CONTENT']
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.MessageContent
]
});

this.config = config;
Expand Down Expand Up @@ -124,11 +119,11 @@ export default class SoundBot extends Client {
if (!guild.members.me) return undefined;

const channels = guild.channels.cache
.filter(channel => channel.type === 'GUILD_TEXT')
.filter(channel => channel.type === ChannelType.GuildText)
.filter(channel => {
const permissions = channel.permissionsFor(guild.members.me!);

return Boolean(permissions && permissions.has('SEND_MESSAGES'));
return Boolean(permissions && permissions.has(PermissionFlagsBits.SendMessages));
});

if (!channels.size) return undefined;
Expand Down
8 changes: 4 additions & 4 deletions src/commands/config/AvatarCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export class AvatarCommand extends ConfigCommand implements UserCommand {
return;
}

this.user
.setAvatar(message.attachments.first()!.url)
.catch(() => message.channel.send(localize.t('commands.avatar.errors.tooFast')));
this.user.setAvatar(message.attachments.first()!.url).catch(() => {
message.channel.send(localize.t('commands.avatar.errors.tooFast'));
});
}

private listAvatar(message: Message) {
Expand All @@ -48,7 +48,7 @@ export class AvatarCommand extends ConfigCommand implements UserCommand {

message.channel.send(
localize.t('commands.avatar.url', {
url: this.user.displayAvatarURL({ dynamic: true, format: 'png', size: 256 })
url: this.user.displayAvatarURL({ size: 256 })
})
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/config/LanguageCommand.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Collection, Message, MessageEmbed } from 'discord.js';
import { Collection, EmbedBuilder, Message } from 'discord.js';

import localize from '~/util/i18n/localize';

Expand Down Expand Up @@ -38,7 +38,7 @@ export class LanguageCommand extends ConfigCommand {
}

private help() {
return new MessageEmbed()
return new EmbedBuilder()
.setColor('#0099ff')
.setTitle(localize.t('commands.lang.title'))
.setDescription(
Expand Down
6 changes: 3 additions & 3 deletions src/commands/manage/DownloadCommand.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Message, MessageAttachment } from 'discord.js';
import { AttachmentBuilder, Message } from 'discord.js';

import { existsSound, getPathForSound } from '~/util/SoundUtil';

Expand All @@ -18,7 +18,7 @@ export class DownloadCommand extends Command {
const sound = params[0];
if (!existsSound(sound)) return;

const attachment = new MessageAttachment(getPathForSound(sound));
message.channel.send({ attachments: [attachment] });
const attachment = new AttachmentBuilder(getPathForSound(sound));
message.channel.send({ files: [attachment] });
}
}
4 changes: 2 additions & 2 deletions src/commands/manage/add/downloader/AttachmentDownloader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Message, MessageAttachment } from 'discord.js';
import { Attachment, Message } from 'discord.js';
import fs from 'fs';
import { IncomingMessage } from 'http';
import https from 'https';
Expand Down Expand Up @@ -40,7 +40,7 @@ export default class AttachmentDownloader extends BaseDownloader {
}
}

private async fetchAndSaveSound(attachment: MessageAttachment) {
private async fetchAndSaveSound(attachment: Attachment) {
const response = await this.downloadFile(attachment.url);
this.saveResponseToFile(response, attachment.name!.toLowerCase());
}
Expand Down
6 changes: 3 additions & 3 deletions src/commands/manage/add/validator/AttachmentValidator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable max-classes-per-file */

import { MessageAttachment } from 'discord.js';
import { Attachment } from 'discord.js';

import Config from '~/config/Config';
import { AttachmentExtensionError, AttachmentSizeError } from '~/util/Errors';
Expand All @@ -15,11 +15,11 @@ export default class AttachmentValidator extends BaseValidator {
this.config = config;
}

public validate(attachment: MessageAttachment) {
public validate(attachment: Attachment) {
return this.validateAttachment(attachment);
}

private validateAttachment(attachment: MessageAttachment) {
private validateAttachment(attachment: Attachment) {
if (!attachment.name) throw new Error('Attachment without name :confused:');

const fileName = attachment.name.toLowerCase();
Expand Down
4 changes: 2 additions & 2 deletions src/commands/util/userHasElevatedRole.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { GuildMember, Permissions } from 'discord.js';
import { GuildMember, PermissionFlagsBits } from 'discord.js';

import { config } from '~/util/Container';

const userHasElevatedRole = (member: Nullable<GuildMember>) => {
if (!member) return false;
if (member.permissions.has(Permissions.FLAGS.ADMINISTRATOR)) return true;
if (member.permissions.has(PermissionFlagsBits.Administrator)) return true;

return member.roles.cache.some(role => config.elevatedRoles.includes(role.name));
};
Expand Down
4 changes: 2 additions & 2 deletions src/discord/Message.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Message } from 'discord.js';
import { ChannelType, Message } from 'discord.js';

declare module 'discord.js' {
// NOTE: Monkeypatching
Expand All @@ -14,5 +14,5 @@ Message.prototype.hasPrefix = function hasPrefix(prefix) {
};

Message.prototype.isDirectMessage = function isDirectMessage() {
return this.channel.type === 'DM';
return this.channel.type === ChannelType.DM;
};
2 changes: 1 addition & 1 deletion src/queue/SoundQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export default class SoundQueue {
private wasMessageAlreadyDeleted(message: Message) {
if (!message) return false;

return message.channel.messages.cache.find(msg => msg.id === message.id) === null;
return !message.channel.messages.cache.has(message.id);
}

private isLastSoundFromCurrentMessage(message: Message) {
Expand Down
Loading

0 comments on commit e7eebd9

Please sign in to comment.