Files
discord.js/typings/index.ts
Antonio Román 985d4d6a43 refactor: removed code and split options (#5918)
Co-authored-by: Jan <66554238+vaporox@users.noreply.github.com>

BREAKING CHANGE: Removed `APIMessage#split`
BREAKING CHANGE: Removed `MessageEditOptions#code`
BREAKING CHANGE: Removed `BaseMessageOptions#code`
BREAKING CHANGE: Removed `BaseMessageOptions#split`
2021-06-26 23:11:40 +01:00

51 lines
1.5 KiB
TypeScript

/// <reference path="index.d.ts" />
import { Client, Intents, Message, MessageAttachment, MessageEmbed } 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<Message>) => 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');