Skip to content

Commit 78aba15

Browse files
committed
feat: support for djs v14
1 parent 3a6df4a commit 78aba15

16 files changed

+95
-333
lines changed

package-lock.json

+56-254
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gcommands",
3-
"version": "9.3.0",
3+
"version": "10.0.0",
44
"description": "Powerful and flexible framework!",
55
"main": "dist/index.js",
66
"module": "dist/index.mjs",
@@ -49,7 +49,6 @@
4949
"license": "ISC",
5050
"dependencies": {
5151
"@discordjs/rest": "^1.0.0",
52-
"discord-api-types": "^0.30.0",
5352
"ms": "^2.1.3",
5453
"tslib": "^2.3.1",
5554
"zod": "^3.11.6"
@@ -68,7 +67,7 @@
6867
"@typescript-eslint/eslint-plugin": "5.31.0",
6968
"@typescript-eslint/parser": "5.31.0",
7069
"conventional-changelog-cli": "2.2.2",
71-
"discord.js": "13.9.1",
70+
"discord.js": "^14.0.3",
7271
"eslint": "8.20.0",
7372
"eslint-config-prettier": "8.5.0",
7473
"eslint-plugin-import": "2.26.0",

src/handlers/ComponentHandler.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { setTimeout } from 'node:timers';
2-
import { Collection, MessageComponentInteraction } from 'discord.js';
2+
import { Collection, InteractionType, MessageComponentInteraction, ModalSubmitInteraction } from 'discord.js';
33
import { AutoDeferType, GClient } from '../lib/GClient';
44
import { Components } from '../lib/managers/ComponentManager';
55
import { Handlers } from '../lib/managers/HandlerManager';
@@ -11,7 +11,7 @@ import { Events, Logger } from '../lib/util/logger/Logger';
1111
const cooldowns = new Collection<string, Collection<string, number>>();
1212

1313
export async function ComponentHandler(
14-
interaction: MessageComponentInteraction,
14+
interaction: MessageComponentInteraction | ModalSubmitInteraction,
1515
) {
1616
const client = interaction.client as GClient;
1717

@@ -66,9 +66,9 @@ export async function ComponentHandler(
6666
customId: interaction.customId,
6767
arguments: args,
6868
values: interaction.isSelectMenu() ? interaction.values : undefined,
69-
fields: interaction.isModalSubmit() ? interaction.fields : undefined,
69+
fields: interaction.type === InteractionType.ModalSubmit ? interaction.fields : undefined,
7070
deferReply: interaction.deferReply.bind(interaction),
71-
deferUpdate: interaction.deferUpdate.bind(interaction),
71+
deferUpdate: interaction.type !== InteractionType.ModalSubmit ? interaction.deferUpdate.bind(interaction): () => { throw new Error('Cannot defer update in modal submit interaction'); },
7272
deleteReply: interaction.deleteReply.bind(interaction),
7373
editReply: interaction.editReply.bind(interaction),
7474
fetchReply: interaction.fetchReply.bind(interaction),

src/handlers/InteractionCommandHandler.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { setTimeout } from 'node:timers';
22
import {
33
Collection,
44
CommandInteraction,
5-
ContextMenuInteraction,
5+
ContextMenuCommandInteraction,
66
} from 'discord.js';
77
import { AutoDeferType, GClient } from '../lib/GClient';
88
import { Commands } from '../lib/managers/CommandManager';
@@ -14,7 +14,7 @@ import { Events, Logger } from '../lib/util/logger/Logger';
1414
const cooldowns = new Collection<string, Collection<string, number>>();
1515

1616
export async function InteractionCommandHandler(
17-
interaction: CommandInteraction | ContextMenuInteraction,
17+
interaction: CommandInteraction | ContextMenuCommandInteraction,
1818
) {
1919
const client = interaction.client as GClient;
2020

src/handlers/MessageCommandHandler.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import {
44
CommandInteractionOptionResolver,
55
Guild,
66
Message,
7-
MessageAttachment,
87
MessagePayload,
98
ReplyMessageOptions,
109
SelectMenuInteraction,
1110
TextChannel,
1211
User,
12+
ComponentType,
13+
Attachment,
1314
} from 'discord.js';
1415
import type { GClient } from '../lib/GClient';
1516
import { Commands } from '../lib/managers/CommandManager';
@@ -30,7 +31,7 @@ const cooldowns = new Collection<string, Collection<string, number>>();
3031

3132
const checkValidation = async (
3233
arg: MessageArgumentTypes,
33-
content: string | MessageAttachment,
34+
content: string | Attachment,
3435
client: Client,
3536
guild: Guild,
3637
argument: Argument,
@@ -75,7 +76,7 @@ const checkValidation = async (
7576
const component: SelectMenuInteraction =
7677
(await channel.awaitMessageComponent({
7778
filter: m =>
78-
m.componentType === 'SELECT_MENU' &&
79+
m.componentType === ComponentType.SelectMenu &&
7980
m.user.id === user.id &&
8081
m.channelId === channel.id &&
8182
m.message.id === message.id &&

src/lib/managers/HandlerManager.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type {
22
AutocompleteInteraction,
33
Collection,
44
CommandInteraction,
5-
ContextMenuInteraction,
5+
ContextMenuCommandInteraction,
66
Message,
77
MessageComponentInteraction,
88
ModalSubmitInteraction,
@@ -17,7 +17,7 @@ import type { Component } from '../structures/Component';
1717

1818
export class HandlerManager {
1919
public interactionCommandHandler: (
20-
interaction: CommandInteraction | ContextMenuInteraction,
20+
interaction: CommandInteraction | ContextMenuCommandInteraction,
2121
) => any;
2222
public messageCommandHandler: (
2323
message: Message,
@@ -43,7 +43,7 @@ export class HandlerManager {
4343
}
4444

4545
public setInteractionCommandHandler(
46-
handler: (interaction: CommandInteraction | ContextMenuInteraction) => any,
46+
handler: (interaction: CommandInteraction | ContextMenuCommandInteraction) => any,
4747
): HandlerManager {
4848
this.interactionCommandHandler = handler;
4949

src/lib/managers/ListenerManager.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ClientEvents, Collection, WSEventType } from 'discord.js';
1+
import { ClientEvents, Collection, GatewayDispatchEvents } from 'discord.js';
22
import { Plugins } from './PluginManager';
33
import type { GClient } from '../GClient';
44
import { Listener } from '../structures/Listener';
@@ -42,7 +42,7 @@ export class ListenerManager extends Collection<string, Listener> {
4242
if (maxListeners !== 0) this.client.setMaxListeners(maxListeners - 1);
4343

4444
listener.ws
45-
? this.client.ws.off(listener.event as WSEventType, listener._run)
45+
? this.client.ws.off(listener.event as GatewayDispatchEvents, listener._run)
4646
: this.client.off(
4747
listener.event as keyof ClientEvents,
4848
listener._run,

src/lib/structures/Argument.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import type { ApplicationCommandOptionType } from 'discord-api-types/v9';
1+
import { ApplicationCommandOptionType, Locale, LocaleString } from 'discord.js';
22
import { z } from 'zod';
33
import type { AutocompleteContext } from './contexts/AutocompleteContext';
4-
import { Locale, LocaleString } from '../util/common';
54
import { Logger } from '../util/logger/Logger';
65
import { commandAndOptionNameRegexp } from '../util/regexes';
76

src/lib/structures/Command.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import { Argument, ArgumentOptions } from './Argument';
33
import type { CommandContext } from './contexts/CommandContext';
44
import { AutoDeferType, GClient } from '../GClient';
55
import { Commands } from '../managers/CommandManager';
6-
import { Locale, LocaleString } from '../util/common';
76
import { Logger } from '../util/logger/Logger';
87
import { commandAndOptionNameRegexp } from '../util/regexes';
9-
import { PermissionResolvable, Permissions } from 'discord.js';
8+
import { PermissionResolvable, PermissionsBitField, Locale, LocaleString } from 'discord.js';
109
import { Util } from '../util/Util';
1110

1211
export enum CommandType {
@@ -221,7 +220,7 @@ export class Command {
221220
description_localizations: this.descriptionLocalizations,
222221
dm_permission: this.dmPermission,
223222
default_member_permissions: this.defaultMemberPermissions
224-
? new Permissions(
223+
? new PermissionsBitField(
225224
this.defaultMemberPermissions,
226225
).bitfield.toString()
227226
: null,

src/lib/structures/Listener.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import type { ClientEvents, WSEventType } from 'discord.js';
1+
import type { ClientEvents, GatewayDispatchEvents } from 'discord.js';
22
import { z } from 'zod';
33
import type { GClient } from '../GClient';
44
import { Listeners } from '../managers/ListenerManager';
55
import { Logger } from '../util/logger/Logger';
66

77
export interface ListenerOptions<
88
WS extends boolean,
9-
Event extends WS extends true ? WSEventType : keyof ClientEvents,
9+
Event extends WS extends true ? GatewayDispatchEvents : keyof ClientEvents,
1010
> {
1111
event: Event | string;
1212
name: string;
@@ -32,8 +32,8 @@ const validationSchema = z
3232
export class Listener<
3333
WS extends boolean = boolean,
3434
Event extends WS extends true
35-
? WSEventType
36-
: keyof ClientEvents = WS extends true ? WSEventType : keyof ClientEvents,
35+
? GatewayDispatchEvents
36+
: keyof ClientEvents = WS extends true ? GatewayDispatchEvents : keyof ClientEvents,
3737
> {
3838
public client: GClient;
3939
public event: Event | string;
@@ -77,7 +77,7 @@ export class Listener<
7777

7878
if (this.ws)
7979
client.ws[this.once ? 'once' : 'on'](
80-
this.event as WSEventType,
80+
this.event as GatewayDispatchEvents,
8181
this._run.bind(this),
8282
);
8383
else

src/lib/structures/arguments/Attachment.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { MessageAttachment } from 'discord.js';
1+
import { Attachment } from 'discord.js';
22
import { MessageArgumentTypeBase } from './base';
33
import { Argument, ArgumentType } from '../Argument';
44

55
export class AttachmentType extends MessageArgumentTypeBase {
66
value;
77

8-
validate(attachment: string | MessageAttachment) {
9-
if (attachment instanceof MessageAttachment) {
8+
validate(attachment: string | Attachment) {
9+
if (attachment instanceof Attachment) {
1010
this.value = attachment;
1111
return true;
1212
}

src/lib/structures/contexts/CommandContext.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type {
22
CacheType,
33
CommandInteraction,
44
CommandInteractionOptionResolver,
5-
ContextMenuInteraction,
5+
ContextMenuCommandInteraction,
66
GuildCacheMessage,
77
InteractionDeferReplyOptions,
88
InteractionReplyOptions,
@@ -16,7 +16,7 @@ import type { Command } from '../Command';
1616

1717
export interface CommandContextOptions<Cached extends CacheType = CacheType>
1818
extends ContextOptions<Cached> {
19-
interaction?: CommandInteraction | ContextMenuInteraction;
19+
interaction?: CommandInteraction | ContextMenuCommandInteraction;
2020
message?: Message;
2121
command: Command;
2222
arguments: CommandInteractionOptionResolver<Cached>;
@@ -44,7 +44,7 @@ export class CommandContext<
4444
Cached extends CacheType = CacheType,
4545
> extends Context<Cached> {
4646
[key: string]: any;
47-
public interaction?: CommandInteraction | ContextMenuInteraction;
47+
public interaction?: CommandInteraction | ContextMenuCommandInteraction;
4848
public message?: Message;
4949
public readonly command: Command;
5050
public readonly commandName: string;

src/lib/structures/contexts/ComponentContext.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
InteractionReplyOptions,
77
MessageComponentInteraction,
88
MessagePayload,
9-
ModalSubmitFieldsResolver,
9+
ModalSubmitFields,
1010
ModalSubmitInteraction,
1111
WebhookEditMessageOptions,
1212
} from 'discord.js';
@@ -21,7 +21,7 @@ export interface ComponentContextOptions<Cached extends CacheType = CacheType>
2121
customId: string;
2222
arguments: Array<string>;
2323
values?: Array<string>;
24-
fields?: ModalSubmitFieldsResolver;
24+
fields?: ModalSubmitFields;
2525
deferReply: <Fetch extends boolean = boolean>(
2626
options?: InteractionDeferReplyOptions & { fetchReply?: Fetch },
2727
) => Promise<Fetch extends true ? GuildCacheMessage<Cached> : void>;
@@ -55,7 +55,7 @@ export class ComponentContext<
5555
public readonly customId: string;
5656
public arguments: Array<string>;
5757
public values?: Array<string>;
58-
public fields?: ModalSubmitFieldsResolver;
58+
public fields?: ModalSubmitFields;
5959
public deferred = false;
6060
public replied = false;
6161
public deferReply: <Fetch extends boolean = boolean>(

src/lib/structures/contexts/Context.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {
44
Guild,
55
GuildMember,
66
GuildTextBasedChannel,
7-
Permissions,
7+
PermissionsBitField,
88
Snowflake,
99
TextBasedChannel,
1010
User,
@@ -13,7 +13,7 @@ import type { AutocompleteContext } from './AutocompleteContext';
1313
import type { CommandContext } from './CommandContext';
1414
import type { ComponentContext } from './ComponentContext';
1515
import type { GClient } from '../../GClient';
16-
import type { APIInteractionGuildMember } from 'discord-api-types/v9';
16+
import type { APIInteractionGuildMember } from 'discord.js';
1717

1818
export interface ContextOptions<Cached extends CacheType = CacheType> {
1919
channel: CacheTypeReducer<
@@ -28,7 +28,7 @@ export interface ContextOptions<Cached extends CacheType = CacheType> {
2828
guild: CacheTypeReducer<Cached, Guild, null>;
2929
guildId: CacheTypeReducer<Cached, Snowflake>;
3030
member: CacheTypeReducer<Cached, GuildMember, APIInteractionGuildMember>;
31-
memberPermissions: CacheTypeReducer<Cached, Readonly<Permissions>>;
31+
memberPermissions: CacheTypeReducer<Cached, Readonly<PermissionsBitField>>;
3232
user: User;
3333
}
3434

@@ -54,7 +54,7 @@ export class Context<Cached extends CacheType = CacheType> {
5454
>;
5555
public user: User;
5656
public userId: Snowflake;
57-
public memberPermissions: CacheTypeReducer<Cached, Readonly<Permissions>>;
57+
public memberPermissions: CacheTypeReducer<Cached, Readonly<PermissionsBitField>>;
5858
public type: 'COMMAND' | 'BUTTON' | 'SELECT_MENU' | 'AUTOCOMPLETE';
5959

6060
constructor(client: GClient, options: ContextOptions<Cached>) {

src/lib/util/common.ts

-38
This file was deleted.

src/lib/util/sync.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { setTimeout } from 'node:timers';
22
import { REST } from '@discordjs/rest';
3-
import { Routes } from 'discord-api-types/v9';
3+
import { Routes } from 'discord.js';
44
import { Logger } from './logger/Logger';
55
import type { GClient } from '../GClient';
66
import { Commands } from '../managers/CommandManager';

0 commit comments

Comments
 (0)