chapterjs 0.0.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/cli.d.ts +2 -0
- package/dist/cli/cli.js +33 -0
- package/dist/cli/dev.d.ts +1 -0
- package/dist/cli/dev.js +206 -0
- package/dist/components.d.ts +97 -0
- package/dist/components.js +260 -0
- package/dist/context.d.ts +72 -0
- package/dist/context.js +273 -0
- package/dist/discord/client.d.ts +35 -0
- package/dist/discord/client.js +66 -0
- package/dist/discord/constants.d.ts +49 -0
- package/dist/discord/constants.js +61 -0
- package/dist/discord/events.d.ts +129 -0
- package/dist/discord/events.js +102 -0
- package/dist/discord/gateway.d.ts +61 -0
- package/dist/discord/gateway.js +320 -0
- package/dist/discord/payloads.d.ts +275 -0
- package/dist/discord/payloads.js +3 -0
- package/dist/discord/presence.d.ts +42 -0
- package/dist/discord/presence.js +51 -0
- package/dist/discord/rest.d.ts +49 -0
- package/dist/discord/rest.js +271 -0
- package/dist/discord/types.d.ts +334 -0
- package/dist/discord/types.js +4 -0
- package/dist/events.d.ts +94 -0
- package/dist/events.js +255 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +12 -0
- package/dist/presence.d.ts +92 -0
- package/dist/presence.js +250 -0
- package/dist/structures/Channel.d.ts +110 -0
- package/dist/structures/Channel.js +171 -0
- package/dist/structures/Guild.d.ts +70 -0
- package/dist/structures/Guild.js +105 -0
- package/dist/structures/Interaction.d.ts +113 -0
- package/dist/structures/Interaction.js +274 -0
- package/dist/structures/Member.d.ts +70 -0
- package/dist/structures/Member.js +124 -0
- package/dist/structures/Message.d.ts +87 -0
- package/dist/structures/Message.js +182 -0
- package/dist/structures/Reaction.d.ts +38 -0
- package/dist/structures/Reaction.js +64 -0
- package/dist/structures/Role.d.ts +43 -0
- package/dist/structures/Role.js +77 -0
- package/dist/structures/User.d.ts +41 -0
- package/dist/structures/User.js +79 -0
- package/dist/structures/utils.d.ts +72 -0
- package/dist/structures/utils.js +59 -0
- package/dist/utils/errors.d.ts +5 -0
- package/dist/utils/errors.js +28 -0
- package/dist/utils/modules.d.ts +39 -0
- package/dist/utils/modules.js +156 -0
- package/package.json +30 -5
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Guild } from './Guild.js';
|
|
2
|
+
import { User } from './User.js';
|
|
3
|
+
import { cdnUrl, toDate, } from './utils.js';
|
|
4
|
+
/** Longest timeout Discord accepts: 28 days. */
|
|
5
|
+
const MAX_TIMEOUT = 28 * 24 * 60 * 60 * 1000;
|
|
6
|
+
/**
|
|
7
|
+
* A user in a server.
|
|
8
|
+
* https://docs.discord.com/developers/resources/guild#guild-member-object
|
|
9
|
+
*/
|
|
10
|
+
export class Member {
|
|
11
|
+
client;
|
|
12
|
+
guildId;
|
|
13
|
+
raw;
|
|
14
|
+
id;
|
|
15
|
+
user;
|
|
16
|
+
/** Nickname in this server. */
|
|
17
|
+
nick;
|
|
18
|
+
/** Role ids, without the @everyone role. */
|
|
19
|
+
roles;
|
|
20
|
+
joinedAt;
|
|
21
|
+
/** When the member started boosting the server. */
|
|
22
|
+
premiumSince;
|
|
23
|
+
/** True until the member passes Membership Screening. */
|
|
24
|
+
pending;
|
|
25
|
+
/** Server avatar hash, if the member set one. */
|
|
26
|
+
avatar;
|
|
27
|
+
/** End of the member's timeout, null when not timed out. */
|
|
28
|
+
communicationDisabledUntil;
|
|
29
|
+
/** Permissions in the channel, sent with interactions only. */
|
|
30
|
+
permissions;
|
|
31
|
+
constructor(client, guildId, raw) {
|
|
32
|
+
this.client = client;
|
|
33
|
+
this.guildId = guildId;
|
|
34
|
+
this.raw = raw;
|
|
35
|
+
this.user = new User(client, raw.user);
|
|
36
|
+
this.id = this.user.id;
|
|
37
|
+
this.nick = raw.nick ?? null;
|
|
38
|
+
this.roles = raw.roles;
|
|
39
|
+
this.joinedAt = toDate(raw.joined_at);
|
|
40
|
+
this.premiumSince = toDate(raw.premium_since);
|
|
41
|
+
this.pending = raw.pending ?? false;
|
|
42
|
+
this.avatar = raw.avatar ?? null;
|
|
43
|
+
this.communicationDisabledUntil = toDate(raw.communication_disabled_until);
|
|
44
|
+
this.permissions = raw.permissions;
|
|
45
|
+
}
|
|
46
|
+
get guild() {
|
|
47
|
+
return new Guild(this.client, { id: this.guildId });
|
|
48
|
+
}
|
|
49
|
+
/** Name shown in this server: nickname, display name or username. */
|
|
50
|
+
get displayName() {
|
|
51
|
+
return this.nick ?? this.user.displayName;
|
|
52
|
+
}
|
|
53
|
+
get isTimedOut() {
|
|
54
|
+
return (this.communicationDisabledUntil?.getTime() ?? 0) > Date.now();
|
|
55
|
+
}
|
|
56
|
+
hasRole(roleId) {
|
|
57
|
+
return this.roles.includes(roleId);
|
|
58
|
+
}
|
|
59
|
+
/** Mention, e.g. `${member}` in a message. */
|
|
60
|
+
toString() {
|
|
61
|
+
return `<@${this.id}>`;
|
|
62
|
+
}
|
|
63
|
+
// https://docs.discord.com/developers/reference#image-formatting-cdn-endpoints
|
|
64
|
+
/** Avatar shown in this server: server avatar, user avatar or default avatar. */
|
|
65
|
+
displayAvatarURL(options) {
|
|
66
|
+
return this.avatar
|
|
67
|
+
? cdnUrl(`guilds/${this.guildId}/users/${this.id}/avatars`, this.avatar, options)
|
|
68
|
+
: this.user.displayAvatarURL(options);
|
|
69
|
+
}
|
|
70
|
+
/** Sends a direct message. */
|
|
71
|
+
send(options) {
|
|
72
|
+
return this.user.send(options);
|
|
73
|
+
}
|
|
74
|
+
kick(reason) {
|
|
75
|
+
return this.guild.kick(this.id, reason);
|
|
76
|
+
}
|
|
77
|
+
ban(options) {
|
|
78
|
+
return this.guild.ban(this.id, options);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Times the member out for `duration` milliseconds (up to 28 days), or
|
|
82
|
+
* removes the timeout with null.
|
|
83
|
+
* https://docs.discord.com/developers/resources/guild#modify-guild-member
|
|
84
|
+
*/
|
|
85
|
+
timeout(duration, reason) {
|
|
86
|
+
if (duration !== null && !(duration > 0 && duration <= MAX_TIMEOUT)) {
|
|
87
|
+
return Promise.reject(new Error(`timeout(): duration is ${duration}, it must be a number of milliseconds between 1 and 28 days, ` +
|
|
88
|
+
'e.g. 10 * 60_000 for 10 minutes (or null to remove the timeout).'));
|
|
89
|
+
}
|
|
90
|
+
const until = duration === null ? null : new Date(Date.now() + duration).toISOString();
|
|
91
|
+
return this.edit({ communication_disabled_until: until }, reason);
|
|
92
|
+
}
|
|
93
|
+
/** Null removes the nickname. */
|
|
94
|
+
setNickname(nick, reason) {
|
|
95
|
+
return this.edit({ nick }, reason);
|
|
96
|
+
}
|
|
97
|
+
/** https://docs.discord.com/developers/resources/guild#add-guild-member-role */
|
|
98
|
+
async addRole(roleId, reason) {
|
|
99
|
+
await this.client.rest.put(`/guilds/${this.guildId}/members/${this.id}/roles/${roleId}`, {
|
|
100
|
+
reason,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/** https://docs.discord.com/developers/resources/guild#remove-guild-member-role */
|
|
104
|
+
async removeRole(roleId, reason) {
|
|
105
|
+
await this.client.rest.delete(`/guilds/${this.guildId}/members/${this.id}/roles/${roleId}`, {
|
|
106
|
+
reason,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Updates the member with fields of the documented JSON params (snake_case:
|
|
111
|
+
* nick, roles, mute, deaf, channel_id, communication_disabled_until, flags).
|
|
112
|
+
* https://docs.discord.com/developers/resources/guild#modify-guild-member
|
|
113
|
+
*/
|
|
114
|
+
async edit(data, reason) {
|
|
115
|
+
const member = await this.client.rest.patch(`/guilds/${this.guildId}/members/${this.id}`, { body: data, reason });
|
|
116
|
+
return new Member(this.client, this.guildId, {
|
|
117
|
+
...member,
|
|
118
|
+
user: member.user ?? this.raw.user,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
async fetch() {
|
|
122
|
+
return this.guild.fetchMember(this.id);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { Client } from '../discord/client.js';
|
|
2
|
+
import type { APIMessage, Snowflake } from '../discord/types.js';
|
|
3
|
+
import { Channel, type CreateThreadOptions } from './Channel.js';
|
|
4
|
+
import { Guild } from './Guild.js';
|
|
5
|
+
import { Member } from './Member.js';
|
|
6
|
+
import { User } from './User.js';
|
|
7
|
+
import { type MessageOptions, type ReplyOptions } from './utils.js';
|
|
8
|
+
/** A unicode emoji (`'👍'`), a custom one (`'<:name:id>'` or `'name:id'`) or an emoji object. */
|
|
9
|
+
export type EmojiResolvable = string | {
|
|
10
|
+
id: Snowflake | null;
|
|
11
|
+
name: string | null;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A message. `raw` holds every field sent by Discord (embeds, components,
|
|
15
|
+
* attachments…).
|
|
16
|
+
* https://docs.discord.com/developers/resources/message#message-object
|
|
17
|
+
*/
|
|
18
|
+
export declare class Message {
|
|
19
|
+
#private;
|
|
20
|
+
readonly client: Client;
|
|
21
|
+
readonly raw: APIMessage;
|
|
22
|
+
readonly id: Snowflake;
|
|
23
|
+
readonly channelId: Snowflake;
|
|
24
|
+
/** Null in DMs and for ephemeral messages. */
|
|
25
|
+
readonly guildId: Snowflake | null;
|
|
26
|
+
/** For webhook messages, holds the webhook's id, username and avatar. */
|
|
27
|
+
readonly author: User;
|
|
28
|
+
/** Author as a server member. Null in DMs, for webhooks and ephemeral messages. */
|
|
29
|
+
readonly member: Member | null;
|
|
30
|
+
/** Empty without the MessageContent intent, except in DMs and when the bot is mentioned. */
|
|
31
|
+
readonly content: string;
|
|
32
|
+
readonly createdAt: Date;
|
|
33
|
+
readonly editedAt: Date | null;
|
|
34
|
+
readonly tts: boolean;
|
|
35
|
+
readonly pinned: boolean;
|
|
36
|
+
/** https://docs.discord.com/developers/resources/message#message-object-message-types */
|
|
37
|
+
readonly type: number;
|
|
38
|
+
/** https://docs.discord.com/developers/resources/message#message-object-message-flags */
|
|
39
|
+
readonly flags: number;
|
|
40
|
+
readonly webhookId: Snowflake | null;
|
|
41
|
+
readonly mentions: User[];
|
|
42
|
+
readonly mentionRoles: Snowflake[];
|
|
43
|
+
readonly mentionEveryone: boolean;
|
|
44
|
+
/** https://docs.discord.com/developers/resources/message#attachment-object */
|
|
45
|
+
readonly attachments: unknown[];
|
|
46
|
+
/** https://docs.discord.com/developers/resources/message#embed-object */
|
|
47
|
+
readonly embeds: unknown[];
|
|
48
|
+
readonly components: unknown[];
|
|
49
|
+
/** Message replied to: null if it was deleted, undefined if not a reply or not sent. */
|
|
50
|
+
readonly referencedMessage: Message | null | undefined;
|
|
51
|
+
constructor(client: Client, raw: APIMessage);
|
|
52
|
+
get channel(): Channel;
|
|
53
|
+
/** Server of the message, null in DMs. */
|
|
54
|
+
get guild(): Guild | null;
|
|
55
|
+
get url(): string;
|
|
56
|
+
/**
|
|
57
|
+
* Replies to the message.
|
|
58
|
+
* https://docs.discord.com/developers/resources/message#message-reference-structure
|
|
59
|
+
*/
|
|
60
|
+
reply(options: ReplyOptions): Promise<Message>;
|
|
61
|
+
/** Only the bot's own messages can have their content edited. https://docs.discord.com/developers/resources/message#edit-message */
|
|
62
|
+
edit(options: MessageOptions): Promise<Message>;
|
|
63
|
+
/** https://docs.discord.com/developers/resources/message#delete-message */
|
|
64
|
+
delete(reason?: string): Promise<void>;
|
|
65
|
+
/** https://docs.discord.com/developers/resources/message#create-reaction */
|
|
66
|
+
react(emoji: EmojiResolvable): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Removes the bot's reaction, or the reaction of `userId`.
|
|
69
|
+
* https://docs.discord.com/developers/resources/message#delete-user-reaction
|
|
70
|
+
*/
|
|
71
|
+
removeReaction(emoji: EmojiResolvable, userId?: Snowflake): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Removes every reaction, or every reaction with `emoji`.
|
|
74
|
+
* https://docs.discord.com/developers/resources/message#delete-all-reactions
|
|
75
|
+
*/
|
|
76
|
+
removeAllReactions(emoji?: EmojiResolvable): Promise<void>;
|
|
77
|
+
/** https://docs.discord.com/developers/resources/message#pin-message */
|
|
78
|
+
pin(reason?: string): Promise<void>;
|
|
79
|
+
/** https://docs.discord.com/developers/resources/message#unpin-message */
|
|
80
|
+
unpin(reason?: string): Promise<void>;
|
|
81
|
+
/** Publishes a message of an announcement channel to the following servers. */
|
|
82
|
+
crosspost(): Promise<Message>;
|
|
83
|
+
/** https://docs.discord.com/developers/resources/channel#start-thread-from-message */
|
|
84
|
+
startThread(options: Omit<CreateThreadOptions, 'type' | 'invitable'>): Promise<Channel>;
|
|
85
|
+
/** https://docs.discord.com/developers/resources/message#get-channel-message */
|
|
86
|
+
fetch(): Promise<Message>;
|
|
87
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
import { Channel, toThreadBody } from './Channel.js';
|
|
3
|
+
import { Guild } from './Guild.js';
|
|
4
|
+
import { Member } from './Member.js';
|
|
5
|
+
import { User } from './User.js';
|
|
6
|
+
import { encodeEmoji, toAllowedMentions, toDate, toMessageBody, } from './utils.js';
|
|
7
|
+
/**
|
|
8
|
+
* A message. `raw` holds every field sent by Discord (embeds, components,
|
|
9
|
+
* attachments…).
|
|
10
|
+
* https://docs.discord.com/developers/resources/message#message-object
|
|
11
|
+
*/
|
|
12
|
+
export class Message {
|
|
13
|
+
client;
|
|
14
|
+
raw;
|
|
15
|
+
id;
|
|
16
|
+
channelId;
|
|
17
|
+
/** Null in DMs and for ephemeral messages. */
|
|
18
|
+
guildId;
|
|
19
|
+
/** For webhook messages, holds the webhook's id, username and avatar. */
|
|
20
|
+
author;
|
|
21
|
+
/** Author as a server member. Null in DMs, for webhooks and ephemeral messages. */
|
|
22
|
+
member;
|
|
23
|
+
/** Empty without the MessageContent intent, except in DMs and when the bot is mentioned. */
|
|
24
|
+
content;
|
|
25
|
+
createdAt;
|
|
26
|
+
editedAt;
|
|
27
|
+
tts;
|
|
28
|
+
pinned;
|
|
29
|
+
/** https://docs.discord.com/developers/resources/message#message-object-message-types */
|
|
30
|
+
type;
|
|
31
|
+
/** https://docs.discord.com/developers/resources/message#message-object-message-flags */
|
|
32
|
+
flags;
|
|
33
|
+
webhookId;
|
|
34
|
+
mentions;
|
|
35
|
+
mentionRoles;
|
|
36
|
+
mentionEveryone;
|
|
37
|
+
/** https://docs.discord.com/developers/resources/message#attachment-object */
|
|
38
|
+
attachments;
|
|
39
|
+
/** https://docs.discord.com/developers/resources/message#embed-object */
|
|
40
|
+
embeds;
|
|
41
|
+
components;
|
|
42
|
+
/** Message replied to: null if it was deleted, undefined if not a reply or not sent. */
|
|
43
|
+
referencedMessage;
|
|
44
|
+
constructor(client, raw) {
|
|
45
|
+
this.client = client;
|
|
46
|
+
this.raw = raw;
|
|
47
|
+
this.id = raw.id;
|
|
48
|
+
this.channelId = raw.channel_id;
|
|
49
|
+
this.guildId = raw.guild_id ?? null;
|
|
50
|
+
this.author = new User(client, raw.author);
|
|
51
|
+
this.member =
|
|
52
|
+
raw.member && this.guildId
|
|
53
|
+
? new Member(client, this.guildId, { ...raw.member, user: raw.author })
|
|
54
|
+
: null;
|
|
55
|
+
this.content = raw.content;
|
|
56
|
+
this.createdAt = new Date(raw.timestamp);
|
|
57
|
+
this.editedAt = toDate(raw.edited_timestamp);
|
|
58
|
+
this.tts = raw.tts;
|
|
59
|
+
this.pinned = raw.pinned;
|
|
60
|
+
this.type = raw.type;
|
|
61
|
+
this.flags = raw.flags ?? 0;
|
|
62
|
+
this.webhookId = raw.webhook_id ?? null;
|
|
63
|
+
this.mentions = (raw.mentions ?? []).map(user => new User(client, user));
|
|
64
|
+
this.mentionRoles = raw.mention_roles ?? [];
|
|
65
|
+
this.mentionEveryone = raw.mention_everyone;
|
|
66
|
+
this.attachments = raw.attachments ?? [];
|
|
67
|
+
this.embeds = raw.embeds ?? [];
|
|
68
|
+
this.components = raw.components ?? [];
|
|
69
|
+
this.referencedMessage = raw.referenced_message
|
|
70
|
+
? new _a(client, {
|
|
71
|
+
guild_id: raw.guild_id,
|
|
72
|
+
...raw.referenced_message,
|
|
73
|
+
})
|
|
74
|
+
: raw.referenced_message;
|
|
75
|
+
}
|
|
76
|
+
get channel() {
|
|
77
|
+
return new Channel(this.client, {
|
|
78
|
+
id: this.channelId,
|
|
79
|
+
...(this.guildId && { guild_id: this.guildId }),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/** Server of the message, null in DMs. */
|
|
83
|
+
get guild() {
|
|
84
|
+
return this.guildId ? new Guild(this.client, { id: this.guildId }) : null;
|
|
85
|
+
}
|
|
86
|
+
get url() {
|
|
87
|
+
return `https://discord.com/channels/${this.guildId ?? '@me'}/${this.channelId}/${this.id}`;
|
|
88
|
+
}
|
|
89
|
+
#path(suffix = '') {
|
|
90
|
+
return `/channels/${this.channelId}/messages/${this.id}${suffix}`;
|
|
91
|
+
}
|
|
92
|
+
#wrap(message) {
|
|
93
|
+
return new _a(this.client, {
|
|
94
|
+
guild_id: this.guildId ?? undefined,
|
|
95
|
+
...message,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Replies to the message.
|
|
100
|
+
* https://docs.discord.com/developers/resources/message#message-reference-structure
|
|
101
|
+
*/
|
|
102
|
+
async reply(options) {
|
|
103
|
+
const { body, files } = toMessageBody(options);
|
|
104
|
+
const reply = typeof options === 'string' ? {} : options;
|
|
105
|
+
body.message_reference = {
|
|
106
|
+
message_id: this.id,
|
|
107
|
+
channel_id: this.channelId,
|
|
108
|
+
...(this.guildId && { guild_id: this.guildId }),
|
|
109
|
+
...(reply.failIfNotExists !== undefined && {
|
|
110
|
+
fail_if_not_exists: reply.failIfNotExists,
|
|
111
|
+
}),
|
|
112
|
+
};
|
|
113
|
+
if (reply.mention !== undefined) {
|
|
114
|
+
body.allowed_mentions = {
|
|
115
|
+
// Without allowed_mentions, regular messages parse every mention type
|
|
116
|
+
...(reply.allowedMentions
|
|
117
|
+
? toAllowedMentions(reply.allowedMentions)
|
|
118
|
+
: { parse: ['users', 'roles', 'everyone'] }),
|
|
119
|
+
replied_user: reply.mention,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return this.#wrap(await this.client.rest.post(`/channels/${this.channelId}/messages`, {
|
|
123
|
+
body,
|
|
124
|
+
files,
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
127
|
+
/** Only the bot's own messages can have their content edited. https://docs.discord.com/developers/resources/message#edit-message */
|
|
128
|
+
async edit(options) {
|
|
129
|
+
const { body, files } = toMessageBody(options);
|
|
130
|
+
return this.#wrap(await this.client.rest.patch(this.#path(), { body, files }));
|
|
131
|
+
}
|
|
132
|
+
/** https://docs.discord.com/developers/resources/message#delete-message */
|
|
133
|
+
async delete(reason) {
|
|
134
|
+
await this.client.rest.delete(this.#path(), { reason });
|
|
135
|
+
}
|
|
136
|
+
/** https://docs.discord.com/developers/resources/message#create-reaction */
|
|
137
|
+
async react(emoji) {
|
|
138
|
+
await this.client.rest.put(this.#path(`/reactions/${encodeEmoji(emoji)}/@me`));
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Removes the bot's reaction, or the reaction of `userId`.
|
|
142
|
+
* https://docs.discord.com/developers/resources/message#delete-user-reaction
|
|
143
|
+
*/
|
|
144
|
+
async removeReaction(emoji, userId) {
|
|
145
|
+
await this.client.rest.delete(this.#path(`/reactions/${encodeEmoji(emoji)}/${userId ?? '@me'}`));
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Removes every reaction, or every reaction with `emoji`.
|
|
149
|
+
* https://docs.discord.com/developers/resources/message#delete-all-reactions
|
|
150
|
+
*/
|
|
151
|
+
async removeAllReactions(emoji) {
|
|
152
|
+
await this.client.rest.delete(this.#path(emoji ? `/reactions/${encodeEmoji(emoji)}` : '/reactions'));
|
|
153
|
+
}
|
|
154
|
+
/** https://docs.discord.com/developers/resources/message#pin-message */
|
|
155
|
+
async pin(reason) {
|
|
156
|
+
await this.client.rest.put(`/channels/${this.channelId}/messages/pins/${this.id}`, { reason });
|
|
157
|
+
}
|
|
158
|
+
/** https://docs.discord.com/developers/resources/message#unpin-message */
|
|
159
|
+
async unpin(reason) {
|
|
160
|
+
await this.client.rest.delete(`/channels/${this.channelId}/messages/pins/${this.id}`, {
|
|
161
|
+
reason,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
/** Publishes a message of an announcement channel to the following servers. */
|
|
165
|
+
async crosspost() {
|
|
166
|
+
return this.#wrap(await this.client.rest.post(this.#path('/crosspost')));
|
|
167
|
+
}
|
|
168
|
+
/** https://docs.discord.com/developers/resources/channel#start-thread-from-message */
|
|
169
|
+
async startThread(options) {
|
|
170
|
+
const { reason, ...thread } = options;
|
|
171
|
+
const channel = await this.client.rest.post(this.#path('/threads'), {
|
|
172
|
+
body: toThreadBody(thread),
|
|
173
|
+
reason,
|
|
174
|
+
});
|
|
175
|
+
return new Channel(this.client, channel);
|
|
176
|
+
}
|
|
177
|
+
/** https://docs.discord.com/developers/resources/message#get-channel-message */
|
|
178
|
+
async fetch() {
|
|
179
|
+
return this.#wrap(await this.client.rest.get(this.#path()));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
_a = Message;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Client } from '../discord/client.js';
|
|
2
|
+
import type { APIMessageReactionAddEvent, PartialEmoji, Snowflake } from '../discord/types.js';
|
|
3
|
+
import { Channel } from './Channel.js';
|
|
4
|
+
import { Guild } from './Guild.js';
|
|
5
|
+
import { Member } from './Member.js';
|
|
6
|
+
import type { Message } from './Message.js';
|
|
7
|
+
/**
|
|
8
|
+
* A reaction added or removed by a user.
|
|
9
|
+
* https://docs.discord.com/developers/events/gateway-events#message-reaction-add
|
|
10
|
+
*/
|
|
11
|
+
export declare class Reaction {
|
|
12
|
+
readonly client: Client;
|
|
13
|
+
readonly raw: Omit<APIMessageReactionAddEvent, 'member'> & {
|
|
14
|
+
member?: APIMessageReactionAddEvent['member'];
|
|
15
|
+
};
|
|
16
|
+
readonly emoji: PartialEmoji;
|
|
17
|
+
readonly userId: Snowflake;
|
|
18
|
+
readonly messageId: Snowflake;
|
|
19
|
+
readonly channelId: Snowflake;
|
|
20
|
+
readonly guildId: Snowflake | null;
|
|
21
|
+
/** Member who reacted, sent with reactions added in a server. */
|
|
22
|
+
readonly member: Member | null;
|
|
23
|
+
/** Author of the message, sent with reactions added. */
|
|
24
|
+
readonly messageAuthorId: Snowflake | null;
|
|
25
|
+
/** True for a super reaction. */
|
|
26
|
+
readonly burst: boolean;
|
|
27
|
+
constructor(client: Client, raw: Omit<APIMessageReactionAddEvent, 'member'> & {
|
|
28
|
+
member?: APIMessageReactionAddEvent['member'];
|
|
29
|
+
});
|
|
30
|
+
get channel(): Channel;
|
|
31
|
+
get guild(): Guild | null;
|
|
32
|
+
/** `👍` or `<:name:id>`, as written in a message. */
|
|
33
|
+
toString(): string;
|
|
34
|
+
/** The reacted message. */
|
|
35
|
+
fetchMessage(): Promise<Message>;
|
|
36
|
+
/** Removes this user's reaction. https://docs.discord.com/developers/resources/message#delete-user-reaction */
|
|
37
|
+
remove(): Promise<void>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Channel } from './Channel.js';
|
|
2
|
+
import { Guild } from './Guild.js';
|
|
3
|
+
import { Member } from './Member.js';
|
|
4
|
+
import { encodeEmoji } from './utils.js';
|
|
5
|
+
/**
|
|
6
|
+
* A reaction added or removed by a user.
|
|
7
|
+
* https://docs.discord.com/developers/events/gateway-events#message-reaction-add
|
|
8
|
+
*/
|
|
9
|
+
export class Reaction {
|
|
10
|
+
client;
|
|
11
|
+
raw;
|
|
12
|
+
emoji;
|
|
13
|
+
userId;
|
|
14
|
+
messageId;
|
|
15
|
+
channelId;
|
|
16
|
+
guildId;
|
|
17
|
+
/** Member who reacted, sent with reactions added in a server. */
|
|
18
|
+
member;
|
|
19
|
+
/** Author of the message, sent with reactions added. */
|
|
20
|
+
messageAuthorId;
|
|
21
|
+
/** True for a super reaction. */
|
|
22
|
+
burst;
|
|
23
|
+
constructor(client, raw) {
|
|
24
|
+
this.client = client;
|
|
25
|
+
this.raw = raw;
|
|
26
|
+
this.emoji = raw.emoji;
|
|
27
|
+
this.userId = raw.user_id;
|
|
28
|
+
this.messageId = raw.message_id;
|
|
29
|
+
this.channelId = raw.channel_id;
|
|
30
|
+
this.guildId = raw.guild_id ?? null;
|
|
31
|
+
this.member =
|
|
32
|
+
raw.member?.user && this.guildId
|
|
33
|
+
? new Member(client, this.guildId, {
|
|
34
|
+
...raw.member,
|
|
35
|
+
user: raw.member.user,
|
|
36
|
+
})
|
|
37
|
+
: null;
|
|
38
|
+
this.messageAuthorId = raw.message_author_id ?? null;
|
|
39
|
+
this.burst = raw.burst;
|
|
40
|
+
}
|
|
41
|
+
get channel() {
|
|
42
|
+
return new Channel(this.client, {
|
|
43
|
+
id: this.channelId,
|
|
44
|
+
...(this.guildId && { guild_id: this.guildId }),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
get guild() {
|
|
48
|
+
return this.guildId ? new Guild(this.client, { id: this.guildId }) : null;
|
|
49
|
+
}
|
|
50
|
+
/** `👍` or `<:name:id>`, as written in a message. */
|
|
51
|
+
toString() {
|
|
52
|
+
const { id, name, animated } = this.emoji;
|
|
53
|
+
return id ? `<${animated ? 'a' : ''}:${name}:${id}>` : (name ?? '');
|
|
54
|
+
}
|
|
55
|
+
/** The reacted message. */
|
|
56
|
+
fetchMessage() {
|
|
57
|
+
return this.channel.fetchMessage(this.messageId);
|
|
58
|
+
}
|
|
59
|
+
/** Removes this user's reaction. https://docs.discord.com/developers/resources/message#delete-user-reaction */
|
|
60
|
+
async remove() {
|
|
61
|
+
const user = this.userId === this.client.user?.id ? '@me' : this.userId;
|
|
62
|
+
await this.client.rest.delete(`/channels/${this.channelId}/messages/${this.messageId}/reactions/${encodeEmoji(this.emoji)}/${user}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Client } from '../discord/client.js';
|
|
2
|
+
import type { APIRole, Snowflake } from '../discord/types.js';
|
|
3
|
+
import { Guild } from './Guild.js';
|
|
4
|
+
import { type ImageOptions } from './utils.js';
|
|
5
|
+
/**
|
|
6
|
+
* A server role.
|
|
7
|
+
* https://docs.discord.com/developers/topics/permissions#role-object
|
|
8
|
+
*/
|
|
9
|
+
export declare class Role {
|
|
10
|
+
readonly client: Client;
|
|
11
|
+
readonly guildId: Snowflake;
|
|
12
|
+
readonly raw: APIRole;
|
|
13
|
+
readonly id: Snowflake;
|
|
14
|
+
readonly name: string;
|
|
15
|
+
/** Primary color as an integer, 0 when the role has none. */
|
|
16
|
+
readonly color: number;
|
|
17
|
+
/** Shown separately in the member list. */
|
|
18
|
+
readonly hoist: boolean;
|
|
19
|
+
readonly position: number;
|
|
20
|
+
/** Permission bit set, as a string since it doesn't fit in a number. */
|
|
21
|
+
readonly permissions: string;
|
|
22
|
+
/** Managed by an integration (bot role, boosters…): can't be assigned. */
|
|
23
|
+
readonly managed: boolean;
|
|
24
|
+
readonly mentionable: boolean;
|
|
25
|
+
readonly icon: string | null;
|
|
26
|
+
readonly unicodeEmoji: string | null;
|
|
27
|
+
constructor(client: Client, guildId: Snowflake, raw: APIRole);
|
|
28
|
+
get guild(): Guild;
|
|
29
|
+
/** The @everyone role has the guild's id. */
|
|
30
|
+
get isEveryone(): boolean;
|
|
31
|
+
/** Whether the role grants a permission, e.g. `1n << 3n` (ADMINISTRATOR). */
|
|
32
|
+
has(permission: bigint): boolean;
|
|
33
|
+
/** Mention, e.g. `${role}` in a message. */
|
|
34
|
+
toString(): string;
|
|
35
|
+
iconURL(options?: ImageOptions): string | null;
|
|
36
|
+
/**
|
|
37
|
+
* Updates the role with fields of the documented JSON params (snake_case).
|
|
38
|
+
* https://docs.discord.com/developers/resources/guild#modify-guild-role
|
|
39
|
+
*/
|
|
40
|
+
edit(data: Record<string, unknown>, reason?: string): Promise<Role>;
|
|
41
|
+
/** https://docs.discord.com/developers/resources/guild#delete-guild-role */
|
|
42
|
+
delete(reason?: string): Promise<void>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Guild } from './Guild.js';
|
|
2
|
+
import { cdnUrl } from './utils.js';
|
|
3
|
+
/**
|
|
4
|
+
* A server role.
|
|
5
|
+
* https://docs.discord.com/developers/topics/permissions#role-object
|
|
6
|
+
*/
|
|
7
|
+
export class Role {
|
|
8
|
+
client;
|
|
9
|
+
guildId;
|
|
10
|
+
raw;
|
|
11
|
+
id;
|
|
12
|
+
name;
|
|
13
|
+
/** Primary color as an integer, 0 when the role has none. */
|
|
14
|
+
color;
|
|
15
|
+
/** Shown separately in the member list. */
|
|
16
|
+
hoist;
|
|
17
|
+
position;
|
|
18
|
+
/** Permission bit set, as a string since it doesn't fit in a number. */
|
|
19
|
+
permissions;
|
|
20
|
+
/** Managed by an integration (bot role, boosters…): can't be assigned. */
|
|
21
|
+
managed;
|
|
22
|
+
mentionable;
|
|
23
|
+
icon;
|
|
24
|
+
unicodeEmoji;
|
|
25
|
+
constructor(client, guildId, raw) {
|
|
26
|
+
this.client = client;
|
|
27
|
+
this.guildId = guildId;
|
|
28
|
+
this.raw = raw;
|
|
29
|
+
this.id = raw.id;
|
|
30
|
+
this.name = raw.name;
|
|
31
|
+
this.color = raw.colors?.primary_color ?? raw.color;
|
|
32
|
+
this.hoist = raw.hoist;
|
|
33
|
+
this.position = raw.position;
|
|
34
|
+
this.permissions = raw.permissions;
|
|
35
|
+
this.managed = raw.managed;
|
|
36
|
+
this.mentionable = raw.mentionable;
|
|
37
|
+
this.icon = raw.icon ?? null;
|
|
38
|
+
this.unicodeEmoji = raw.unicode_emoji ?? null;
|
|
39
|
+
}
|
|
40
|
+
get guild() {
|
|
41
|
+
return new Guild(this.client, { id: this.guildId });
|
|
42
|
+
}
|
|
43
|
+
/** The @everyone role has the guild's id. */
|
|
44
|
+
get isEveryone() {
|
|
45
|
+
return this.id === this.guildId;
|
|
46
|
+
}
|
|
47
|
+
/** Whether the role grants a permission, e.g. `1n << 3n` (ADMINISTRATOR). */
|
|
48
|
+
has(permission) {
|
|
49
|
+
return (BigInt(this.permissions) & permission) === permission;
|
|
50
|
+
}
|
|
51
|
+
/** Mention, e.g. `${role}` in a message. */
|
|
52
|
+
toString() {
|
|
53
|
+
return this.isEveryone ? '@everyone' : `<@&${this.id}>`;
|
|
54
|
+
}
|
|
55
|
+
iconURL(options) {
|
|
56
|
+
return this.icon
|
|
57
|
+
? cdnUrl(`role-icons/${this.id}`, this.icon, options)
|
|
58
|
+
: null;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Updates the role with fields of the documented JSON params (snake_case).
|
|
62
|
+
* https://docs.discord.com/developers/resources/guild#modify-guild-role
|
|
63
|
+
*/
|
|
64
|
+
async edit(data, reason) {
|
|
65
|
+
const role = await this.client.rest.patch(`/guilds/${this.guildId}/roles/${this.id}`, {
|
|
66
|
+
body: data,
|
|
67
|
+
reason,
|
|
68
|
+
});
|
|
69
|
+
return new Role(this.client, this.guildId, role);
|
|
70
|
+
}
|
|
71
|
+
/** https://docs.discord.com/developers/resources/guild#delete-guild-role */
|
|
72
|
+
async delete(reason) {
|
|
73
|
+
await this.client.rest.delete(`/guilds/${this.guildId}/roles/${this.id}`, {
|
|
74
|
+
reason,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Client } from '../discord/client.js';
|
|
2
|
+
import type { APIUser, Snowflake } from '../discord/types.js';
|
|
3
|
+
import type { Message } from './Message.js';
|
|
4
|
+
import { type ImageOptions, type MessageOptions } from './utils.js';
|
|
5
|
+
/**
|
|
6
|
+
* A Discord user. `raw` holds every field sent by Discord.
|
|
7
|
+
* https://docs.discord.com/developers/resources/user#user-object
|
|
8
|
+
*/
|
|
9
|
+
export declare class User {
|
|
10
|
+
readonly client: Client;
|
|
11
|
+
readonly raw: APIUser;
|
|
12
|
+
readonly id: Snowflake;
|
|
13
|
+
readonly username: string;
|
|
14
|
+
/** Display name set by the user, if any. */
|
|
15
|
+
readonly globalName: string | null;
|
|
16
|
+
readonly discriminator: string;
|
|
17
|
+
readonly avatar: string | null;
|
|
18
|
+
readonly banner: string | null;
|
|
19
|
+
readonly bot: boolean;
|
|
20
|
+
readonly system: boolean;
|
|
21
|
+
constructor(client: Client, raw: APIUser);
|
|
22
|
+
/** Name shown in Discord: the display name, or the username. */
|
|
23
|
+
get displayName(): string;
|
|
24
|
+
get createdAt(): Date;
|
|
25
|
+
/** Mention, e.g. `${user}` in a message. */
|
|
26
|
+
toString(): string;
|
|
27
|
+
/** Uploaded avatar, or null when the user has none. */
|
|
28
|
+
avatarURL(options?: ImageOptions): string | null;
|
|
29
|
+
/** Default avatar Discord shows when the user has none. */
|
|
30
|
+
get defaultAvatarURL(): string;
|
|
31
|
+
/** Avatar shown in Discord: the uploaded one, or the default one. */
|
|
32
|
+
displayAvatarURL(options?: ImageOptions): string;
|
|
33
|
+
bannerURL(options?: ImageOptions): string | null;
|
|
34
|
+
/**
|
|
35
|
+
* Sends a direct message, opening the DM channel (or reusing it).
|
|
36
|
+
* https://docs.discord.com/developers/resources/user#create-dm
|
|
37
|
+
*/
|
|
38
|
+
send(options: MessageOptions): Promise<Message>;
|
|
39
|
+
/** Latest data from Discord. */
|
|
40
|
+
fetch(): Promise<User>;
|
|
41
|
+
}
|