import type { ChildProcess } from 'node:child_process'; import type { Worker } from 'node:worker_threads'; import { APIInteractionGuildMember, APIPartialChannel, APIPartialGuild, APIInteractionDataResolvedGuildMember, APIInteractionDataResolvedChannel, APIRole, APIButtonComponent, APISelectMenuComponent, ApplicationCommandOptionType, ComponentType, ApplicationCommandPermissionType, ChannelType, InteractionType, GatewayIntentBits, Locale, PermissionFlagsBits, AuditLogEvent, ButtonStyle, TextInputStyle, APITextInputComponent, APIEmbed, ApplicationCommandType, APIMessage, APIActionRowComponent, APIActionRowComponentTypes, APIStringSelectComponent, } from 'discord-api-types/v10'; import { ApplicationCommand, ApplicationCommandData, ApplicationCommandManager, ApplicationCommandOptionData, ApplicationCommandResolvable, ApplicationCommandSubCommandData, ApplicationCommandSubGroupData, CommandInteraction, ButtonInteraction, CacheType, CategoryChannel, Client, ClientApplication, ClientUser, CloseEvent, Collection, ChatInputCommandInteraction, CommandInteractionOption, CommandInteractionOptionResolver, CommandOptionNonChoiceResolvableType, ContextMenuCommandInteraction, DMChannel, Guild, GuildApplicationCommandManager, GuildChannelManager, GuildEmoji, GuildEmojiManager, GuildMember, GuildResolvable, IntentsBitField, Interaction, InteractionCollector, Message, AttachmentBuilder, MessageCollector, MessageComponentInteraction, MessageReaction, ModalBuilder, NewsChannel, Options, PartialTextBasedChannelFields, PartialUser, PermissionsBitField, ReactionCollector, Role, RoleManager, Serialized, ShardClientUtil, ShardingManager, Snowflake, StageChannel, TextBasedChannelFields, TextBasedChannel, TextBasedChannelTypes, VoiceBasedChannel, GuildBasedChannel, NonThreadGuildBasedChannel, GuildTextBasedChannel, TextChannel, ThreadChannel, ThreadMember, Typing, User, VoiceChannel, Shard, WebSocketShard, Collector, GuildAuditLogsEntry, GuildAuditLogs, StageInstance, ActionRowBuilder, ButtonComponent, SelectMenuComponent, RepliableInteraction, ThreadChannelType, Events, WebSocketShardEvents, Status, CategoryChannelChildManager, ActionRowData, MessageActionRowComponentData, PartialThreadMember, ThreadMemberFlagsBitField, ButtonBuilder, EmbedBuilder, MessageActionRowComponent, StringSelectMenuBuilder, TextInputBuilder, TextInputComponent, Embed, MessageActionRowComponentBuilder, GuildBanManager, GuildBan, MessageManager, ChannelMention, UserMention, PartialGroupDMChannel, Attachment, MessageContextMenuCommandInteraction, UserContextMenuCommandInteraction, AnyThreadChannel, ThreadMemberManager, CollectedMessageInteraction, ShardEvents, Webhook, WebhookClient, InteractionWebhook, ActionRowComponent, ActionRow, GuildAuditLogsActionType, GuildAuditLogsTargetType, ModalSubmitInteraction, ForumChannel, ChannelFlagsBitField, GuildForumThreadManager, GuildTextThreadManager, AnySelectMenuInteraction, StringSelectMenuInteraction, StringSelectMenuComponent, UserSelectMenuInteraction, RoleSelectMenuInteraction, ChannelSelectMenuInteraction, MentionableSelectMenuInteraction, MessageMentions, AutoModerationActionExecution, AutoModerationRule, AutoModerationRuleManager, PrivateThreadChannel, PublicThreadChannel, GuildMemberManager, GuildMemberFlagsBitField, ThreadManager, FetchedThreads, FetchedThreadsMore, DMMessageManager, GuildMessageManager, ApplicationCommandChannelOptionData, ApplicationCommandChannelOption, ApplicationCommandChoicesOption, ApplicationCommandChoicesData, ApplicationCommandSubGroup, ApplicationCommandSubCommand, ChatInputApplicationCommandData, ApplicationCommandPermissionsManager, GuildOnboarding, StringSelectMenuComponentData, ButtonComponentData, } from '.'; import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd'; import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders'; // Test type transformation: declare const serialize: (value: T) => Serialized; declare const notPropertyOf: (value: T, property: P & Exclude) => void; const client: Client = new Client({ intents: GatewayIntentBits.Guilds, makeCache: Options.cacheWithLimits({ MessageManager: 200, // @ts-expect-error Message: 100, GuildMemberManager: { maxSize: 200, keepOverLimit: member => member.id === client.user?.id, }, }), }); const testGuildId = '222078108977594368'; // DJS const testUserId = '987654321098765432'; // example id const globalCommandId = '123456789012345678'; // example id const guildCommandId = '234567890123456789'; // example id client.on('autoModerationActionExecution', autoModerationActionExecution => expectType(autoModerationActionExecution), ); client.on('autoModerationRuleCreate', ({ client }) => expectType>(client)); client.on('autoModerationRuleDelete', ({ client }) => expectType>(client)); client.on('autoModerationRuleUpdate', (oldAutoModerationRule, { client: newClient }) => { expectType>(oldAutoModerationRule!.client); expectType>(newClient); }); client.on('channelCreate', ({ client }) => expectType>(client)); client.on('channelDelete', ({ client }) => expectType>(client)); client.on('channelPinsUpdate', ({ client }) => expectType>(client)); client.on('channelUpdate', ({ client: oldClient }, { client: newClient }) => { expectType>(oldClient); expectType>(newClient); }); client.on('emojiCreate', ({ client }) => expectType>(client)); client.on('emojiDelete', ({ client }) => expectType>(client)); client.on('emojiUpdate', ({ client: oldClient }, { client: newClient }) => { expectType>(oldClient); expectType>(newClient); }); client.on('guildBanAdd', ({ client }) => expectType>(client)); client.on('guildBanRemove', ({ client }) => expectType>(client)); client.on('guildDelete', ({ client }) => expectType>(client)); client.on('guildIntegrationsUpdate', ({ client }) => expectType>(client)); client.on('guildMemberAdd', ({ client }) => expectType>(client)); client.on('guildMemberAvailable', ({ client }) => expectType>(client)); client.on('guildMemberRemove', member => { expectType>(member.client); if (member.partial) return expectType(member.joinedAt); expectType(member.joinedAt); }); client.on('guildMembersChunk', (members, { client }) => { expectType>(members.first()!.client); expectType>(client); }); client.on('guildMemberUpdate', ({ client: oldClient }, { client: newClient }) => { expectType>(oldClient); expectType>(newClient); }); client.on('guildScheduledEventCreate', ({ client }) => expectType>(client)); client.on('guildScheduledEventDelete', ({ client }) => expectType>(client)); client.on('guildScheduledEventUpdate', (oldGuildScheduledEvent, { client }) => { expectType>(oldGuildScheduledEvent!.client); expectType>(client); }); client.on('guildScheduledEventUserAdd', ({ client: oldClient }, { client: newClient }) => { expectType>(oldClient); expectType>(newClient); }); client.on('guildScheduledEventUserRemove', ({ client: oldClient }, { client: newClient }) => { expectType>(oldClient); expectType>(newClient); }); client.on('guildUnavailable', ({ client }) => expectType>(client)); client.on('guildUpdate', ({ client: oldClient }, { client: newClient }) => { expectType>(oldClient); expectType>(newClient); }); client.on('interactionCreate', async interaction => { expectType>(interaction.client); expectType(interaction.guildId); expectType(interaction.channelId); expectType(interaction.member); if (interaction.type === InteractionType.MessageComponent) { expectType(interaction.channelId); } if (interaction.type !== InteractionType.ApplicationCommand) return; void new ActionRowBuilder(); const button = new ButtonBuilder(); const actionRow = new ActionRowBuilder({ type: ComponentType.ActionRow, components: [button.toJSON()], }); actionRow.toJSON(); await interaction.reply({ content: 'Hi!', components: [actionRow] }); // @ts-expect-error interaction.reply({ content: 'Hi!', components: [[button]] }); void new ActionRowBuilder({}); // @ts-expect-error await interaction.reply({ content: 'Hi!', components: [button] }); await interaction.reply({ content: 'test', components: [ { components: [ { custom_id: 'abc', label: 'abc', style: ButtonStyle.Primary, type: ComponentType.Button, }, ], type: ComponentType.ActionRow, }, ], }); // This is for testing never type resolution if (!interaction.inGuild()) { return; } if (interaction.inRawGuild()) { expectNotType(interaction); return; } if (interaction.inCachedGuild()) { expectNotType(interaction); return; } }); client.on('inviteCreate', ({ client }) => expectType>(client)); client.on('inviteDelete', ({ client }) => expectType>(client)); // This is to check that stuff is the right type declare const assertIsMessage: (m: Promise) => void; client.on('messageCreate', async message => { const { client, channel } = message; // https://github.com/discordjs/discord.js/issues/8545 { // These should not throw any errors when comparing messages from any source. channel.messages.cache.filter(m => m); (await channel.messages.fetch()).filter(m => m.author.id === message.author.id); if (channel.isDMBased()) { expectType(channel.messages.channel.messages); } else { expectType(channel.messages.channel.messages); } } if (!message.inGuild() && message.partial) { expectNotType(message); } expectType>(client); assertIsMessage(channel.send('string')); assertIsMessage(channel.send({})); assertIsMessage(channel.send({ embeds: [] })); const attachment = new AttachmentBuilder('file.png'); const embed = new EmbedBuilder(); assertIsMessage(channel.send({ files: [attachment] })); assertIsMessage(channel.send({ embeds: [embed] })); assertIsMessage(channel.send({ embeds: [embed], files: [attachment] })); if (message.inGuild()) { expectAssignable>(message); const component = await message.awaitMessageComponent({ componentType: ComponentType.Button }); expectType>(component); expectType>(await component.reply({ fetchReply: true })); const buttonCollector = message.createMessageComponentCollector({ componentType: ComponentType.Button }); expectType>>(buttonCollector); expectAssignable< ( test: ButtonInteraction<'cached'>, items: Collection>, ) => boolean | Promise >(buttonCollector.filter); expectType(message.channel); expectType(message.guild); expectType(message.member); expectType>(message.mentions); expectType(message.guild); expectType>(message.mentions.members); } expectType(message.channel); expectNotType(message.channel); // @ts-expect-error channel.send(); // @ts-expect-error channel.send({ another: 'property' }); // Check collector creations. // Verify that buttons interactions are inferred. const buttonCollector = message.createMessageComponentCollector({ componentType: ComponentType.Button }); expectAssignable>(message.awaitMessageComponent({ componentType: ComponentType.Button })); expectAssignable>(channel.awaitMessageComponent({ componentType: ComponentType.Button })); expectAssignable>(buttonCollector); // Verify that select menus interaction are inferred. const selectMenuCollector = message.createMessageComponentCollector({ componentType: ComponentType.StringSelect }); expectAssignable>( message.awaitMessageComponent({ componentType: ComponentType.StringSelect }), ); expectAssignable>( channel.awaitMessageComponent({ componentType: ComponentType.StringSelect }), ); expectAssignable>(selectMenuCollector); // Verify that message component interactions are default collected types. const defaultCollector = message.createMessageComponentCollector(); expectAssignable>(message.awaitMessageComponent()); expectAssignable>(channel.awaitMessageComponent()); expectAssignable>(defaultCollector); // Verify that additional options don't affect default collector types. const semiDefaultCollector = message.createMessageComponentCollector({ time: 10000 }); expectType>(semiDefaultCollector); const semiDefaultCollectorChannel = message.createMessageComponentCollector({ time: 10000 }); expectType>(semiDefaultCollectorChannel); // Verify that interaction collector options can't be used. message.createMessageComponentCollector({ // @ts-expect-error interactionType: InteractionType.ApplicationCommand, }); // Make sure filter parameters are properly inferred. message.createMessageComponentCollector({ filter: i => { expectType(i); return true; }, }); message.createMessageComponentCollector({ componentType: ComponentType.Button, filter: i => { expectType(i); return true; }, }); message.createMessageComponentCollector({ componentType: ComponentType.StringSelect, filter: i => { expectType(i); return true; }, }); message.awaitMessageComponent({ filter: i => { expectType(i); return true; }, }); message.awaitMessageComponent({ componentType: ComponentType.Button, filter: i => { expectType(i); return true; }, }); message.awaitMessageComponent({ componentType: ComponentType.StringSelect, filter: i => { expectType(i); return true; }, }); const webhook = await message.fetchWebhook(); if (webhook.isChannelFollower()) { expectAssignable(webhook.sourceGuild); expectAssignable(webhook.sourceChannel); } else if (webhook.isIncoming()) { expectType(webhook.token); } expectNotType(webhook.sourceGuild); expectNotType(webhook.sourceChannel); expectNotType(webhook.token); channel.awaitMessageComponent({ filter: i => { expectType>(i); return true; }, }); channel.awaitMessageComponent({ componentType: ComponentType.Button, filter: i => { expectType>(i); return true; }, }); channel.awaitMessageComponent({ componentType: ComponentType.StringSelect, filter: i => { expectType>(i); return true; }, }); // Check that both builders and builder data can be sent in messages const row = new ActionRowBuilder(); const rawButtonsRow: ActionRowData = { type: ComponentType.ActionRow, components: [ { type: ComponentType.Button, label: 'test', style: ButtonStyle.Primary, customId: 'test' }, { type: ComponentType.Button, label: 'another test', style: ButtonStyle.Link, url: 'https://discord.js.org', }, ], }; const buttonsRow: ActionRowData = { type: ComponentType.ActionRow, components: [new ButtonBuilder()], }; const rawStringSelectMenuRow: ActionRowData = { type: ComponentType.ActionRow, components: [ { type: ComponentType.StringSelect, options: [{ label: 'test', value: 'test' }], customId: 'test', }, ], }; const stringSelectRow: ActionRowData = { type: ComponentType.ActionRow, components: [new StringSelectMenuBuilder()], }; const embedData = { description: 'test', color: 0xff0000 }; channel.send({ components: [row, rawButtonsRow, buttonsRow, rawStringSelectMenuRow, stringSelectRow], embeds: [embed, embedData], }); }); client.on('messageDelete', ({ client }) => expectType>(client)); client.on('messageDeleteBulk', (messages, { client }) => { expectType>(messages.first()!.client); expectType>(client); }); client.on('messageReactionAdd', async (reaction, { client }) => { expectType>(reaction.client); expectType>(client); if (reaction.partial) { expectType(reaction.count); reaction = await reaction.fetch(); } expectType(reaction.count); if (reaction.message.partial) return expectType(reaction.message.content); expectType(reaction.message.content); }); client.on('messageReactionRemove', ({ client: oldClient }, { client: newClient }) => { expectType>(oldClient); expectType>(newClient); }); client.on('messageReactionRemoveAll', async (message, reactions) => { console.log(`messageReactionRemoveAll - id: ${message.id} (${message.id.length})`); if (message.partial) message = await message.fetch(); console.log(`messageReactionRemoveAll - content: ${message.content}`); expectType>(message.client); expectType>(reactions.first()!.client); }); client.on('messageReactionRemoveEmoji', ({ client }) => expectType>(client)); client.on('messageUpdate', ({ client: oldClient }, { client: newClient }) => { expectType>(oldClient); expectType>(newClient); }); client.on('presenceUpdate', (oldPresence, { client }) => { expectType>(oldPresence!.client); expectType>(client); }); declare const slashCommandBuilder: SlashCommandBuilder; declare const contextMenuCommandBuilder: ContextMenuCommandBuilder; client.on('ready', async client => { expectType>(client); console.log(`Client is logged in as ${client.user.tag} and ready!`); // Test fetching all global commands and ones from one guild expectType>>( await client.application!.commands.fetch(), ); expectType>>( await client.application!.commands.fetch({ guildId: testGuildId }), ); // Test command manager methods const globalCommand = await client.application?.commands.fetch(globalCommandId); const guildCommandFromGlobal = await client.application?.commands.fetch(guildCommandId, { guildId: testGuildId }); const guildCommandFromGuild = await client.guilds.cache.get(testGuildId)?.commands.fetch(guildCommandId); await client.application?.commands.create(slashCommandBuilder); await client.application?.commands.create(contextMenuCommandBuilder); await guild.commands.create(slashCommandBuilder); await guild.commands.create(contextMenuCommandBuilder); await client.application?.commands.edit(globalCommandId, slashCommandBuilder); await client.application?.commands.edit(globalCommandId, contextMenuCommandBuilder); await guild.commands.edit(guildCommandId, slashCommandBuilder); await guild.commands.edit(guildCommandId, contextMenuCommandBuilder); await client.application?.commands.edit(globalCommandId, { defaultMemberPermissions: null }); await globalCommand?.edit({ defaultMemberPermissions: null }); await globalCommand?.setDefaultMemberPermissions(null); await guildCommandFromGlobal?.edit({ dmPermission: false }); // @ts-expect-error await client.guilds.cache.get(testGuildId)?.commands.fetch(guildCommandId, { guildId: testGuildId }); // Test command permissions const globalPermissionsManager = client.application?.commands.permissions; const guildPermissionsManager = client.guilds.cache.get(testGuildId)?.commands.permissions; // Permissions from global manager await globalPermissionsManager?.add({ command: globalCommandId, guild: testGuildId, permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); await globalPermissionsManager?.has({ command: globalCommandId, guild: testGuildId, permissionId: testGuildId }); await globalPermissionsManager?.fetch({ guild: testGuildId }); await globalPermissionsManager?.fetch({ command: globalCommandId, guild: testGuildId }); await globalPermissionsManager?.remove({ command: globalCommandId, guild: testGuildId, roles: [testGuildId], token: 'VeryRealToken', }); await globalPermissionsManager?.remove({ command: globalCommandId, guild: testGuildId, users: [testUserId], token: 'VeryRealToken', }); await globalPermissionsManager?.remove({ command: globalCommandId, guild: testGuildId, channels: [testGuildId], token: 'VeryRealToken', }); await globalPermissionsManager?.remove({ command: globalCommandId, guild: testGuildId, roles: [testGuildId], users: [testUserId], channels: [testGuildId], token: 'VeryRealToken', }); await globalPermissionsManager?.set({ command: globalCommandId, guild: testGuildId, permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); // @ts-expect-error await globalPermissionsManager?.add({ command: globalCommandId, permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); // @ts-expect-error await globalPermissionsManager?.has({ command: globalCommandId, permissionId: testGuildId }); // @ts-expect-error await globalPermissionsManager?.fetch(); // @ts-expect-error await globalPermissionsManager?.fetch({ command: globalCommandId }); // @ts-expect-error await globalPermissionsManager?.remove({ command: globalCommandId, roles: [testGuildId], token: 'VeryRealToken' }); // @ts-expect-error await globalPermissionsManager?.remove({ command: globalCommandId, users: [testUserId], token: 'VeryRealToken' }); // @ts-expect-error await globalPermissionsManager?.remove({ command: globalCommandId, roles: [testGuildId], users: [testUserId], token: 'VeryRealToken', }); // @ts-expect-error await globalPermissionsManager?.set({ command: globalCommandId, permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); // @ts-expect-error await globalPermissionsManager?.add({ guild: testGuildId, permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); // @ts-expect-error await globalPermissionsManager?.has({ guild: testGuildId, permissionId: testGuildId }); // @ts-expect-error await globalPermissionsManager?.remove({ guild: testGuildId, roles: [testGuildId], token: 'VeryRealToken' }); // @ts-expect-error await globalPermissionsManager?.remove({ guild: testGuildId, users: [testUserId], token: 'VeryRealToken' }); // @ts-expect-error await globalPermissionsManager?.remove({ guild: testGuildId, roles: [testGuildId], users: [testUserId], token: 'VeryRealToken', }); // @ts-expect-error await globalPermissionsManager?.set({ guild: testGuildId, permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); // Permissions from guild manager await guildPermissionsManager?.add({ command: globalCommandId, permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); await guildPermissionsManager?.has({ command: globalCommandId, permissionId: testGuildId }); await guildPermissionsManager?.fetch({}); await guildPermissionsManager?.fetch({ command: globalCommandId }); await guildPermissionsManager?.remove({ command: globalCommandId, roles: [testGuildId], token: 'VeryRealToken' }); await guildPermissionsManager?.remove({ command: globalCommandId, users: [testUserId], token: 'VeryRealToken' }); await guildPermissionsManager?.remove({ command: globalCommandId, channels: [testGuildId], token: 'VeryRealToken' }); await guildPermissionsManager?.remove({ command: globalCommandId, roles: [testGuildId], users: [testUserId], channels: [testGuildId], token: 'VeryRealToken', }); await guildPermissionsManager?.set({ command: globalCommandId, permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); await guildPermissionsManager?.add({ command: globalCommandId, // @ts-expect-error guild: testGuildId, permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); // @ts-expect-error await guildPermissionsManager?.has({ command: globalCommandId, guild: testGuildId, permissionId: testGuildId }); // @ts-expect-error await guildPermissionsManager?.fetch({ guild: testGuildId }); // @ts-expect-error await guildPermissionsManager?.fetch({ command: globalCommandId, guild: testGuildId }); await guildPermissionsManager?.remove({ command: globalCommandId, // @ts-expect-error guild: testGuildId, roles: [testGuildId], token: 'VeryRealToken', }); await guildPermissionsManager?.remove({ command: globalCommandId, // @ts-expect-error guild: testGuildId, users: [testUserId], token: 'VeryRealToken', }); await guildPermissionsManager?.remove({ command: globalCommandId, // @ts-expect-error guild: testGuildId, roles: [testGuildId], users: [testUserId], token: 'VeryRealToken', }); await guildPermissionsManager?.set({ command: globalCommandId, // @ts-expect-error guild: testGuildId, permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); // @ts-expect-error await guildPermissionsManager?.add({ permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); // @ts-expect-error await guildPermissionsManager?.has({ permissionId: testGuildId }); // @ts-expect-error await guildPermissionsManager?.remove({ roles: [testGuildId], token: 'VeryRealToken' }); // @ts-expect-error await guildPermissionsManager?.remove({ users: [testUserId], token: 'VeryRealToken' }); // @ts-expect-error await guildPermissionsManager?.remove({ roles: [testGuildId], users: [testUserId], token: 'VeryRealToken' }); // @ts-expect-error await guildPermissionsManager?.set({ permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); // Permissions from cached global ApplicationCommand await globalCommand?.permissions.add({ guild: testGuildId, permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); await globalCommand?.permissions.has({ guild: testGuildId, permissionId: testGuildId }); await globalCommand?.permissions.fetch({ guild: testGuildId }); await globalCommand?.permissions.remove({ guild: testGuildId, roles: [testGuildId], token: 'VeryRealToken' }); await globalCommand?.permissions.remove({ guild: testGuildId, users: [testUserId], token: 'VeryRealToken' }); await globalCommand?.permissions.remove({ guild: testGuildId, roles: [testGuildId], users: [testUserId], token: 'VeryRealToken', }); await globalCommand?.permissions.set({ guild: testGuildId, permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); await globalCommand?.permissions.add({ // @ts-expect-error command: globalCommandId, guild: testGuildId, permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); await globalCommand?.permissions.has({ // @ts-expect-error command: globalCommandId, guild: testGuildId, permissionId: testGuildId, token: 'VeryRealToken', }); // @ts-expect-error await globalCommand?.permissions.fetch({ command: globalCommandId, guild: testGuildId, token: 'VeryRealToken' }); await globalCommand?.permissions.remove({ // @ts-expect-error command: globalCommandId, guild: testGuildId, roles: [testGuildId], token: 'VeryRealToken', }); await globalCommand?.permissions.remove({ // @ts-expect-error command: globalCommandId, guild: testGuildId, users: [testUserId], token: 'VeryRealToken', }); await globalCommand?.permissions.remove({ // @ts-expect-error command: globalCommandId, guild: testGuildId, roles: [testGuildId], users: [testUserId], token: 'VeryRealToken', }); await globalCommand?.permissions.set({ // @ts-expect-error command: globalCommandId, guild: testGuildId, permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); // @ts-expect-error await globalCommand?.permissions.add({ permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); // @ts-expect-error await globalCommand?.permissions.has({ permissionId: testGuildId }); // @ts-expect-error await globalCommand?.permissions.fetch({}); // @ts-expect-error await globalCommand?.permissions.remove({ roles: [testGuildId], token: 'VeryRealToken' }); // @ts-expect-error await globalCommand?.permissions.remove({ users: [testUserId], token: 'VeryRealToken' }); // @ts-expect-error await globalCommand?.permissions.remove({ roles: [testGuildId], users: [testUserId], token: 'VeryRealToken' }); // @ts-expect-error await globalCommand?.permissions.set({ permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], }); // Permissions from cached guild ApplicationCommand await guildCommandFromGlobal?.permissions.add({ permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); await guildCommandFromGlobal?.permissions.has({ permissionId: testGuildId }); await guildCommandFromGlobal?.permissions.fetch({}); await guildCommandFromGlobal?.permissions.remove({ roles: [testGuildId], token: 'VeryRealToken' }); await guildCommandFromGlobal?.permissions.remove({ users: [testUserId], token: 'VeryRealToken' }); await guildCommandFromGlobal?.permissions.remove({ roles: [testGuildId], users: [testUserId], token: 'VeryRealToken', }); await guildCommandFromGlobal?.permissions.set({ permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); await guildCommandFromGlobal?.permissions.add({ // @ts-expect-error command: globalCommandId, permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); // @ts-expect-error await guildCommandFromGlobal?.permissions.has({ command: guildCommandId, permissionId: testGuildId }); await guildCommandFromGlobal?.permissions.remove({ // @ts-expect-error command: guildCommandId, roles: [testGuildId], token: 'VeryRealToken', }); await guildCommandFromGlobal?.permissions.remove({ // @ts-expect-error command: guildCommandId, users: [testUserId], token: 'VeryRealToken', }); await guildCommandFromGlobal?.permissions.remove({ // @ts-expect-error command: guildCommandId, roles: [testGuildId], users: [testUserId], token: 'VeryRealToken', }); await guildCommandFromGlobal?.permissions.set({ // @ts-expect-error command: guildCommandId, permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); await guildCommandFromGlobal?.permissions.add({ // @ts-expect-error guild: testGuildId, permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); // @ts-expect-error await guildCommandFromGlobal?.permissions.has({ guild: testGuildId, permissionId: testGuildId }); await guildCommandFromGlobal?.permissions.remove({ // @ts-expect-error guild: testGuildId, roles: [testGuildId], token: 'VeryRealToken', }); // @ts-expect-error await guildCommandFromGlobal?.permissions.remove({ guild: testGuildId, users: [testUserId], token: 'VeryRealToken' }); await guildCommandFromGlobal?.permissions.remove({ // @ts-expect-error guild: testGuildId, roles: [testGuildId], users: [testUserId], token: 'VeryRealToken', }); await guildCommandFromGlobal?.permissions.set({ // @ts-expect-error guild: testGuildId, permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); await guildCommandFromGuild?.permissions.add({ permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); await guildCommandFromGuild?.permissions.has({ permissionId: testGuildId }); await guildCommandFromGuild?.permissions.fetch({}); await guildCommandFromGuild?.permissions.remove({ roles: [testGuildId], token: 'VeryRealToken' }); await guildCommandFromGuild?.permissions.remove({ users: [testUserId], token: 'VeryRealToken' }); await guildCommandFromGuild?.permissions.remove({ roles: [testGuildId], users: [testUserId], token: 'VeryRealToken', }); await guildCommandFromGuild?.permissions.set({ permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); await guildCommandFromGuild?.permissions.add({ // @ts-expect-error command: globalCommandId, permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); // @ts-expect-error await guildCommandFromGuild?.permissions.has({ command: guildCommandId, permissionId: testGuildId }); await guildCommandFromGuild?.permissions.remove({ // @ts-expect-error command: guildCommandId, roles: [testGuildId], token: 'VeryRealToken', }); await guildCommandFromGuild?.permissions.remove({ // @ts-expect-error command: guildCommandId, users: [testUserId], token: 'VeryRealToken', }); await guildCommandFromGuild?.permissions.remove({ // @ts-expect-error command: guildCommandId, roles: [testGuildId], users: [testUserId], token: 'VeryRealToken', }); await guildCommandFromGuild?.permissions.set({ // @ts-expect-error command: guildCommandId, permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); await guildCommandFromGuild?.permissions.add({ // @ts-expect-error guild: testGuildId, permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); // @ts-expect-error await guildCommandFromGuild?.permissions.has({ guild: testGuildId, permissionId: testGuildId }); // @ts-expect-error await guildCommandFromGuild?.permissions.remove({ guild: testGuildId, roles: [testGuildId], token: 'VeryRealToken' }); // @ts-expect-error await guildCommandFromGuild?.permissions.remove({ guild: testGuildId, users: [testUserId], token: 'VeryRealToken' }); await guildCommandFromGuild?.permissions.remove({ // @ts-expect-error guild: testGuildId, roles: [testGuildId], users: [testUserId], token: 'VeryRealToken', }); await guildCommandFromGuild?.permissions.set({ // @ts-expect-error guild: testGuildId, permissions: [{ type: ApplicationCommandPermissionType.Role, id: testGuildId, permission: true }], token: 'VeryRealToken', }); }); client.on('roleCreate', ({ client }) => expectType>(client)); client.on('roleDelete', ({ client }) => expectType>(client)); client.on('roleUpdate', ({ client: oldClient }, { client: newClient }) => { expectType>(oldClient); expectType>(newClient); }); client.on('stageInstanceCreate', ({ client }) => expectType>(client)); client.on('stageInstanceDelete', ({ client }) => expectType>(client)); client.on('stageInstanceUpdate', (oldStageInstance, { client }) => { expectType>(oldStageInstance!.client); expectType>(client); }); client.on('stickerCreate', ({ client }) => expectType>(client)); client.on('stickerDelete', ({ client }) => expectType>(client)); client.on('stickerUpdate', ({ client: oldClient }, { client: newClient }) => { expectType>(oldClient); expectType>(newClient); }); client.on('threadCreate', thread => { expectType>(thread.client); if (thread.type === ChannelType.PrivateThread) { expectType(thread.createdTimestamp); expectType(thread.createdAt); } else { expectType(thread.createdTimestamp); expectType(thread.createdAt); } }); client.on('threadDelete', ({ client }) => expectType>(client)); client.on('threadListSync', (threads, { client }) => { expectType>(threads.first()!.client); expectType>(client); }); client.on('threadMembersUpdate', (addedMembers, removedMembers, thread) => { expectType>(addedMembers.first()!.client); expectType>(removedMembers.first()!.client); expectType>(thread.client); expectType>(addedMembers); expectType>(removedMembers); expectType(thread); const left = removedMembers.first(); if (!left) return; if (left.partial) { expectType(left); expectType(left.flags); } else { expectType(left); expectType(left.flags); } }); client.on('threadMemberUpdate', ({ client: oldClient }, { client: newClient }) => { expectType>(oldClient); expectType>(newClient); }); client.on('threadUpdate', ({ client: oldClient }, { client: newClient }) => { expectType>(oldClient); expectType>(newClient); }); client.on('typingStart', ({ client }) => expectType>(client)); client.on('userUpdate', ({ client: oldClient }, { client: newClient }) => { expectType>(oldClient); expectType>(newClient); }); client.on('voiceStateUpdate', ({ client: oldClient }, { client: newClient }) => { expectType>(oldClient); expectType>(newClient); }); client.on('webhooksUpdate', ({ client }) => expectType>(client)); client.on('guildCreate', async g => { expectType>(g.client); const channel = g.channels.cache.random(); if (!channel) return; if (channel.type === ChannelType.GuildText) { const row: ActionRowData = { type: ComponentType.ActionRow, components: [ new ButtonBuilder(), { type: ComponentType.Button, style: ButtonStyle.Primary, label: 'string', customId: 'foo' }, { type: ComponentType.Button, style: ButtonStyle.Link, label: 'test', url: 'test' }, { type: ComponentType.StringSelect, customId: 'foo', options: [{ label: 'label', value: 'value' }] }, new StringSelectMenuBuilder(), // @ts-expect-error { type: ComponentType.TextInput, style: TextInputStyle.Paragraph, customId: 'foo', label: 'test' }, // @ts-expect-error new TextInputBuilder(), ], }; const row2 = new ActionRowBuilder({ type: ComponentType.ActionRow, components: [ { type: ComponentType.Button, style: ButtonStyle.Primary, label: 'string', customId: 'foo' }, { type: ComponentType.Button, style: ButtonStyle.Link, label: 'test', url: 'test' }, { type: ComponentType.StringSelect, customId: 'foo', options: [{ label: 'label', value: 'value' }] }, ], }); channel.send({ components: [row, row2] }); } channel.setName('foo').then(updatedChannel => { console.log(`New channel name: ${updatedChannel.name}`); }); // @ts-expect-error no options expectNotType>(g.members.add(testUserId)); // @ts-expect-error no access token expectNotType>(g.members.add(testUserId, {})); expectNotType>( // @ts-expect-error invalid role resolvable g.members.add(testUserId, { accessToken: 'totallyRealAccessToken', roles: [g.roles.cache] }), ); expectType>( g.members.add(testUserId, { accessToken: 'totallyRealAccessToken', fetchWhenExisting: false }), ); expectType>(g.members.add(testUserId, { accessToken: 'totallyRealAccessToken' })); expectType>( g.members.add(testUserId, { accessToken: 'totallyRealAccessToken', mute: true, deaf: false, roles: [g.roles.cache.first()!], force: true, fetchWhenExisting: true, }), ); }); client.login('absolutely-valid-token'); declare const loggedInClient: Client; expectType(loggedInClient.application); expectType(loggedInClient.readyAt); expectType(loggedInClient.readyTimestamp); expectType(loggedInClient.token); expectType(loggedInClient.uptime); expectType(loggedInClient.user); declare const loggedOutClient: Client; expectType(loggedOutClient.application); expectType(loggedOutClient.readyAt); expectType(loggedOutClient.readyTimestamp); expectType(loggedOutClient.token); expectType(loggedOutClient.uptime); expectType(loggedOutClient.user); expectType(serialize(undefined)); expectType(serialize(null)); expectType(serialize([1, 2, 3])); expectType<{}>(serialize(new Set([1, 2, 3]))); expectType<{}>( serialize( new Map([ [1, '2'], [2, '4'], ]), ), ); expectType(serialize(new PermissionsBitField(PermissionFlagsBits.AttachFiles))); expectType(serialize(new IntentsBitField(GatewayIntentBits.Guilds))); expectAssignable( serialize( new Collection([ [1, '2'], [2, '4'], ]), ), ); expectType(serialize(Symbol('a'))); expectType(serialize(() => {})); expectType(serialize(BigInt(42))); // Test type return of broadcastEval: declare const shardClientUtil: ShardClientUtil; declare const shardingManager: ShardingManager; expectType>(shardingManager.broadcastEval(() => 1)); expectType>(shardClientUtil.broadcastEval(() => 1)); expectType>(shardingManager.broadcastEval(async () => 1)); expectType>(shardClientUtil.broadcastEval(async () => 1)); declare const dmChannel: DMChannel; declare const threadChannel: ThreadChannel; declare const threadChannelFromForum: ThreadChannel; declare const threadChannelNotFromForum: ThreadChannel; declare const newsChannel: NewsChannel; declare const textChannel: TextChannel; declare const voiceChannel: VoiceChannel; declare const guild: Guild; declare const user: User; declare const guildMember: GuildMember; // Test thread channels' parent inference expectType(threadChannel.parent); expectType(threadChannelFromForum.parent); expectType(threadChannelNotFromForum.parent); // Test whether the structures implement send expectType['send']>(dmChannel.send); expectType['send']>(threadChannel.send); expectType['send']>(newsChannel.send); expectType['send']>(textChannel.send); expectType['send']>(voiceChannel.send); expectAssignable(user); expectAssignable(guildMember); expectType>(textChannel.setType(ChannelType.GuildAnnouncement)); expectType>(newsChannel.setType(ChannelType.GuildText)); expectType(dmChannel.lastMessage); expectType(threadChannel.lastMessage); expectType(newsChannel.lastMessage); expectType(textChannel.lastMessage); expectType(voiceChannel.lastMessage); notPropertyOf(user, 'lastMessage'); notPropertyOf(user, 'lastMessageId'); notPropertyOf(guildMember, 'lastMessage'); notPropertyOf(guildMember, 'lastMessageId'); // Test collector event parameters declare const messageCollector: MessageCollector; messageCollector.on('collect', (...args) => { expectType<[Message, Collection]>(args); }); (async () => { for await (const value of messageCollector) { expectType<[Message, Collection]>(value); } })(); declare const reactionCollector: ReactionCollector; reactionCollector.on('dispose', (...args) => { expectType<[MessageReaction, User]>(args); }); (async () => { for await (const value of reactionCollector) { expectType<[MessageReaction, User]>(value); } })(); // Make sure the properties are typed correctly, and that no backwards properties // (K -> V and V -> K) exist: expectAssignable<'messageCreate'>(Events.MessageCreate); expectAssignable<'close'>(WebSocketShardEvents.Close); expectAssignable<'death'>(ShardEvents.Death); expectAssignable<1>(Status.Connecting); declare const applicationCommandData: ApplicationCommandData; declare const applicationCommandOptionData: ApplicationCommandOptionData; declare const applicationCommandResolvable: ApplicationCommandResolvable; declare const applicationCommandManager: ApplicationCommandManager; { type ApplicationCommandScope = ApplicationCommand<{ guild: GuildResolvable }>; expectType>(applicationCommandManager.create(applicationCommandData)); expectAssignable>(applicationCommandManager.create(applicationCommandData, '0')); expectType>( applicationCommandManager.edit(applicationCommandResolvable, applicationCommandData), ); expectType>( applicationCommandManager.edit(applicationCommandResolvable, applicationCommandData, '0'), ); expectType>>( applicationCommandManager.set([applicationCommandData]), ); expectType>>( applicationCommandManager.set([applicationCommandData] as const, '0'), ); // Test inference of choice values. if ('choices' in applicationCommandOptionData) { if (applicationCommandOptionData.type === ApplicationCommandOptionType.String) { expectType(applicationCommandOptionData.choices[0]!.value); expectNotType(applicationCommandOptionData.choices[0]!.value); } if (applicationCommandOptionData.type === ApplicationCommandOptionType.Integer) { expectType(applicationCommandOptionData.choices[0]!.value); expectNotType(applicationCommandOptionData.choices[0]!.value); } if (applicationCommandOptionData.type === ApplicationCommandOptionType.Number) { expectType(applicationCommandOptionData.choices[0]!.value); expectNotType(applicationCommandOptionData.choices[0]!.value); } } } declare const applicationCommandPermissionsManager: ApplicationCommandPermissionsManager< {}, {}, Guild | null, Snowflake >; { applicationCommandPermissionsManager.add({ permissions: [], token: '' }); applicationCommandPermissionsManager.add({ permissions: [] as const, token: '' }); applicationCommandPermissionsManager.set({ permissions: [], token: '' }); applicationCommandPermissionsManager.set({ permissions: [] as const, token: '' }); applicationCommandPermissionsManager.remove({ channels: [], roles: [], users: [], token: '' }); applicationCommandPermissionsManager.remove({ channels: [] as const, roles: [] as const, users: [] as const, token: '', }); } declare const chatInputApplicationCommandData: ChatInputApplicationCommandData; { chatInputApplicationCommandData.options = []; chatInputApplicationCommandData.options = [] as const; } declare const applicationCommandChannelOptionData: ApplicationCommandChannelOptionData; declare const applicationCommandChannelOption: ApplicationCommandChannelOption; { applicationCommandChannelOptionData.channelTypes = [] as const; applicationCommandChannelOptionData.channel_types = [] as const; applicationCommandChannelOption.channelTypes = [] as const; } declare const applicationNonChoiceOptionData: ApplicationCommandOptionData & { type: CommandOptionNonChoiceResolvableType; }; { // Options aren't allowed on this command type. // @ts-expect-error applicationNonChoiceOptionData.choices; } declare const applicationCommandChoicesData: ApplicationCommandChoicesData; declare const applicationCommandChoicesOption: ApplicationCommandChoicesOption; { applicationCommandChoicesData.choices = []; applicationCommandChoicesData.choices = [] as const; applicationCommandChoicesOption.choices = []; applicationCommandChoicesOption.choices = [] as const; } declare const applicationCommandSubCommandData: ApplicationCommandSubCommandData; declare const applicationCommandSubCommand: ApplicationCommandSubCommand; { applicationCommandSubCommandData.options = []; applicationCommandSubCommandData.options = [] as const; applicationCommandSubCommand.options = []; applicationCommandSubCommand.options = [] as const; } declare const applicationSubGroupCommandData: ApplicationCommandSubGroupData; declare const applicationCommandSubGroup: ApplicationCommandSubGroup; { expectType(applicationSubGroupCommandData.type); applicationSubGroupCommandData.options = []; applicationSubGroupCommandData.options = [] as const; applicationCommandSubGroup.options = []; applicationCommandSubGroup.options = [] as const; } declare const autoModerationRuleManager: AutoModerationRuleManager; { expectType>(autoModerationRuleManager.fetch('1234567890')); expectType>(autoModerationRuleManager.fetch({ autoModerationRule: '1234567890' })); expectType>( autoModerationRuleManager.fetch({ autoModerationRule: '1234567890', cache: false }), ); expectType>( autoModerationRuleManager.fetch({ autoModerationRule: '1234567890', force: true }), ); expectType>( autoModerationRuleManager.fetch({ autoModerationRule: '1234567890', cache: false, force: true }), ); expectType>>(autoModerationRuleManager.fetch()); expectType>>(autoModerationRuleManager.fetch({})); expectType>>(autoModerationRuleManager.fetch({ cache: false })); // @ts-expect-error The `force` option cannot be used alongside fetching all auto moderation rules. autoModerationRuleManager.fetch({ force: false }); } declare const guildApplicationCommandManager: GuildApplicationCommandManager; expectType>>(guildApplicationCommandManager.fetch()); expectType>>(guildApplicationCommandManager.fetch(undefined, {})); expectType>(guildApplicationCommandManager.fetch('0')); declare const categoryChannelChildManager: CategoryChannelChildManager; { expectType>(categoryChannelChildManager.create({ name: 'name', type: ChannelType.GuildVoice })); expectType>(categoryChannelChildManager.create({ name: 'name', type: ChannelType.GuildText })); expectType>( categoryChannelChildManager.create({ name: 'name', type: ChannelType.GuildAnnouncement }), ); expectType>( categoryChannelChildManager.create({ name: 'name', type: ChannelType.GuildStageVoice }), ); expectType>(categoryChannelChildManager.create({ name: 'name' })); expectType>(categoryChannelChildManager.create({ name: 'name' })); } declare const guildChannelManager: GuildChannelManager; { expectType>(guildChannelManager.create({ name: 'name' })); expectType>(guildChannelManager.create({ name: 'name' })); expectType>(guildChannelManager.create({ name: 'name', type: ChannelType.GuildVoice })); expectType>(guildChannelManager.create({ name: 'name', type: ChannelType.GuildCategory })); expectType>(guildChannelManager.create({ name: 'name', type: ChannelType.GuildText })); expectType>(guildChannelManager.create({ name: 'name', type: ChannelType.GuildAnnouncement })); expectType>(guildChannelManager.create({ name: 'name', type: ChannelType.GuildStageVoice })); expectType>(guildChannelManager.create({ name: 'name', type: ChannelType.GuildForum })); expectType>>(guildChannelManager.fetch()); expectType>>( guildChannelManager.fetch(undefined, {}), ); expectType>(guildChannelManager.fetch('0')); const channel = guildChannelManager.cache.first()!; if (channel.isTextBased()) { const { messages } = channel; const message = await messages.fetch('123'); expectType(messages); expectType>>(messages.crosspost('1234567890')); expectType>>(messages.edit('1234567890', 'text')); expectType>>(messages.fetch('1234567890')); expectType>>>(messages.fetchPinned()); expectType(message.guild); expectType(message.guildId); expectType(message.channel.messages.channel); } } { const { messages } = dmChannel; const message = await messages.fetch('123'); expectType(messages); expectType>(messages.edit('1234567890', 'text')); expectType>(messages.fetch('1234567890')); expectType>>(messages.fetchPinned()); expectType(message.guild); expectType(message.guildId); expectType(message.channel.messages.channel); expectType(message.mentions); expectType(message.mentions.guild); expectType | null>(message.mentions.members); if (messages.channel.isDMBased()) { expectType(messages.channel); expectType(messages.channel.messages.channel); } // @ts-expect-error Crossposting is not possible in direct messages. messages.crosspost('1234567890'); } declare const threadManager: ThreadManager; { expectType>(threadManager.fetch('12345678901234567')); expectType>(threadManager.fetch('12345678901234567', { cache: true, force: false })); expectType>(threadManager.fetch()); expectType>(threadManager.fetch({})); expectType>(threadManager.fetch({ archived: { limit: 4 } })); // @ts-expect-error The force option has no effect here. threadManager.fetch({ archived: {} }, { force: true }); } declare const guildForumThreadManager: GuildForumThreadManager; expectType(guildForumThreadManager.channel); declare const guildTextThreadManager: GuildTextThreadManager< ChannelType.PublicThread | ChannelType.PrivateThread | ChannelType.AnnouncementThread >; expectType(guildTextThreadManager.channel); declare const guildMemberManager: GuildMemberManager; { expectType>(guildMemberManager.fetch('12345678901234567')); expectType>(guildMemberManager.fetch({ user: '12345678901234567' })); expectType>(guildMemberManager.fetch({ user: '12345678901234567', cache: true, force: false })); expectType>(guildMemberManager.fetch({ user: '12345678901234567', cache: true, force: false })); expectType>>(guildMemberManager.fetch()); expectType>>(guildMemberManager.fetch({})); expectType>>(guildMemberManager.fetch({ user: ['12345678901234567'] })); expectType>>(guildMemberManager.fetch({ withPresences: false })); expectType>(guildMemberManager.fetch({ user: '12345678901234567', withPresences: true })); expectType>>( guildMemberManager.fetch({ query: 'test', user: ['12345678901234567'], nonce: 'test' }), ); // @ts-expect-error The cache & force options have no effect here. guildMemberManager.fetch({ cache: true, force: false }); // @ts-expect-error The force option has no effect here. guildMemberManager.fetch({ user: ['12345678901234567'], cache: true, force: false }); } declare const messageManager: MessageManager; { expectType>(messageManager.fetch('1234567890')); expectType>(messageManager.fetch({ message: '1234567890' })); expectType>(messageManager.fetch({ message: '1234567890', cache: true, force: false })); expectType>>(messageManager.fetch()); expectType>>(messageManager.fetch({})); expectType>>( messageManager.fetch({ limit: 100, before: '1234567890', cache: false }), ); // @ts-expect-error messageManager.fetch({ cache: true, force: false }); // @ts-expect-error messageManager.fetch({ message: '1234567890', after: '1234567890', cache: true, force: false }); } declare const roleManager: RoleManager; expectType>>(roleManager.fetch()); expectType>>(roleManager.fetch(undefined, {})); expectType>(roleManager.fetch('0')); declare const guildEmojiManager: GuildEmojiManager; expectType>>(guildEmojiManager.fetch()); expectType>>(guildEmojiManager.fetch(undefined, {})); expectType>(guildEmojiManager.fetch('0')); declare const guildBanManager: GuildBanManager; { expectType>(guildBanManager.fetch('1234567890')); expectType>(guildBanManager.fetch({ user: '1234567890' })); expectType>(guildBanManager.fetch({ user: '1234567890', cache: true, force: false })); expectType>>(guildBanManager.fetch()); expectType>>(guildBanManager.fetch({})); expectType>>(guildBanManager.fetch({ limit: 100, before: '1234567890' })); // @ts-expect-error guildBanManager.fetch({ cache: true, force: false }); // @ts-expect-error guildBanManager.fetch({ user: '1234567890', after: '1234567890', cache: true, force: false }); } declare const threadMemberWithGuildMember: ThreadMember; declare const threadMemberManager: ThreadMemberManager; { expectType>(threadMemberManager.fetch('12345678')); expectType>(threadMemberManager.fetch({ member: '12345678', cache: false })); expectType>(threadMemberManager.fetch({ member: '12345678', force: true })); expectType>>(threadMemberManager.fetch({ member: threadMemberWithGuildMember })); expectType>>(threadMemberManager.fetch({ member: '12345678901234567', withMember: true })); expectType>>(threadMemberManager.fetch()); expectType>>(threadMemberManager.fetch({})); expectType>>>( threadMemberManager.fetch({ cache: true, limit: 50, withMember: true, after: '12345678901234567' }), ); expectType>>( threadMemberManager.fetch({ cache: true, withMember: false }), ); // @ts-expect-error The `force` option cannot be used alongside fetching all thread members. threadMemberManager.fetch({ cache: true, force: false }); // @ts-expect-error `withMember` needs to be `true` to receive paginated results. threadMemberManager.fetch({ withMember: false, limit: 5, after: '12345678901234567' }); } declare const typing: Typing; expectType(typing.user); if (typing.user.partial) expectType(typing.user.username); if (!typing.user.partial) expectType(typing.user.tag); expectType(typing.channel); if (typing.channel.partial) expectType(typing.channel.lastMessageId); expectType(typing.member); expectType(typing.guild); if (typing.inGuild()) { expectType(typing.channel.guild); expectType(typing.guild); } // Test interactions declare const interaction: Interaction; declare const booleanValue: boolean; if (interaction.inGuild()) { expectType(interaction.guildId); } else { expectType(interaction.guildId); } client.on('interactionCreate', async interaction => { if (interaction.type === InteractionType.MessageComponent) { expectType(interaction); expectType(interaction.component); expectType(interaction.message); if (interaction.inCachedGuild()) { expectAssignable(interaction); expectType(interaction.component); expectType>(interaction.message); expectType(interaction.guild); expectType>>(interaction.reply({ content: 'a', fetchReply: true })); expectType>>(interaction.deferReply({ fetchReply: true })); expectType>>(interaction.editReply({ content: 'a' })); expectType>>(interaction.fetchReply()); expectType>>(interaction.update({ content: 'a', fetchReply: true })); expectType>>(interaction.deferUpdate({ fetchReply: true })); expectType>>(interaction.followUp({ content: 'a' })); } else if (interaction.inRawGuild()) { expectAssignable(interaction); expectType(interaction.component); expectType>(interaction.message); expectType(interaction.guild); expectType>>(interaction.reply({ content: 'a', fetchReply: true })); expectType>>(interaction.deferReply({ fetchReply: true })); expectType>>(interaction.editReply({ content: 'a' })); expectType>>(interaction.fetchReply()); expectType>>(interaction.update({ content: 'a', fetchReply: true })); expectType>>(interaction.deferUpdate({ fetchReply: true })); expectType>>(interaction.followUp({ content: 'a' })); } else if (interaction.inGuild()) { expectAssignable(interaction); expectType(interaction.component); expectType(interaction.message); expectType(interaction.guild); expectType>(interaction.reply({ content: 'a', fetchReply: true })); expectType>(interaction.deferReply({ fetchReply: true })); expectType>(interaction.editReply({ content: 'a' })); expectType>(interaction.fetchReply()); expectType>(interaction.update({ content: 'a', fetchReply: true })); expectType>(interaction.deferUpdate({ fetchReply: true })); expectType>(interaction.followUp({ content: 'a' })); } } if (interaction.inCachedGuild()) { expectAssignable(interaction.member); expectNotType>(interaction); expectAssignable(interaction); expectType(interaction.guildLocale); } else if (interaction.inRawGuild()) { expectAssignable(interaction.member); expectNotAssignable>(interaction); expectType(interaction.guildLocale); } else if (interaction.inGuild()) { expectType(interaction.guildLocale); } else { expectType(interaction.member); expectNotAssignable>(interaction); expectType(interaction.guildId); } if ( interaction.type === InteractionType.ApplicationCommand && (interaction.commandType === ApplicationCommandType.User || interaction.commandType === ApplicationCommandType.Message) ) { expectType(interaction); if (interaction.inCachedGuild()) { expectAssignable(interaction); expectAssignable(interaction.guild); expectAssignable>(interaction); expectType>>(interaction.reply({ content: 'a', fetchReply: true })); expectType>>(interaction.deferReply({ fetchReply: true })); expectType>>(interaction.editReply({ content: 'a' })); expectType>>(interaction.fetchReply()); expectType>>(interaction.followUp({ content: 'a' })); } else if (interaction.inRawGuild()) { expectAssignable(interaction); expectType(interaction.guild); expectType>>(interaction.reply({ content: 'a', fetchReply: true })); expectType>>(interaction.deferReply({ fetchReply: true })); expectType>>(interaction.editReply({ content: 'a' })); expectType>>(interaction.fetchReply()); expectType>>(interaction.followUp({ content: 'a' })); } else if (interaction.inGuild()) { expectAssignable(interaction); expectType(interaction.guild); expectType>(interaction.reply({ content: 'a', fetchReply: true })); expectType>(interaction.deferReply({ fetchReply: true })); expectType>(interaction.editReply({ content: 'a' })); expectType>(interaction.fetchReply()); expectType>(interaction.followUp({ content: 'a' })); } } if ( interaction.type === InteractionType.ApplicationCommand && interaction.commandType === ApplicationCommandType.Message ) { expectType(interaction.targetMessage); if (interaction.inCachedGuild()) { expectType>(interaction.targetMessage); } else if (interaction.inRawGuild()) { expectType>(interaction.targetMessage); } else if (interaction.inGuild()) { expectType(interaction.targetMessage); } } if (interaction.type === InteractionType.MessageComponent && interaction.componentType === ComponentType.Button) { expectType(interaction); expectType(interaction.component); expectType(interaction.message); if (interaction.inCachedGuild()) { expectAssignable(interaction); expectType(interaction.component); expectType>(interaction.message); expectType(interaction.guild); expectType>>(interaction.reply({ fetchReply: true })); } else if (interaction.inRawGuild()) { expectAssignable(interaction); expectType(interaction.component); expectType>(interaction.message); expectType(interaction.guild); expectType>>(interaction.reply({ fetchReply: true })); } else if (interaction.inGuild()) { expectAssignable(interaction); expectType(interaction.component); expectType(interaction.message); expectAssignable(interaction.guild); expectType>(interaction.reply({ fetchReply: true })); } } if ( interaction.type === InteractionType.MessageComponent && interaction.componentType === ComponentType.StringSelect ) { expectType(interaction); expectType(interaction.component); expectType(interaction.message); if (interaction.inCachedGuild()) { expectAssignable(interaction); expectType(interaction.component); expectType>(interaction.message); expectType(interaction.guild); expectType>>(interaction.reply({ fetchReply: true })); } else if (interaction.inRawGuild()) { expectAssignable(interaction); expectType(interaction.component); expectType>(interaction.message); expectType(interaction.guild); expectType>>(interaction.reply({ fetchReply: true })); } else if (interaction.inGuild()) { expectAssignable(interaction); expectType(interaction.component); expectType(interaction.message); expectType(interaction.guild); expectType>(interaction.reply({ fetchReply: true })); } } if ( interaction.type === InteractionType.ApplicationCommand && interaction.commandType === ApplicationCommandType.ChatInput ) { if (interaction.inRawGuild()) { expectNotAssignable>(interaction); expectAssignable(interaction); expectType>>(interaction.reply({ fetchReply: true })); expectType(interaction.options.getMember('test')); expectType(interaction.options.getChannel('test', true)); expectType(interaction.options.getRole('test', true)); } else if (interaction.inCachedGuild()) { const msg = await interaction.reply({ fetchReply: true }); const btn = await msg.awaitMessageComponent({ componentType: ComponentType.Button }); expectType>(msg); expectType>(btn); expectType(interaction.options.getMember('test')); expectAssignable(interaction); expectType>>(interaction.reply({ fetchReply: true })); expectType(interaction.options.getChannel('test', true)); expectType(interaction.options.getRole('test', true)); expectType(interaction.options.getChannel('test', true, [ChannelType.PublicThread])); expectType(interaction.options.getChannel('test', true, [ChannelType.AnnouncementThread])); expectType( interaction.options.getChannel('test', true, [ChannelType.PublicThread, ChannelType.AnnouncementThread]), ); expectType(interaction.options.getChannel('test', true, [ChannelType.PrivateThread])); expectType(interaction.options.getChannel('test', true, [ChannelType.GuildText])); expectType(interaction.options.getChannel('test', false, [ChannelType.GuildText])); expectType( interaction.options.getChannel('test', true, [ChannelType.GuildForum, ChannelType.GuildVoice]), ); expectType(interaction.options.getChannel('test', true, [ChannelType.GuildText] as const)); expectType( interaction.options.getChannel('test', false, [ChannelType.GuildForum, ChannelType.GuildVoice]), ); } else { // @ts-expect-error consumeCachedCommand(interaction); expectType(interaction); expectType>(interaction.reply({ fetchReply: true })); expectType(interaction.options.getMember('test')); expectType(interaction.options.getChannel('test', true)); expectType(interaction.options.getRole('test', true)); } expectType(interaction); expectType, 'getFocused' | 'getMessage'>>(interaction.options); expectType(interaction.options.data); const optionalOption = interaction.options.get('name'); const requiredOption = interaction.options.get('name', true); expectType(optionalOption); expectType(requiredOption); expectType(requiredOption.options); expectType(interaction.options.getString('name', booleanValue)); expectType(interaction.options.getString('name', false)); expectType(interaction.options.getString('name', true)); expectType(interaction.options.getSubcommand()); expectType(interaction.options.getSubcommand(true)); expectType(interaction.options.getSubcommand(booleanValue)); expectType(interaction.options.getSubcommand(false)); expectType(interaction.options.getSubcommandGroup(true)); expectType(interaction.options.getSubcommandGroup()); expectType(interaction.options.getSubcommandGroup(booleanValue)); expectType(interaction.options.getSubcommandGroup(false)); } if (interaction.isRepliable()) { expectAssignable(interaction); interaction.reply('test'); } if ( interaction.type === InteractionType.ApplicationCommand && interaction.commandType === ApplicationCommandType.ChatInput && interaction.isRepliable() ) { expectAssignable(interaction); expectAssignable(interaction); } if (interaction.type === InteractionType.ModalSubmit && interaction.isRepliable()) { expectType(interaction); if (interaction.inCachedGuild()) { expectAssignable(interaction); expectType(interaction.guild); expectType>>(interaction.reply({ content: 'a', fetchReply: true })); expectType>>(interaction.deferReply({ fetchReply: true })); expectType>>(interaction.editReply({ content: 'a' })); expectType>>(interaction.fetchReply()); expectType>>(interaction.deferUpdate({ fetchReply: true })); expectType>>(interaction.followUp({ content: 'a' })); } else if (interaction.inRawGuild()) { expectAssignable(interaction); expectType(interaction.guild); expectType>>(interaction.reply({ content: 'a', fetchReply: true })); expectType>>(interaction.deferReply({ fetchReply: true })); expectType>>(interaction.editReply({ content: 'a' })); expectType>>(interaction.fetchReply()); expectType>>(interaction.deferUpdate({ fetchReply: true })); expectType>>(interaction.followUp({ content: 'a' })); } else if (interaction.inGuild()) { expectAssignable(interaction); expectType(interaction.guild); expectType>(interaction.reply({ content: 'a', fetchReply: true })); expectType>(interaction.deferReply({ fetchReply: true })); expectType>(interaction.editReply({ content: 'a' })); expectType>(interaction.fetchReply()); expectType>(interaction.deferUpdate({ fetchReply: true })); expectType>(interaction.followUp({ content: 'a' })); } } }); declare const shard: Shard; shard.on('death', process => { expectType(process); }); declare const webSocketShard: WebSocketShard; webSocketShard.on('close', event => { expectType(event); }); declare const collector: Collector; collector.on('collect', (collected, ...other) => { expectType(collected); expectType(other); }); collector.on('dispose', (vals, ...other) => { expectType(vals); expectType(other); }); collector.on('end', (collection, reason) => { expectType>(collection); expectType(reason); }); (async () => { for await (const value of collector) { expectType<[Interaction, ...string[]]>(value); } })(); expectType>(shard.eval(c => c.readyTimestamp)); // Test audit logs expectType>>(guild.fetchAuditLogs({ type: AuditLogEvent.MemberKick })); expectType>>( guild.fetchAuditLogs({ type: AuditLogEvent.ChannelCreate }), ); expectType>>( guild.fetchAuditLogs({ type: AuditLogEvent.IntegrationUpdate }), ); expectType>>(guild.fetchAuditLogs({ type: null })); expectType>>(guild.fetchAuditLogs()); expectType | undefined>>( guild.fetchAuditLogs({ type: AuditLogEvent.MemberKick }).then(al => al.entries.first()), ); expectAssignable | undefined>>( guild.fetchAuditLogs({ type: AuditLogEvent.MemberKick }).then(al => al.entries.first()), ); expectType | undefined>>( guild.fetchAuditLogs({ type: null }).then(al => al.entries.first()), ); expectType | undefined>>( guild.fetchAuditLogs().then(al => al.entries.first()), ); expectType>( guild.fetchAuditLogs({ type: AuditLogEvent.MemberKick }).then(al => al.entries.first()?.extra), ); expectType>( guild.fetchAuditLogs({ type: AuditLogEvent.StageInstanceCreate }).then(al => al.entries.first()?.extra), ); expectType>( guild.fetchAuditLogs({ type: AuditLogEvent.MessageDelete }).then(al => al.entries.first()?.extra), ); expectType>( guild.fetchAuditLogs({ type: AuditLogEvent.MemberKick }).then(al => al.entries.first()?.target), ); expectType>( guild.fetchAuditLogs({ type: AuditLogEvent.StageInstanceCreate }).then(al => al.entries.first()?.target), ); expectType>( guild.fetchAuditLogs({ type: AuditLogEvent.MessageDelete }).then(al => al.entries.first()?.target), ); declare const TextBasedChannel: TextBasedChannel; declare const TextBasedChannelTypes: TextBasedChannelTypes; declare const VoiceBasedChannel: VoiceBasedChannel; declare const GuildBasedChannel: GuildBasedChannel; declare const NonThreadGuildBasedChannel: NonThreadGuildBasedChannel; declare const GuildTextBasedChannel: GuildTextBasedChannel; expectType(TextBasedChannel); expectType< | ChannelType.GuildText | ChannelType.DM | ChannelType.GuildAnnouncement | ChannelType.GuildVoice | ChannelType.GuildStageVoice | ThreadChannelType >(TextBasedChannelTypes); expectType(VoiceBasedChannel); expectType(GuildBasedChannel); expectType( NonThreadGuildBasedChannel, ); expectType(GuildTextBasedChannel); const button = new ButtonBuilder({ label: 'test', style: ButtonStyle.Primary, customId: 'test', }); const selectMenu = new StringSelectMenuBuilder({ maxValues: 10, minValues: 2, customId: 'test', }); new ActionRowBuilder({ components: [selectMenu.toJSON(), button.toJSON()], }); new StringSelectMenuBuilder({ customId: 'foo', }); new ButtonBuilder({ style: ButtonStyle.Danger, }) .setEmoji('') .setEmoji('<:foo:123>') .setEmoji('foobar:123') .setEmoji('😏') .setEmoji({ name: 'test', id: '123', animated: false, }); // @ts-expect-error new EmbedBuilder().setColor('abc'); new EmbedBuilder().setColor('#ffffff'); expectNotAssignable>({ type: ComponentType.ActionRow, components: [ { type: ComponentType.Button, }, ], }); declare const chatInputInteraction: ChatInputCommandInteraction; expectType(chatInputInteraction.options.getAttachment('attachment', true)); expectType(chatInputInteraction.options.getAttachment('attachment')); declare const modal: ModalBuilder; chatInputInteraction.showModal(modal); chatInputInteraction.showModal({ title: 'abc', custom_id: 'abc', components: [ { components: [ { custom_id: 'aa', label: 'label', style: TextInputStyle.Short, type: ComponentType.TextInput, }, ], type: ComponentType.ActionRow, }, ], }); declare const selectMenuData: APISelectMenuComponent; StringSelectMenuBuilder.from(selectMenuData); declare const selectMenuComp: SelectMenuComponent; StringSelectMenuBuilder.from(selectMenuComp); declare const buttonData: APIButtonComponent; ButtonBuilder.from(buttonData); declare const buttonComp: ButtonComponent; ButtonBuilder.from(buttonComp); declare const textInputData: APITextInputComponent; TextInputBuilder.from(textInputData); declare const textInputComp: TextInputComponent; TextInputBuilder.from(textInputComp); declare const embedData: APIEmbed; EmbedBuilder.from(embedData); declare const embedComp: Embed; EmbedBuilder.from(embedComp); declare const actionRowData: APIActionRowComponent; ActionRowBuilder.from(actionRowData); declare const actionRowComp: ActionRow; ActionRowBuilder.from(actionRowComp); declare const buttonsActionRowData: APIActionRowComponent; declare const buttonsActionRowComp: ActionRow; expectType>(ActionRowBuilder.from(buttonsActionRowData)); expectType>(ActionRowBuilder.from(buttonsActionRowComp)); declare const anyComponentsActionRowData: APIActionRowComponent; declare const anyComponentsActionRowComp: ActionRow; expectType(ActionRowBuilder.from(anyComponentsActionRowData)); expectType(ActionRowBuilder.from(anyComponentsActionRowComp)); declare const stageChannel: StageChannel; declare const partialGroupDMChannel: PartialGroupDMChannel; expectType(textChannel.toString()); expectType(voiceChannel.toString()); expectType(newsChannel.toString()); expectType(threadChannel.toString()); expectType(stageChannel.toString()); expectType(partialGroupDMChannel.toString()); expectType(dmChannel.toString()); expectType(user.toString()); expectType(guildMember.toString()); declare const webhook: Webhook; declare const webhookClient: WebhookClient; declare const interactionWebhook: InteractionWebhook; declare const snowflake: Snowflake; expectType>(webhook.send('content')); expectType>(webhook.editMessage(snowflake, 'content')); expectType>(webhook.fetchMessage(snowflake)); expectType>(webhookClient.send('content')); expectType>(webhookClient.editMessage(snowflake, 'content')); expectType>(webhookClient.fetchMessage(snowflake)); expectType>(interactionWebhook.send('content')); expectType>(interactionWebhook.editMessage(snowflake, 'content')); expectType>(interactionWebhook.fetchMessage(snowflake)); declare const categoryChannel: CategoryChannel; declare const forumChannel: ForumChannel; await forumChannel.edit({ availableTags: [...forumChannel.availableTags, { name: 'tag' }], }); await forumChannel.setAvailableTags([{ ...forumChannel.availableTags, name: 'tag' }]); await forumChannel.setAvailableTags([{ name: 'tag' }]); expectType>(textChannel.flags); expectType>(voiceChannel.flags); expectType>(stageChannel.flags); expectType>(forumChannel.flags); expectType>(dmChannel.flags); expectType>(categoryChannel.flags); expectType>(newsChannel.flags); expectType>(categoryChannel.flags); expectType>(threadChannel.flags); expectType(partialGroupDMChannel.flags); // Select menu type narrowing if (interaction.isAnySelectMenu()) { expectType(interaction); } declare const anySelectMenu: AnySelectMenuInteraction; if (anySelectMenu.isStringSelectMenu()) { expectType(anySelectMenu); } else if (anySelectMenu.isUserSelectMenu()) { expectType(anySelectMenu); } else if (anySelectMenu.isRoleSelectMenu()) { expectType(anySelectMenu); } else if (anySelectMenu.isChannelSelectMenu()) { expectType(anySelectMenu); } else if (anySelectMenu.isMentionableSelectMenu()) { expectType(anySelectMenu); } client.on('guildAuditLogEntryCreate', (auditLogEntry, guild) => { expectType(auditLogEntry); expectType(guild); }); expectType>(guildMember.flags); { const onboarding = await guild.fetchOnboarding(); expectType(onboarding); }