(value: T, property: P & Exclude) => void;
-
-const client: Client = new Client({
- intents: Intents.FLAGS.GUILDS,
- makeCache: Options.cacheWithLimits({
- MessageManager: 200,
- // @ts-expect-error
- Message: 100,
- ThreadManager: {
- maxSize: 1000,
- keepOverLimit: (x: ThreadChannel) => x.id === '123',
- sweepInterval: 5000,
- sweepFilter: LimitedCollection.filterByLifetime({
- getComparisonTimestamp: (x: ThreadChannel) => x.archiveTimestamp ?? 0,
- excludeFromSweep: (x: ThreadChannel) => !x.archived,
- }),
- },
- }),
-});
-
-const testGuildId = '222078108977594368'; // DJS
-const testUserId = '987654321098765432'; // example id
-const globalCommandId = '123456789012345678'; // example id
-const guildCommandId = '234567890123456789'; // example id
-
-client.on('ready', async () => {
- 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);
-
- // @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;
- const originalPermissions = await client.application?.commands.permissions.fetch({ guild: testGuildId });
-
- // Permissions from global manager
- await globalPermissionsManager?.add({
- command: globalCommandId,
- guild: testGuildId,
- permissions: [{ type: 'ROLE', id: testGuildId, permission: true }],
- });
- 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] });
- await globalPermissionsManager?.remove({ command: globalCommandId, guild: testGuildId, users: [testUserId] });
- await globalPermissionsManager?.remove({
- command: globalCommandId,
- guild: testGuildId,
- roles: [testGuildId],
- users: [testUserId],
- });
- await globalPermissionsManager?.set({
- command: globalCommandId,
- guild: testGuildId,
- permissions: [{ type: 'ROLE', id: testGuildId, permission: true }],
- });
- await globalPermissionsManager?.set({
- guild: testGuildId,
- fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }],
- });
-
- // @ts-expect-error
- await globalPermissionsManager?.add({
- command: globalCommandId,
- permissions: [{ type: 'ROLE', id: testGuildId, permission: true }],
- });
- // @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] });
- // @ts-expect-error
- await globalPermissionsManager?.remove({ command: globalCommandId, users: [testUserId] });
- // @ts-expect-error
- await globalPermissionsManager?.remove({ command: globalCommandId, roles: [testGuildId], users: [testUserId] });
- // @ts-expect-error
- await globalPermissionsManager?.set({
- command: globalCommandId,
- permissions: [{ type: 'ROLE', id: testGuildId, permission: true }],
- });
- // @ts-expect-error
- await globalPermissionsManager?.set({
- fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }],
- });
- // @ts-expect-error
- await globalPermissionsManager?.set({
- command: globalCommandId,
- guild: testGuildId,
- fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }],
- });
-
- // @ts-expect-error
- await globalPermissionsManager?.add({
- guild: testGuildId,
- permissions: [{ type: 'ROLE', id: testGuildId, permission: true }],
- });
- // @ts-expect-error
- await globalPermissionsManager?.has({ guild: testGuildId, permissionId: testGuildId });
- // @ts-expect-error
- await globalPermissionsManager?.remove({ guild: testGuildId, roles: [testGuildId] });
- // @ts-expect-error
- await globalPermissionsManager?.remove({ guild: testGuildId, users: [testUserId] });
- // @ts-expect-error
- await globalPermissionsManager?.remove({ guild: testGuildId, roles: [testGuildId], users: [testUserId] });
- // @ts-expect-error
- await globalPermissionsManager?.set({
- guild: testGuildId,
- permissions: [{ type: 'ROLE', id: testGuildId, permission: true }],
- });
-
- // Permissions from guild manager
- await guildPermissionsManager?.add({
- command: globalCommandId,
- permissions: [{ type: 'ROLE', id: testGuildId, permission: true }],
- });
- await guildPermissionsManager?.has({ command: globalCommandId, permissionId: testGuildId });
- await guildPermissionsManager?.fetch({});
- await guildPermissionsManager?.fetch({ command: globalCommandId });
- await guildPermissionsManager?.remove({ command: globalCommandId, roles: [testGuildId] });
- await guildPermissionsManager?.remove({ command: globalCommandId, users: [testUserId] });
- await guildPermissionsManager?.remove({ command: globalCommandId, roles: [testGuildId], users: [testUserId] });
- await guildPermissionsManager?.set({
- command: globalCommandId,
- permissions: [{ type: 'ROLE', id: testGuildId, permission: true }],
- });
- await guildPermissionsManager?.set({
- fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }],
- });
-
- await guildPermissionsManager?.add({
- command: globalCommandId,
- // @ts-expect-error
- guild: testGuildId,
- permissions: [{ type: 'ROLE', id: testGuildId, permission: true }],
- });
- // @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 });
- // @ts-expect-error
- await guildPermissionsManager?.remove({ command: globalCommandId, guild: testGuildId, roles: [testGuildId] });
- // @ts-expect-error
- await guildPermissionsManager?.remove({ command: globalCommandId, guild: testGuildId, users: [testUserId] });
- await guildPermissionsManager?.remove({
- command: globalCommandId,
- // @ts-expect-error
- guild: testGuildId,
- roles: [testGuildId],
- users: [testUserId],
- });
- // @ts-expect-error
- await guildPermissionsManager?.set({
- command: globalCommandId,
- guild: testGuildId,
- permissions: [{ type: 'ROLE', id: testGuildId, permission: true }],
- });
- await guildPermissionsManager?.set({
- // @ts-expect-error
- guild: testGuildId,
- fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }],
- });
-
- // @ts-expect-error
- await guildPermissionsManager?.add({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] });
- // @ts-expect-error
- await guildPermissionsManager?.has({ permissionId: testGuildId });
- // @ts-expect-error
- await guildPermissionsManager?.remove({ roles: [testGuildId] });
- // @ts-expect-error
- await guildPermissionsManager?.remove({ users: [testUserId] });
- // @ts-expect-error
- await guildPermissionsManager?.remove({ roles: [testGuildId], users: [testUserId] });
- // @ts-expect-error
- await guildPermissionsManager?.set({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] });
- // @ts-expect-error
- await guildPermissionsManager?.set({
- command: globalCommandId,
- fullPermissions: [{ id: globalCommandId, permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] }],
- });
-
- // Permissions from cached global ApplicationCommand
- await globalCommand?.permissions.add({
- guild: testGuildId,
- permissions: [{ type: 'ROLE', id: testGuildId, permission: true }],
- });
- await globalCommand?.permissions.has({ guild: testGuildId, permissionId: testGuildId });
- await globalCommand?.permissions.fetch({ guild: testGuildId });
- await globalCommand?.permissions.remove({ guild: testGuildId, roles: [testGuildId] });
- await globalCommand?.permissions.remove({ guild: testGuildId, users: [testUserId] });
- await globalCommand?.permissions.remove({ guild: testGuildId, roles: [testGuildId], users: [testUserId] });
- await globalCommand?.permissions.set({
- guild: testGuildId,
- permissions: [{ type: 'ROLE', id: testGuildId, permission: true }],
- });
-
- await globalCommand?.permissions.add({
- // @ts-expect-error
- command: globalCommandId,
- guild: testGuildId,
- permissions: [{ type: 'ROLE', id: testGuildId, permission: true }],
- });
- // @ts-expect-error
- await globalCommand?.permissions.has({ command: globalCommandId, guild: testGuildId, permissionId: testGuildId });
- // @ts-expect-error
- await globalCommand?.permissions.fetch({ command: globalCommandId, guild: testGuildId });
- // @ts-expect-error
- await globalCommand?.permissions.remove({ command: globalCommandId, guild: testGuildId, roles: [testGuildId] });
- // @ts-expect-error
- await globalCommand?.permissions.remove({ command: globalCommandId, guild: testGuildId, users: [testUserId] });
- await globalCommand?.permissions.remove({
- // @ts-expect-error
- command: globalCommandId,
- guild: testGuildId,
- roles: [testGuildId],
- users: [testUserId],
- });
- await globalCommand?.permissions.set({
- // @ts-expect-error
- command: globalCommandId,
- guild: testGuildId,
- permissions: [{ type: 'ROLE', id: testGuildId, permission: true }],
- });
-
- // @ts-expect-error
- await globalCommand?.permissions.add({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] });
- // @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] });
- // @ts-expect-error
- await globalCommand?.permissions.remove({ users: [testUserId] });
- // @ts-expect-error
- await globalCommand?.permissions.remove({ roles: [testGuildId], users: [testUserId] });
- // @ts-expect-error
- await globalCommand?.permissions.set({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] });
-
- // Permissions from cached guild ApplicationCommand
- await guildCommandFromGlobal?.permissions.add({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] });
- await guildCommandFromGlobal?.permissions.has({ permissionId: testGuildId });
- await guildCommandFromGlobal?.permissions.fetch({});
- await guildCommandFromGlobal?.permissions.remove({ roles: [testGuildId] });
- await guildCommandFromGlobal?.permissions.remove({ users: [testUserId] });
- await guildCommandFromGlobal?.permissions.remove({ roles: [testGuildId], users: [testUserId] });
- await guildCommandFromGlobal?.permissions.set({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] });
-
- await guildCommandFromGlobal?.permissions.add({
- // @ts-expect-error
- command: globalCommandId,
- permissions: [{ type: 'ROLE', id: testGuildId, permission: true }],
- });
- // @ts-expect-error
- await guildCommandFromGlobal?.permissions.has({ command: guildCommandId, permissionId: testGuildId });
- // @ts-expect-error
- await guildCommandFromGlobal?.permissions.remove({ command: guildCommandId, roles: [testGuildId] });
- // @ts-expect-error
- await guildCommandFromGlobal?.permissions.remove({ command: guildCommandId, users: [testUserId] });
- await guildCommandFromGlobal?.permissions.remove({
- // @ts-expect-error
- command: guildCommandId,
- roles: [testGuildId],
- users: [testUserId],
- });
- await guildCommandFromGlobal?.permissions.set({
- // @ts-expect-error
- command: guildCommandId,
- permissions: [{ type: 'ROLE', id: testGuildId, permission: true }],
- });
-
- await guildCommandFromGlobal?.permissions.add({
- // @ts-expect-error
- guild: testGuildId,
- permissions: [{ type: 'ROLE', id: testGuildId, permission: true }],
- });
- // @ts-expect-error
- await guildCommandFromGlobal?.permissions.has({ guild: testGuildId, permissionId: testGuildId });
- // @ts-expect-error
- await guildCommandFromGlobal?.permissions.remove({ guild: testGuildId, roles: [testGuildId] });
- // @ts-expect-error
- await guildCommandFromGlobal?.permissions.remove({ guild: testGuildId, users: [testUserId] });
- // @ts-expect-error
- await guildCommandFromGlobal?.permissions.remove({ guild: testGuildId, roles: [testGuildId], users: [testUserId] });
- await guildCommandFromGlobal?.permissions.set({
- // @ts-expect-error
- guild: testGuildId,
- permissions: [{ type: 'ROLE', id: testGuildId, permission: true }],
- });
-
- await guildCommandFromGuild?.permissions.add({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] });
- await guildCommandFromGuild?.permissions.has({ permissionId: testGuildId });
- await guildCommandFromGuild?.permissions.fetch({});
- await guildCommandFromGuild?.permissions.remove({ roles: [testGuildId] });
- await guildCommandFromGuild?.permissions.remove({ users: [testUserId] });
- await guildCommandFromGuild?.permissions.remove({ roles: [testGuildId], users: [testUserId] });
- await guildCommandFromGuild?.permissions.set({ permissions: [{ type: 'ROLE', id: testGuildId, permission: true }] });
-
- await guildCommandFromGuild?.permissions.add({
- // @ts-expect-error
- command: globalCommandId,
- permissions: [{ type: 'ROLE', id: testGuildId, permission: true }],
- });
- // @ts-expect-error
- await guildCommandFromGuild?.permissions.has({ command: guildCommandId, permissionId: testGuildId });
- // @ts-expect-error
- await guildCommandFromGuild?.permissions.remove({ command: guildCommandId, roles: [testGuildId] });
- // @ts-expect-error
- await guildCommandFromGuild?.permissions.remove({ command: guildCommandId, users: [testUserId] });
- await guildCommandFromGuild?.permissions.remove({
- // @ts-expect-error
- command: guildCommandId,
- roles: [testGuildId],
- users: [testUserId],
- });
- await guildCommandFromGuild?.permissions.set({
- // @ts-expect-error
- command: guildCommandId,
- permissions: [{ type: 'ROLE', id: testGuildId, permission: true }],
- });
-
- await guildCommandFromGuild?.permissions.add({
- // @ts-expect-error
- guild: testGuildId,
- permissions: [{ type: 'ROLE', id: testGuildId, permission: true }],
- });
- // @ts-expect-error
- await guildCommandFromGuild?.permissions.has({ guild: testGuildId, permissionId: testGuildId });
- // @ts-expect-error
- await guildCommandFromGuild?.permissions.remove({ guild: testGuildId, roles: [testGuildId] });
- // @ts-expect-error
- await guildCommandFromGuild?.permissions.remove({ guild: testGuildId, users: [testUserId] });
- // @ts-expect-error
- await guildCommandFromGuild?.permissions.remove({ guild: testGuildId, roles: [testGuildId], users: [testUserId] });
- await guildCommandFromGuild?.permissions.set({
- // @ts-expect-error
- guild: testGuildId,
- permissions: [{ type: 'ROLE', id: testGuildId, permission: true }],
- });
-
- client.application?.commands.permissions.set({
- guild: testGuildId,
- fullPermissions: originalPermissions?.map((permissions, id) => ({ permissions, id })) ?? [],
- });
-});
-
-client.on('guildCreate', async g => {
- const channel = g.channels.cache.random();
- if (!channel) return;
-
- if (channel.isThread()) {
- const fetchedMember = await channel.members.fetch('12345678');
- expectType(fetchedMember);
- const fetchedMemberCol = await channel.members.fetch(true);
- expectDeprecated(await channel.members.fetch(true));
- expectType>(fetchedMemberCol);
- }
-
- 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.on('messageReactionRemoveAll', async message => {
- console.log(`messageReactionRemoveAll - id: ${message.id} (${message.id.length})`);
-
- if (message.partial) message = await message.fetch();
-
- console.log(`messageReactionRemoveAll - content: ${message.content}`);
-});
-
-// This is to check that stuff is the right type
-declare const assertIsMessage: (m: Promise) => void;
-
-client.on('messageCreate', async message => {
- const { channel } = message;
- assertIsMessage(channel.send('string'));
- assertIsMessage(channel.send({}));
- assertIsMessage(channel.send({ embeds: [] }));
-
- const attachment = new MessageAttachment('file.png');
- const embed = new MessageEmbed();
- 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: 'BUTTON' });
- expectType>(component);
- expectType>(await component.reply({ fetchReply: true }));
-
- const buttonCollector = message.createMessageComponentCollector({ componentType: 'BUTTON' });
- expectType>>(buttonCollector);
- expectAssignable<(test: ButtonInteraction<'cached'>) => boolean | Promise>(buttonCollector.filter);
- expectType(message.channel);
- expectType(message.guild);
- expectType(message.member);
- }
-
- 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: 'BUTTON' });
- expectAssignable>(message.awaitMessageComponent({ componentType: 'BUTTON' }));
- expectAssignable>(channel.awaitMessageComponent({ componentType: 'BUTTON' }));
- expectAssignable>(buttonCollector);
-
- // Verify that select menus interaction are inferred.
- const selectMenuCollector = message.createMessageComponentCollector({ componentType: 'SELECT_MENU' });
- expectAssignable>(message.awaitMessageComponent({ componentType: 'SELECT_MENU' }));
- expectAssignable>(channel.awaitMessageComponent({ componentType: 'SELECT_MENU' }));
- 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.
-
- // @ts-expect-error
- const interactionOptions = message.createMessageComponentCollector({ interactionType: 'APPLICATION_COMMAND' });
-
- // Make sure filter parameters are properly inferred.
- message.createMessageComponentCollector({
- filter: i => {
- expectType(i);
- return true;
- },
- });
-
- message.createMessageComponentCollector({
- componentType: 'BUTTON',
- filter: i => {
- expectType(i);
- return true;
- },
- });
-
- message.createMessageComponentCollector({
- componentType: 'SELECT_MENU',
- filter: i => {
- expectType(i);
- return true;
- },
- });
-
- message.awaitMessageComponent({
- filter: i => {
- expectType(i);
- return true;
- },
- });
-
- message.awaitMessageComponent({
- componentType: 'BUTTON',
- filter: i => {
- expectType(i);
- return true;
- },
- });
-
- message.awaitMessageComponent({
- componentType: 'SELECT_MENU',
- 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: 'BUTTON',
- filter: i => {
- expectType>(i);
- return true;
- },
- });
-
- channel.awaitMessageComponent({
- componentType: 'SELECT_MENU',
- filter: i => {
- expectType>(i);
- return true;
- },
- });
-});
-
-client.on('interaction', async interaction => {
- expectType(interaction.guildId);
- expectType(interaction.channelId);
- expectType(interaction.member);
-
- if (!interaction.isCommand()) return;
-
- void new MessageActionRow();
-
- const button = new MessageButton();
-
- const actionRow = new MessageActionRow({ components: [button] });
-
- await interaction.reply({ content: 'Hi!', components: [actionRow] });
-
- // @ts-expect-error
- interaction.reply({ content: 'Hi!', components: [[button]] });
-
- // @ts-expect-error
- void new MessageActionRow({});
-
- // @ts-expect-error
- await interaction.reply({ content: 'Hi!', components: [button] });
-
- if (interaction.isMessageComponent()) {
- expectType(interaction.channelId);
- }
-});
-
-client.login('absolutely-valid-token');
-
-// Test client conditional types
-client.on('ready', client => {
- expectType>(client);
-});
-
-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 Permissions(Permissions.FLAGS.ATTACH_FILES)));
-expectType(serialize(new Intents(Intents.FLAGS.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 newsChannel: NewsChannel;
-declare const textChannel: TextChannel;
-declare const storeChannel: StoreChannel;
-declare const voiceChannel: VoiceChannel;
-declare const guild: Guild;
-declare const user: User;
-declare const guildMember: GuildMember;
-
-// Test whether the structures implement send
-expectType(dmChannel.send);
-expectType(threadChannel);
-expectType(newsChannel);
-expectType(textChannel);
-expectAssignable(user);
-expectAssignable(guildMember);
-
-expectType(dmChannel.lastMessage);
-expectType(threadChannel.lastMessage);
-expectType(newsChannel.lastMessage);
-expectType(textChannel.lastMessage);
-
-expectDeprecated(storeChannel.clone());
-expectDeprecated(categoryChannel.createChannel('Store', { type: 'GUILD_STORE' }));
-expectDeprecated(guild.channels.create('Store', { type: 'GUILD_STORE' }));
-
-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]>(args);
-});
-
-declare const reactionCollector: ReactionCollector;
-reactionCollector.on('dispose', (...args) => {
- expectType<[MessageReaction, User]>(args);
-});
-
-// Make sure the properties are typed correctly, and that no backwards properties
-// (K -> V and V -> K) exist:
-expectType<'messageCreate'>(Constants.Events.MESSAGE_CREATE);
-expectType<'close'>(Constants.ShardEvents.CLOSE);
-expectType<1>(Constants.Status.CONNECTING);
-expectType<0>(Constants.Opcodes.DISPATCH);
-expectType<2>(Constants.ClientApplicationAssetTypes.BIG);
-
-declare const applicationCommandData: ApplicationCommandData;
-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], '0'),
- );
-}
-
-declare const applicationNonChoiceOptionData: ApplicationCommandOptionData & {
- type: CommandOptionNonChoiceResolvableType;
-};
-{
- // Options aren't allowed on this command type.
-
- // @ts-expect-error
- applicationNonChoiceOptionData.choices;
-}
-
-declare const applicationSubGroupCommandData: ApplicationCommandSubGroupData;
-{
- expectType<'SUB_COMMAND_GROUP' | ApplicationCommandOptionTypes.SUB_COMMAND_GROUP>(
- applicationSubGroupCommandData.type,
- );
- expectType(applicationSubGroupCommandData.options);
-}
-
-declare const guildApplicationCommandManager: GuildApplicationCommandManager;
-expectType>>(guildApplicationCommandManager.fetch());
-expectType>>(guildApplicationCommandManager.fetch(undefined, {}));
-expectType>(guildApplicationCommandManager.fetch('0'));
-
-declare const categoryChannel: CategoryChannel;
-{
- expectType>(categoryChannel.createChannel('name', { type: 'GUILD_VOICE' }));
- expectType>(categoryChannel.createChannel('name', { type: 'GUILD_TEXT' }));
- expectType>(categoryChannel.createChannel('name', { type: 'GUILD_NEWS' }));
- expectType>(categoryChannel.createChannel('name', { type: 'GUILD_STORE' }));
- expectType>(categoryChannel.createChannel('name', { type: 'GUILD_STAGE_VOICE' }));
- expectType>(categoryChannel.createChannel('name', {}));
- expectType>(categoryChannel.createChannel('name'));
-}
-
-declare const guildChannelManager: GuildChannelManager;
-{
- type AnyChannel = TextChannel | VoiceChannel | CategoryChannel | NewsChannel | StoreChannel | StageChannel;
-
- expectType>(guildChannelManager.create('name', { type: 'GUILD_VOICE' }));
- expectType>(guildChannelManager.create('name', { type: 'GUILD_CATEGORY' }));
- expectType>(guildChannelManager.create('name', { type: 'GUILD_TEXT' }));
- expectType>(guildChannelManager.create('name', { type: 'GUILD_NEWS' }));
- expectType>(guildChannelManager.create('name', { type: 'GUILD_STORE' }));
- expectType>(guildChannelManager.create('name', { type: 'GUILD_STAGE_VOICE' }));
-
- expectType>>(guildChannelManager.fetch());
- expectType>>(guildChannelManager.fetch(undefined, {}));
- expectType>(guildChannelManager.fetch('0'));
-}
-
-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 typing: Typing;
-expectType(typing.user);
-if (typing.user.partial) expectType(typing.user.username);
-
-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 partials structures
-client.on('guildMemberRemove', member => {
- if (member.partial) return expectType(member.joinedAt);
- expectType(member.joinedAt);
-});
-
-client.on('messageReactionAdd', async reaction => {
- 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);
-});
-
-// Test .deleted deprecations
-declare const emoji: Emoji;
-declare const message: Message;
-declare const role: Role;
-declare const stageInstance: StageInstance;
-declare const sticker: Sticker;
-expectDeprecated(dmChannel.deleted);
-expectDeprecated(textChannel.deleted);
-expectDeprecated(voiceChannel.deleted);
-expectDeprecated(newsChannel.deleted);
-expectDeprecated(threadChannel.deleted);
-expectDeprecated(emoji.deleted);
-expectDeprecated(guildMember.deleted);
-expectDeprecated(guild.deleted);
-expectDeprecated(message.deleted);
-expectDeprecated(role.deleted);
-expectDeprecated(stageInstance.deleted);
-expectDeprecated(sticker.deleted);
-
-// Test interactions
-declare const interaction: Interaction;
-declare const booleanValue: boolean;
-if (interaction.inGuild()) expectType(interaction.guildId);
-
-client.on('interactionCreate', async interaction => {
- 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.isContextMenu()) {
- expectType(interaction);
- if (interaction.inCachedGuild()) {
- expectAssignable(interaction);
- expectAssignable(interaction.guild);
- expectAssignable>(interaction);
- } else if (interaction.inRawGuild()) {
- expectAssignable(interaction);
- expectType(interaction.guild);
- } else if (interaction.inGuild()) {
- expectAssignable(interaction);
- expectType(interaction.guild);
- }
- }
-
- if (interaction.isMessageContextMenu()) {
- 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.isButton()) {
- expectType(interaction);
- expectType(interaction.component);
- expectType(interaction.message);
- if (interaction.inCachedGuild()) {
- expectAssignable(interaction);
- expectType(interaction.component);
- expectType>(interaction.message);
- expectType(interaction.guild);
- expectAssignable>(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.isMessageComponent()) {
- expectType(interaction);
- expectType(interaction.component);
- expectType(interaction.message);
- if (interaction.inCachedGuild()) {
- expectAssignable(interaction);
- expectType(interaction.component);
- expectType>(interaction.message);
- expectType(interaction.guild);
- expectAssignable>(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.isSelectMenu()) {
- 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.isCommand()) {
- if (interaction.inRawGuild()) {
- expectNotAssignable>(interaction);
- expectAssignable(interaction);
- expectType>(interaction.reply({ fetchReply: true }));
- expectType(interaction.options.getMember('test'));
- expectType(interaction.options.getMember('test', true));
-
- 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: 'BUTTON' });
-
- expectType>(msg);
- expectType