/// import { Client, Collection, Intents, Message, MessageAttachment, MessageEmbed, Permissions, Serialized, ShardClientUtil, ShardingManager, } from 'discord.js'; const client: Client = new Client({ intents: Intents.NON_PRIVILEGED, }); client.on('ready', () => { console.log(`Client is logged in as ${client.user!.tag} and ready!`); }); client.on('guildCreate', g => { const channel = g.channels.cache.random(); if (!channel) return; channel.setName('foo').then(updatedChannel => { console.log(`New channel name: ${updatedChannel.name}`); }); }); 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('message', ({ channel }) => { 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] })); // @ts-expect-error channel.send(); // @ts-expect-error channel.send({ another: 'property' }); }); client.login('absolutely-valid-token'); // Test type transformation: declare const assertType: (value: T) => asserts value is T; declare const serialize: (value: T) => Serialized; assertType(serialize(undefined)); assertType(serialize(null)); assertType(serialize([1, 2, 3])); assertType<{}>(serialize(new Set([1, 2, 3]))); assertType<{}>( serialize( new Map([ [1, '2'], [2, '4'], ]), ), ); assertType(serialize(new Permissions(Permissions.FLAGS.ATTACH_FILES))); assertType(serialize(new Intents(Intents.FLAGS.GUILDS))); assertType( serialize( new Collection([ [1, '2'], [2, '4'], ]), ), ); assertType(serialize(Symbol('a'))); assertType(serialize(() => {})); assertType(serialize(BigInt(42))); // Test type return of broadcastEval: declare const shardClientUtil: ShardClientUtil; declare const shardingManager: ShardingManager; assertType>(shardingManager.broadcastEval(() => 1)); assertType>(shardClientUtil.broadcastEval(() => 1)); assertType>(shardingManager.broadcastEval(async () => 1)); assertType>(shardClientUtil.broadcastEval(async () => 1));