index.ts
1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/// <reference path="index.d.ts" />
import { Client, Message, MessageAttachment, MessageEmbed } from 'discord.js';
const client: Client = new Client();
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}`);
});
// These are to check that stuff is the right type
declare const assertIsMessage: (m: Promise<Message>) => void;
declare const assertIsMessageArray: (m: Promise<Message[]>) => void;
client.on('message', ({ channel }) => {
assertIsMessage(channel.send('string'));
assertIsMessage(channel.send({}));
assertIsMessage(channel.send({ embed: {} }));
assertIsMessage(channel.send({ another: 'property' }, {}));
const attachment = new MessageAttachment('file.png');
const embed = new MessageEmbed();
assertIsMessage(channel.send(attachment));
assertIsMessage(channel.send(embed));
assertIsMessage(channel.send([attachment, embed]));
assertIsMessageArray(channel.send(Symbol('another primitive'), { split: true }));
assertIsMessageArray(channel.send({ split: true }));
// @ts-expect-error
channel.send();
// @ts-expect-error
channel.send({ another: 'property' });
});
client.login('absolutely-valid-token');