oceanic.js
Version:
A NodeJS library for interfacing with Discord.
418 lines (417 loc) • 26.4 kB
TypeScript
/** @module REST/Channels */
import type { AddGroupRecipientOptions, AnyChannel, AnyTextableChannel, ArchivedThreads, CreateInviteOptions, CreateMessageOptions, EditChannelOptions, EditMessageOptions, EditPermissionOptions, FollowedChannel, GetChannelMessagesOptions, GetArchivedThreadsOptions, GetReactionsOptions, AnyInviteChannel, ThreadMember, StartThreadFromMessageOptions, StartThreadInThreadOnlyChannelOptions, StartThreadWithoutMessageOptions, GetInviteWithCountsAndExpirationOptions, GetInviteWithCountsOptions, GetInviteWithExpirationOptions, GetInviteWithNoneOptions, InviteInfoTypes, AnyEditableChannel, PartialInviteChannel, PurgeOptions, AnyTextableGuildChannel, GetThreadMembersOptions, GetChannelMessagesIteratorOptions, MessagesIterator, GetPollAnswerUsersOptions, SendSoundboardSoundOptions } from "../types/channels";
import type Message from "../structures/Message";
import type { CreateGroupChannelOptions } from "../types/users";
import Invite from "../structures/Invite";
import type AnnouncementThreadChannel from "../structures/AnnouncementThreadChannel";
import type PublicThreadChannel from "../structures/PublicThreadChannel";
import type PrivateThreadChannel from "../structures/PrivateThreadChannel";
import type AnnouncementChannel from "../structures/AnnouncementChannel";
import type { VoiceRegion } from "../types/voice";
import type RESTManager from "../rest/RESTManager";
import type PrivateChannel from "../structures/PrivateChannel";
import type GroupChannel from "../structures/GroupChannel";
import type User from "../structures/User";
import type { Uncached } from "../types/shared";
import type { CreateStageInstanceOptions, EditStageInstanceOptions } from "../types/guilds";
import StageInstance from "../structures/StageInstance";
/** Various methods for interacting with channels. Located at {@link Client#rest | Client#rest}{@link RESTManager#channels | .channels}. */
export default class Channels {
private _manager;
constructor(manager: RESTManager);
/**
* Add a user to a group channel.
* @param groupID The ID of the group to add the user to.
* @param options The options for adding the recipient.
* @caching This method **does not** cache its result.
*/
addGroupRecipient(groupID: string, options: AddGroupRecipientOptions): Promise<void>;
/**
* Add a member to a thread.
* @param channelID The ID of the thread to add them to.
* @param userID The ID of the user to add to the thread.
* @caching This method **does not** cache its result.
*/
addThreadMember(channelID: string, userID: string): Promise<void>;
/**
* Create a direct message. This will not create a new channel if you have already started a dm with the user.
* @param recipient The ID of the recipient of the direct message.
* @caching This method **does** cache its result.
* @caches {@link Client#privateChannels | Client#privateChannels}
*/
createDM(recipient: string): Promise<PrivateChannel>;
/**
* Create a group dm.
* @param options The options for creating the group dm.
* @caching This method **does** cache its result.
* @caches {@link Client#groupChannels | Client#groupChannels}
*/
createGroupDM(options: CreateGroupChannelOptions): Promise<GroupChannel>;
/**
* Create an invite for a channel. If the guild is not a `COMMUNITY` server, invites can only be made to last 30 days.
* @param channelID The ID of the channel to create an invite for.
* @param options The options for creating the invite.
* @caching This method **does not** cache its result.
*/
createInvite<T extends InviteInfoTypes, CH extends AnyInviteChannel | PartialInviteChannel | Uncached = AnyInviteChannel | PartialInviteChannel | Uncached>(channelID: string, options: CreateInviteOptions): Promise<Invite<T, CH>>;
/**
* Create a message in a channel.
* @param channelID The ID of the channel to create the message in.
* @param options The options for creating the message.
* @caching This method **may** cache its result. The result will not be cached if the channel is not cached.
* @caches {@link TextableChannel#messages | TextableChannel#messages}<br>{@link ThreadChannel#messages | ThreadChannel#messages}<br>{@link PrivateChannel#messages | PrivateChannel#messages}
*/
createMessage<T extends AnyTextableChannel | Uncached = AnyTextableChannel | Uncached>(channelID: string, options: CreateMessageOptions): Promise<Message<T>>;
/**
* Add a reaction to a message.
* @param channelID The ID of the channel the message is in.
* @param messageID The ID of the message to add a reaction to.
* @param emoji The reaction to add to the message. `name:id` for custom emojis, and the unicode codepoint for default emojis.
* @caching This method **does not** cache its result.
*/
createReaction(channelID: string, messageID: string, emoji: string): Promise<void>;
/**
* Create a stage instance.
* @param channelID The ID of the channel to create the stage instance on.
* @param options The options for creating the stage instance.
* @caching This method **does not** cache its result.
*/
createStageInstance(channelID: string, options: CreateStageInstanceOptions): Promise<StageInstance>;
/**
* Crosspost a message in an announcement channel.
* @param channelID The ID of the channel to crosspost the message in.
* @param messageID The ID of the message to crosspost.
* @caching This method **may** cache its result. The result will not be cached if the channel is not cached.
* @caches {@link TextableChannel#messages | TextableChannel#messages}<br>{@link ThreadChannel#messages | ThreadChannel#messages}<br>{@link PrivateChannel#messages | PrivateChannel#messages}
*/
crosspostMessage<T extends AnnouncementChannel | Uncached = AnnouncementChannel | Uncached>(channelID: string, messageID: string): Promise<Message<T>>;
/**
* Delete or close a channel.
* @param channelID The ID of the channel to delete or close.
* @param reason The reason to be displayed in the audit log.
* @caching This method **does not** cache its result.
*/
delete(channelID: string, reason?: string): Promise<void>;
/**
* Delete an invite.
* @param code The code of the invite to delete.
* @param reason The reason for deleting the invite.
* @caching This method **does not** cache its result.
*/
deleteInvite<T extends AnyInviteChannel | PartialInviteChannel | Uncached = AnyInviteChannel | PartialInviteChannel | Uncached>(code: string, reason?: string): Promise<Invite<"withMetadata", T>>;
/**
* Delete a message.
* @param channelID The ID of the channel to delete the message in.
* @param messageID The ID of the message to delete.
* @param reason The reason for deleting the message.
* @caching This method **does not** cache its result.
*/
deleteMessage(channelID: string, messageID: string, reason?: string): Promise<void>;
/**
* Bulk delete messages.
* @param channelID The ID of the channel to delete the messages in.
* @param messageIDs The IDs of the messages to delete. Any duplicates or messages older than two weeks will cause an error.
* @param reason The reason for deleting the messages.
* @caching This method **does not** cache its result.
*/
deleteMessages(channelID: string, messageIDs: Array<string>, reason?: string): Promise<number>;
/**
* Delete a permission overwrite.
* @param channelID The ID of the channel to delete the permission overwrite in.
* @param overwriteID The ID of the permission overwrite to delete.
* @param reason The reason for deleting the permission overwrite.
* @caching This method **does not** cache its result.
*/
deletePermission(channelID: string, overwriteID: string, reason?: string): Promise<void>;
/**
* Remove a reaction from a message.
* @param channelID The ID of the channel the message is in.
* @param messageID The ID of the message to remove a reaction from.
* @param emoji The reaction to remove from the message. `name:id` for custom emojis, and the unicode codepoint for default emojis.
* @param user The user to remove the reaction from, `@me` for the current user (default).
* @caching This method **does not** cache its result.
*/
deleteReaction(channelID: string, messageID: string, emoji: string, user?: string): Promise<void>;
/**
* Remove all, or a specific emoji's reactions from a message.
* @param channelID The ID of the channel the message is in.
* @param messageID The ID of the message to remove reactions from.
* @param emoji The reaction to remove from the message. `name:id` for custom emojis, and the unicode codepoint for default emojis. Omit to remove all reactions.
* @caching This method **does not** cache its result.
*/
deleteReactions(channelID: string, messageID: string, emoji?: string): Promise<void>;
/**
* Delete a stage instance.
* @param channelID The ID of the channel to delete the stage instance on.
* @param reason The reason for deleting the stage instance.
* @caching This method **does not** cache its result.
*/
deleteStageInstance(channelID: string, reason?: string): Promise<void>;
/**
* Edit a channel.
* @param channelID The ID of the channel to edit.
* @param options The options for editing the channel.
* @caching This method **may** cache its result. If a guild channel, the result will not be cached if the guild is not cached.
* @caches {@link Guild#channels | Guild#channels}<br>{@link Guild#threads | Guild#threads}<br>{@link Client#groupChannels | Client#groupChannels}
*/
edit<T extends AnyEditableChannel = AnyEditableChannel>(channelID: string, options: EditChannelOptions): Promise<T>;
/**
* Edit a message.
* @param channelID The ID of the channel the message is in.
* @param messageID The ID of the message to edit.
* @param options The options for editing the message.
* @caching This method **may** cache its result. The result will not be cached if the channel is not cached.
* @caches {@link TextableChannel#messages | TextableChannel#messages}<br>{@link ThreadChannel#messages | ThreadChannel#messages}<br>{@link PrivateChannel#messages | PrivateChannel#messages}
*/
editMessage<T extends AnyTextableChannel | Uncached = AnyTextableChannel | Uncached>(channelID: string, messageID: string, options: EditMessageOptions): Promise<Message<T>>;
/**
* Edit a permission overwrite.
* @param channelID The ID of the channel to edit the permission overwrite for.
* @param overwriteID The ID of the permission overwrite to edit.
* @param options The options for editing the permission overwrite.
* @caching This method **does not** cache its result.
*/
editPermission(channelID: string, overwriteID: string, options: EditPermissionOptions): Promise<void>;
/**
* Edit a stage instance.
* @param channelID The ID of the channel to edit the stage instance on.
* @param options The options for editing the stage instance.
* @caching This method **does not** cache its result.
*/
editStageInstance(channelID: string, options: EditStageInstanceOptions): Promise<StageInstance>;
/**
* End a poll now.
* @param channelID The ID of the channel the poll is in.
* @param messageID The ID of the message the poll is on.
* @caching This method **does not** cache its result.
*/
expirePoll(channelID: string, messageID: string): Promise<void>;
/**
* Follow an announcement channel.
* @param channelID The ID of the channel to follow announcements from.
* @param webhookChannelID The ID of the channel crossposted messages should be sent to. The client must have the `MANAGE_WEBHOOKS` permission in this channel.
* @param reason The reason for following the announcement channel.
* @caching This method **does not** cache its result.
*/
followAnnouncement(channelID: string, webhookChannelID: string, reason?: string): Promise<FollowedChannel>;
/**
* Get a channel.
* @param channelID The ID of the channel to get.
* @caching This method **may** cache its result. The result will not be cached if the guild is not cached.
* @caches {@link Guild#channels | Guild#channels}<br>{@link Guild#threads | Guild#threads}<br>{@link Client#privateChannels | Client#privateChannels}<br>{@link Client#groupChannels | Client#groupChannels}
*/
get<T extends AnyChannel = AnyChannel>(channelID: string): Promise<T>;
/**
* Get an invite.
* @param code The code of the invite to get.
* @param options The options for getting the invite.
* @caching This method **does not** cache its result.
*/
getInvite<T extends AnyInviteChannel | PartialInviteChannel | Uncached = AnyInviteChannel | PartialInviteChannel | Uncached>(code: string, options: GetInviteWithNoneOptions): Promise<Invite<"withMetadata", T>>;
getInvite<T extends AnyInviteChannel | PartialInviteChannel | Uncached = AnyInviteChannel | PartialInviteChannel | Uncached>(code: string, options: GetInviteWithCountsAndExpirationOptions): Promise<Invite<"withMetadata" | "withCounts" | "withExpiration", T>>;
getInvite<T extends AnyInviteChannel | PartialInviteChannel | Uncached = AnyInviteChannel | PartialInviteChannel | Uncached>(code: string, options: GetInviteWithCountsOptions): Promise<Invite<"withMetadata" | "withCounts", T>>;
getInvite<T extends AnyInviteChannel | PartialInviteChannel | Uncached = AnyInviteChannel | PartialInviteChannel | Uncached>(code: string, options: GetInviteWithExpirationOptions): Promise<Invite<"withMetadata" | "withExpiration", T>>;
/**
* Get the invites of a channel.
* @param channelID The ID of the channel to get the invites of.
* @caching This method **does not** cache its result.
*/
getInvites<T extends AnyInviteChannel | PartialInviteChannel | Uncached = AnyInviteChannel | PartialInviteChannel | Uncached>(channelID: string): Promise<Array<Invite<"withMetadata", T>>>;
/**
* Get the private archived threads the current user has joined in a channel.
* @param channelID The ID of the channel to get the archived threads from.
* @param options The options for getting the archived threads.
* @caching This method **does not** cache its result.
*/
getJoinedPrivateArchivedThreads(channelID: string, options?: GetArchivedThreadsOptions): Promise<ArchivedThreads<PrivateThreadChannel>>;
/**
* Get a message in a channel.
* @param channelID The ID of the channel the message is in
* @param messageID The ID of the message to get.
* @caching This method **may** cache its result. The result will not be cached if the channel is not cached.
* @caches {@link TextableChannel#messages | TextableChannel#messages}<br>{@link ThreadChannel#messages | ThreadChannel#messages}<br>{@link PrivateChannel#messages | PrivateChannel#messages}
*/
getMessage<T extends AnyTextableChannel | Uncached = AnyTextableChannel | Uncached>(channelID: string, messageID: string): Promise<Message<T>>;
/**
* Get messages in a channel.
* @param channelID The ID of the channel to get messages from.
* @param options The options for getting messages. `before`, `after`, and `around `All are mutually exclusive.
* @caching This method **may** cache its result. The result will not be cached if the channel is not cached.
* @caches {@link TextableChannel#messages | TextableChannel#messages}<br>{@link ThreadChannel#messages | ThreadChannel#messages}<br>{@link PrivateChannel#messages | PrivateChannel#messages}
*/
getMessages<T extends AnyTextableChannel | Uncached = AnyTextableChannel | Uncached>(channelID: string, options?: GetChannelMessagesOptions<T>): Promise<Array<Message<T>>>;
/**
* Get an async iterator for getting messages in a channel.
* @param channelID The ID of the channel to get messages from.
* @param options The options for getting messages. `before`, `after`, and `around `All are mutually exclusive.
* @caching This method **may** cache its result. The result will not be cached if the channel is not cached.
* @caches {@link TextableChannel#messages | TextableChannel#messages}<br>{@link ThreadChannel#messages | ThreadChannel#messages}<br>{@link PrivateChannel#messages | PrivateChannel#messages}
*/
getMessagesIterator<T extends AnyTextableChannel | Uncached = AnyTextableChannel | Uncached>(channelID: string, options?: GetChannelMessagesIteratorOptions<T>): MessagesIterator<T>;
/**
* Get the pinned messages in a channel.
* @param channelID The ID of the channel to get the pinned messages from.
* @caching This method **may** cache its result. The result will not be cached if the channel is not cached.
* @caches {@link TextableChannel#messages | TextableChannel#messages}<br>{@link ThreadChannel#messages | ThreadChannel#messages}<br>{@link PrivateChannel#messages | PrivateChannel#messages}
*/
getPinnedMessages<T extends AnyTextableChannel | Uncached = AnyTextableChannel | Uncached>(channelID: string): Promise<Array<Message<T>>>;
/**
* Get the users that voted on a poll answer.
* @param channelID The ID of the channel the poll is in.
* @param messageID The ID of the message the poll is on.
* @param answerID The ID of the poll answer to get voters for.
* @param options The options for getting the voters.
* @caching This method **does** cache its result.
* @caches {@link Client#users | Client#users}
*/
getPollAnswerUsers(channelID: string, messageID: string, answerID: number, options?: GetPollAnswerUsersOptions): Promise<Array<User>>;
/**
* Get the private archived threads in a channel.
* @param channelID The ID of the channel to get the archived threads from.
* @param options The options for getting the archived threads.
* @caching This method **may** cache its result. The result will not be cached if the guild is not cached.
* @caches {@link Guild#threads | Guild#threads}
*/
getPrivateArchivedThreads(channelID: string, options?: GetArchivedThreadsOptions): Promise<ArchivedThreads<PrivateThreadChannel>>;
/**
* Get the private joined archived threads in a channel.
* @param channelID The ID of the channel to get the archived threads from.
* @param options The options for getting the archived threads.
* @caching This method **may** cache its result. The result will not be cached if the guild is not cached.
* @caches {@link Guild#threads | Guild#threads}
*/
getPrivateJoinedArchivedThreads(channelID: string, options?: GetArchivedThreadsOptions): Promise<ArchivedThreads<PrivateThreadChannel>>;
/**
* Get the public archived threads in a channel.
* @param channelID The ID of the channel to get the archived threads from.
* @param options The options for getting the archived threads.
* @caching This method **may** cache its result. The result will not be cached if the guild is not cached.
* @caches {@link Guild#threads | Guild#threads}
*/
getPublicArchivedThreads<T extends AnnouncementThreadChannel | PublicThreadChannel = AnnouncementThreadChannel | PublicThreadChannel>(channelID: string, options?: GetArchivedThreadsOptions): Promise<ArchivedThreads<T>>;
/**
* Get the users who reacted with a specific emoji on a message.
* @param channelID The ID of the channel the message is in.
* @param messageID The ID of the message to get reactions from.
* @param emoji The reaction to remove from the message. `name:id` for custom emojis, and the unicode codepoint for default emojis.
* @param options The options for getting the reactions.
* @caching This method **does not** cache its result.
*/
getReactions(channelID: string, messageID: string, emoji: string, options?: GetReactionsOptions): Promise<Array<User>>;
/**
* Get the stage instance associated with a channel.
* @param channelID The ID of the channel to get the stage instance on.
* @caching This method **does not** cache its result.
*/
getStageInstance(channelID: string): Promise<StageInstance>;
/**
* Get a thread member.
* @param channelID The ID of the thread.
* @param userID The ID of the user to get the thread member of.
* @caching This method **does not** cache its result.
*/
getThreadMember(channelID: string, userID: string): Promise<ThreadMember>;
/**
* Get the members of a thread.
* @param channelID The ID of the thread.
* @param options The options for getting the thread members.
* @caching This method **does not** cache its result.
*/
getThreadMembers(channelID: string, options?: GetThreadMembersOptions): Promise<Array<ThreadMember>>;
/** @deprecated Get the list of usable voice regions. Moved to `misc`. */
getVoiceRegions(): Promise<Array<VoiceRegion>>;
/**
* Join a thread.
* @param channelID The ID of the thread to join.
* @caching This method **does not** cache its result.
*/
joinThread(channelID: string): Promise<void>;
/**
* Leave a thread.
* @param channelID The ID of the thread to leave.
* @caching This method **does not** cache its result.
*/
leaveThread(channelID: string): Promise<void>;
/**
* Pin a message in a channel.
* @param channelID The ID of the channel to pin the message in.
* @param messageID The ID of the message to pin.
* @param reason The reason for pinning the message.
* @caching This method **does not** cache its result.
*/
pinMessage(channelID: string, messageID: string, reason?: string): Promise<void>;
/**
* Purge an amount of messages from a channel.
* @param channelID The ID of the channel to purge.
* @param options The options to purge. `before`, `after`, and `around `All are mutually exclusive.
* @caching This method **does not** cache its result.
*/
purgeMessages<T extends AnyTextableGuildChannel | Uncached = AnyTextableGuildChannel | Uncached>(channelID: string, options: PurgeOptions<T>): Promise<number>;
/**
* Remove a user from the group channel.
* @param groupID The ID of the group to remove the user from.
* @param userID The ID of the user to remove.
* @caching This method **does not** cache its result.
*/
removeGroupRecipient(groupID: string, userID: string): Promise<void>;
/**
* Remove a member from a thread.
* @param channelID The ID of the thread to remove them from.
* @param userID The ID of the user to remove from the thread.
* @caching This method **does not** cache its result.
*/
removeThreadMember(channelID: string, userID: string): Promise<void>;
/**
* Send a sound from the soundboard to the channel where the user is connected.
* @param channelID The ID of the channel to send the soundboard sound to.
* @param soundID The ID of the soundboard sound to send.
* @param sourceGuildID The ID of the guild the soundboard sound is from.
* @caching This method **does not** cache its result.
*/
sendSoundboardSound(channelID: string, options: SendSoundboardSoundOptions): Promise<void>;
/**
* Show a typing indicator in a channel. How long users see this varies from client to client.
* @param channelID The ID of the channel to show the typing indicator in.
* @caching This method **does not** cache its result.
*/
sendTyping(channelID: string): Promise<void>;
/**
* Set a voice status in a channel.
* @param channelID The ID of the channel to set the voice status in.
* @param status The voice status to set.
*/
setVoiceStatus(channelID: string, status: string | null): Promise<void>;
/**
* Create a thread from an existing message.
* @param channelID The ID of the channel to create the thread in.
* @param messageID The ID of the message to create the thread from.
* @param options The options for starting the thread.
* @caching This method **may** cache its result. The result will not be cached if the guild is not cached.
* @caches {@link Guild#threads | Guild#threads}
*/
startThreadFromMessage<T extends AnnouncementThreadChannel | PublicThreadChannel = AnnouncementThreadChannel | PublicThreadChannel>(channelID: string, messageID: string, options: StartThreadFromMessageOptions): Promise<T>;
/**
* Create a thread in a thread only channel (forum & media).
* @param channelID The ID of the channel to start the thread in.
* @param options The options for starting the thread.
* @caching This method **may** cache its result. The result will not be cached if the guild is not cached.
* @caches {@link Guild#threads | Guild#threads}
*/
startThreadInThreadOnlyChannel(channelID: string, options: StartThreadInThreadOnlyChannelOptions): Promise<PublicThreadChannel>;
/**
* Create a thread without an existing message.
* @param channelID The ID of the channel to start the thread in.
* @param options The options for starting the thread.
* @caching This method **may** cache its result. The result will not be cached if the guild is not cached.
* @caches {@link Guild#threads | Guild#threads}
*/
startThreadWithoutMessage<T extends AnnouncementThreadChannel | PublicThreadChannel | PrivateThreadChannel = AnnouncementThreadChannel | PublicThreadChannel | PrivateThreadChannel>(channelID: string, options: StartThreadWithoutMessageOptions): Promise<T>;
/**
* Unpin a message in a channel.
* @param channelID The ID of the channel to unpin the message in.
* @param messageID The ID of the message to unpin.
* @param reason The reason for unpinning the message.
* @caching This method **does not** cache its result.
*/
unpinMessage(channelID: string, messageID: string, reason?: string): Promise<void>;
}