aboutsummaryrefslogtreecommitdiff
path: root/src/lib/extensions/discord.js/BushGuildChannelManager.ts
blob: 4048b9874783de754ab7db8e2cb9f772fca00f8d (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import type {
	BushFetchedThreads,
	BushGuild,
	BushGuildBasedChannel,
	BushGuildChannel,
	BushMappedGuildChannelTypes,
	BushNonThreadGuildBasedChannel,
	BushTextChannel
} from '#lib';
import {
	CachedManager,
	ChannelData,
	ChannelWebhookCreateOptions,
	SetChannelPositionOptions,
	Webhook,
	type BaseFetchOptions,
	type ChannelPosition,
	type Collection,
	type GuildChannelCreateOptions,
	type GuildChannelManager,
	type GuildChannelResolvable,
	type GuildChannelTypes,
	type Snowflake
} from 'discord.js';
import type { RawGuildChannelData } from 'discord.js/typings/rawDataTypes';

/**
 * Manages API methods for GuildChannels and stores their cache.
 */
export declare class BushGuildChannelManager
	extends CachedManager<Snowflake, BushGuildBasedChannel, GuildChannelResolvable>
	implements GuildChannelManager
{
	public constructor(guild: BushGuild, iterable?: Iterable<RawGuildChannelData>);

	/**
	 * The number of channels in this managers cache excluding thread channels
	 * that do not count towards a guild's maximum channels restriction.
	 */
	public readonly channelCountWithoutThreads: number;

	/**
	 * The guild this Manager belongs to
	 */
	public guild: BushGuild;

	/**
	 * Creates a new channel in the guild.
	 * @param name The name of the new channel
	 * @param options Options for creating the new channel
	 * @example
	 * // Create a new text channel
	 * guild.channels.create('new-general', { reason: 'Needed a cool new channel' })
	 *   .then(console.log)
	 *   .catch(console.error);
	 * @example
	 * // Create a new channel with permission overwrites
	 * guild.channels.create('new-voice', {
	 *   type: 'GuildVoice',
	 *   permissionOverwrites: [
	 *      {
	 *        id: message.author.id,
	 *        deny: [PermissionFlagsBits.ViewChannel],
	 *     },
	 *   ],
	 * })
	 */
	public create<T extends GuildChannelTypes>(
		name: string,
		options: GuildChannelCreateOptions & { type: T }
	): Promise<BushMappedGuildChannelTypes[T]>;
	public create(name: string, options?: GuildChannelCreateOptions): Promise<BushTextChannel>;

	/**
	 * Creates a webhook for the channel.
	 * @param channel The channel to create the webhook for
	 * @param name The name of the webhook
	 * @param options Options for creating the webhook
	 * @returns Returns the created Webhook
	 * @example
	 * // Create a webhook for the current channel
	 * guild.channels.createWebhook('222197033908436994', 'Snek', {
	 *   avatar: 'https://i.imgur.com/mI8XcpG.jpg',
	 *   reason: 'Needed a cool new Webhook'
	 * })
	 *   .then(console.log)
	 *   .catch(console.error)
	 */
	public createWebhook(channel: GuildChannelResolvable, name: string, options?: ChannelWebhookCreateOptions): Promise<Webhook>;

	/**
	 * Edits the channel.
	 * @param channel The channel to edit
	 * @param data The new data for the channel
	 * @param reason Reason for editing this channel
	 * @example
	 * // Edit a channel
	 * guild.channels.edit('222197033908436994', { name: 'new-channel' })
	 *   .then(console.log)
	 *   .catch(console.error);
	 */
	public edit(channel: GuildChannelResolvable, data: ChannelData, reason?: string): Promise<BushGuildChannel>;

	/**
	 * Obtains one or more guild channels from Discord, or the channel cache if they're already available.
	 * @param id The channel's id
	 * @param options Additional options for this fetch
	 * @example
	 * // Fetch all channels from the guild (excluding threads)
	 * message.guild.channels.fetch()
	 *   .then(channels => console.log(`There are ${channels.size} channels.`))
	 *   .catch(console.error);
	 * @example
	 * // Fetch a single channel
	 * message.guild.channels.fetch('222197033908436994')
	 *   .then(channel => console.log(`The channel name is: ${channel.name}`))
	 *   .catch(console.error);
	 */
	public fetch(id: Snowflake, options?: BaseFetchOptions): Promise<BushNonThreadGuildBasedChannel | null>;
	public fetch(id?: undefined, options?: BaseFetchOptions): Promise<Collection<Snowflake, BushNonThreadGuildBasedChannel>>;

	/**
	 * Fetches all webhooks for the channel.
	 * @param channel The channel to fetch webhooks for
	 * @example
	 * // Fetch webhooks
	 * guild.channels.fetchWebhooks('769862166131245066')
	 *   .then(hooks => console.log(`This channel has ${hooks.size} hooks`))
	 *   .catch(console.error);
	 */
	public fetchWebhooks(channel: GuildChannelResolvable): Promise<Collection<Snowflake, Webhook>>;

	/**
	 * Sets a new position for the guild channel.
	 * @param channel The channel to set the position for
	 * @param position The new position for the guild channel
	 * @param options Options for setting position
	 * @example
	 * // Set a new channel position
	 * guild.channels.setPosition('222078374472843266', 2)
	 *   .then(newChannel => console.log(`Channel's new position is ${newChannel.position}`))
	 *   .catch(console.error);
	 */
	public setPosition(
		channel: GuildChannelResolvable,
		position: number,
		options?: SetChannelPositionOptions
	): Promise<BushGuildChannel>;

	/**
	 * Batch-updates the guild's channels' positions.
	 * <info>Only one channel's parent can be changed at a time</info>
	 * @param channelPositions Channel positions to update
	 * @example
	 * guild.channels.setPositions([{ channel: channelId, position: newChannelIndex }])
	 *   .then(guild => console.log(`Updated channel positions for ${guild}`))
	 *   .catch(console.error);
	 */
	public setPositions(channelPositions: readonly ChannelPosition[]): Promise<BushGuild>;

	/**
	 * Obtains all active thread channels in the guild from Discord
	 * @param {} [cache=true] Whether to cache the fetched data
	 * @example
	 * // Fetch all threads from the guild
	 * message.guild.channels.fetchActiveThreads()
	 *   .then(fetched => console.log(`There are ${fetched.threads.size} threads.`))
	 *   .catch(console.error);
	 */
	public fetchActiveThreads(cache?: boolean): Promise<BushFetchedThreads>;

	/**
	 * Deletes the channel.
	 * @param channel The channel to delete
	 * @param reason Reason for deleting this channel
	 * @example
	 * // Delete the channel
	 * guild.channels.delete('858850993013260338', 'making room for new channels')
	 *   .then(console.log)
	 *   .catch(console.error);
	 */
	public delete(channel: GuildChannelResolvable, reason?: string): Promise<void>;
}