Skip to content

Commit

Permalink
fix: use enums from discord-api-types (#7258)
Browse files Browse the repository at this point in the history
  • Loading branch information
almeidx committed Jan 13, 2022
1 parent 37ec0bd commit f284a46
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 23 deletions.
3 changes: 2 additions & 1 deletion packages/discord.js/src/managers/GuildInviteManager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const { Collection } = require('@discordjs/collection');
const { InviteTargetType } = require('discord-api-types/v9');
const CachedManager = require('./CachedManager');
const { Error } = require('../errors');
const Invite = require('../structures/Invite');
Expand Down Expand Up @@ -190,7 +191,7 @@ class GuildInviteManager extends CachedManager {
unique,
target_user_id: this.client.users.resolveId(targetUser),
target_application_id: targetApplication?.id ?? targetApplication?.applicationId ?? targetApplication,
target_type: targetType,
target_type: InviteTargetType[targetType],
},
reason,
});
Expand Down
6 changes: 3 additions & 3 deletions packages/discord.js/src/structures/BaseGuildTextChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ class BaseGuildTextChannel extends GuildChannel {
* @property {number} [maxUses=0] Maximum number of uses
* @property {boolean} [unique=false] Create a unique invite, or use an existing one with similar settings
* @property {UserResolvable} [targetUser] The user whose stream to display for this invite,
* required if `targetType` is 1, the user must be streaming in the channel
* required if `targetType` is `STREAM`, the user must be streaming in the channel
* @property {ApplicationResolvable} [targetApplication] The embedded application to open for this invite,
* required if `targetType` is 2, the application must have the `EMBEDDED` flag
* @property {TargetType} [targetType] The type of the target for this voice channel invite
* required if `targetType` is `EMBEDDED_APPLICATION`, the application must have the `EMBEDDED` flag
* @property {InviteTargetType} [targetType] The type of the target for this voice channel invite
* @property {string} [reason] The reason for creating the invite
*/

Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/src/structures/CommandInteraction.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { Collection } = require('@discordjs/collection');
const { ApplicationCommandType } = require('discord-api-types/v9');
const { ApplicationCommandOptionType } = require('discord-api-types/v9');
const Interaction = require('./Interaction');
const InteractionWebhook = require('./InteractionWebhook');
const InteractionResponses = require('./interfaces/InteractionResponses');
Expand Down Expand Up @@ -151,7 +151,7 @@ class CommandInteraction extends Interaction {
transformOption(option, resolved) {
const result = {
name: option.name,
type: ApplicationCommandType[option.type],
type: ApplicationCommandOptionType[option.type],
};

if ('value' in option) result.value = option.value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { ApplicationCommandType } = require('discord-api-types/v9');
const { ApplicationCommandType, ApplicationCommandOptionType } = require('discord-api-types/v9');
const CommandInteraction = require('./CommandInteraction');
const CommandInteractionOptionResolver = require('./CommandInteractionOptionResolver');

Expand Down Expand Up @@ -45,7 +45,7 @@ class ContextMenuCommandInteraction extends CommandInteraction {

if (resolved.users?.[target_id]) {
result.push(
this.transformOption({ name: 'user', type: ApplicationCommandType.User, value: target_id }, resolved),
this.transformOption({ name: 'user', type: ApplicationCommandOptionType.User, value: target_id }, resolved),
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class Guild extends AnonymousGuild {
if ('premium_tier' in data) {
/**
* The premium tier of this guild
* @type {PremiumTier}
* @type {GuildPremiumTier}
*/
this.premiumTier = GuildPremiumTier[data.premium_tier];
}
Expand Down
13 changes: 3 additions & 10 deletions packages/discord.js/src/structures/Invite.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const { InviteTargetType } = require('discord-api-types/v9');
const Base = require('./Base');
const { GuildScheduledEvent } = require('./GuildScheduledEvent');
const IntegrationApplication = require('./IntegrationApplication');
Expand Down Expand Up @@ -151,20 +152,12 @@ class Invite extends Base {
this.targetApplication ??= null;
}

/**
* The type of the invite target:
* * 1: STREAM
* * 2: EMBEDDED_APPLICATION
* @typedef {number} TargetType
* @see {@link https://discord.com/developers/docs/resources/invite#invite-object-invite-target-types}
*/

if ('target_type' in data) {
/**
* The target type
* @type {?TargetType}
* @type {?InviteTargetType}
*/
this.targetType = data.target_type;
this.targetType = InviteTargetType[data.target_type];
} else {
this.targetType ??= null;
}
Expand Down
12 changes: 8 additions & 4 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3323,9 +3323,13 @@ export type AllowedImageSize = 16 | 32 | 56 | 64 | 96 | 128 | 256 | 300 | 512 |

export type AllowedPartial = User | Channel | GuildMember | Message | MessageReaction;

export type AllowedThreadTypeForNewsChannel = 'GUILD_NEWS_THREAD' | 10;
export type AllowedThreadTypeForNewsChannel = 'GUILD_NEWS_THREAD' | ChannelType.GuildNewsThread;

export type AllowedThreadTypeForTextChannel = 'GUILD_PUBLIC_THREAD' | 'GUILD_PRIVATE_THREAD' | 11 | 12;
export type AllowedThreadTypeForTextChannel =
| 'GUILD_PUBLIC_THREAD'
| 'GUILD_PRIVATE_THREAD'
| ChannelType.GuildPublicThread
| ChannelType.GuildPrivateThread;

export interface APIRequest {
method: 'get' | 'post' | 'delete' | 'patch' | 'put';
Expand Down Expand Up @@ -4214,7 +4218,7 @@ interface GuildAuditLogsTypes {
ChannelDelete: ['Channel', 'Delete'];
ChannelOverwriteCreate: ['Channel', 'Create'];
ChannelOverwriteUpdate: ['Channel', 'Update'];
ChannelOverwriteDelete: ['CHANNEL', 'Delete'];
ChannelOverwriteDelete: ['Channel', 'Delete'];
MemberKick: ['User', 'Delete'];
MemberPrune: ['User', 'Delete'];
MemberBanAdd: ['User', 'Delete'];
Expand Down Expand Up @@ -5345,7 +5349,7 @@ export type ThreadChannelTypeKey = 'GuildNewsThread' | 'GuildPublicThread' | 'Gu
export interface ThreadCreateOptions<AllowedThreadType> extends StartThreadOptions {
startMessage?: MessageResolvable;
type?: AllowedThreadType;
invitable?: AllowedThreadType extends 'GUILD_PRIVATE_THREAD' | 12 ? boolean : never;
invitable?: AllowedThreadType extends 'GUILD_PRIVATE_THREAD' | ChannelType.GuildPrivateThread ? boolean : never;
rateLimitPerUser?: number;
}

Expand Down

0 comments on commit f284a46

Please sign in to comment.