Class ChannelMethods

Methods for interacting with Channels and Messages

Hierarchy

  • ChannelMethods

Methods

  • Pin a message within a channel

    Returns

    Resolves the Promise on successful execution

    Permissions needed Condition
    VIEW_CHANNEL if channel is not a DM channel
    READ_MESSAGE_HISTORY if channel is not a DM channel
    MANAGE_MESSAGES if channel is not a DM channel

    Example

    // Pin a message because it was a good meme
    const client = new SnowTransfer("TOKEN")
    client.channel.addChannelPinnedMessage("channel id", "message id", "Good meme")

    Parameters

    • channelId: string

      Id of the channel

    • messageId: string

      Id of the message

    • Optional reason: string

      Reason for pinning the message

    Returns Promise<void>

  • Add a user to a thread

    CurrentUser must be a member of the thread

    Returns

    Resolves the Promise on successful execution

    Permissions needed Condition
    CurrentUser added to Thread always
    SEND_MESSAGES_IN_THREADS always

    Example

    const client = new SnowTransfer("TOKEN")
    client.channel.addThreadMember("thread id", "user id")

    Parameters

    • threadId: string

      Id of the thread

    • userId: string

      Id of the user to add

    Returns Promise<void>

  • Bulk delete messages from a guild channel, messages may not be older than 2 weeks

    Returns

    Resolves the Promise on successful execution

    Permissions needed Condition
    VIEW_CHANNEL always
    MANAGE_MESSAGES always

    Example

    // Bulk deletes 2 messages with a reason of "spam"
    const client = new SnowTransfer("TOKEN")
    client.channel.bulkDeleteMessages("channel id", ["message id 1", "message id 2"], "spam")

    Parameters

    • channelId: string

      Id of the guild channel

    • messages: string[]

      array of message ids to delete

    • Optional reason: string

      Reason for deleting the messages

    Returns Promise<void>

  • Create an invite for a guild channel

    If no data argument is passed, the invite will be created with the defaults

    Returns

    Invite object (with metadata)

    Permissions needed Condition
    VIEW_CHANNEL always
    CREATE_INSTANT_INVITE always

    Example

    // Creates a unique permanent invite with infinite uses
    const client = new SnowTransfer("TOKEN")
    const invite = await client.channel.createChannelInvite("channel id", { max_age: 0, max_uses: 0, unique: true })

    Parameters

    • channelId: string

      Id of the channel

    • data: CreateInviteData & {
          reason?: string;
      } = ...

      invite data (optional)

    Returns Promise<Invite>

  • Creates a new Message within a channel or thread

    Make sure to use a filename with a proper extension (e.g. png, jpeg, etc.) when you want to upload files

    Returns

    discord message object

    Permissions needed Condition
    VIEW_CHANNEL if channel is not a DM channel
    READ_MESSAGE_HISTORY if channel is not a DM channel and message is a reply
    SEND_MESSAGES if channel is not a DM channel and if channel is not a thread
    SEND_TTS_MESSAGES if channel is not a DM channel and tts is set to true
    SEND_MESSAGES_IN_THREADS if channel is a thread

    Example

    // Make a bot say "hi" within a channel
    // createMessage sends the passed data as content, when you give it a string
    const client = new SnowTransfer("TOKEN")
    client.channel.createMessage("channel id", "hi")

    Example

    // Send a rich embed object
    const client = new SnowTransfer("TOKEN")
    const embedData = {
    title: "This is a nice embed",
    description: "But winter is so cold",
    fields: [
    { name: "Brr", value: "Insert snowflake emoji here" }
    ]
    }
    client.channel.createMessage("channel id", { embeds: [embedData] })

    Example

    // Send a file with a comment
    const client = new SnowTransfer("TOKEN")
    // fileData will be a buffer with the data of the png image.
    const fileData = fs.readFileSync("nice_picture.png") // You should probably use fs.readFile, since it is asynchronous, synchronous methods block the thread.
    client.channel.createMessage("channel id", { content: "This is a nice picture", files: [{ name: "Optional_Filename.png", file: fileData }] })

    Parameters

    • channelId: string

      Id of the Channel or thread to sent a message to

    • data: string | CreateMessageData

      Data to send, if data is a string it will be used as the content of the message, if data is not a string you should take a look at the properties below to know what you may send

    • options: {
          disableEveryone?: boolean;
      } = ...
      • Optional disableEveryone?: boolean

    Returns Promise<Message>

  • Adds a reaction to a message

    Returns

    Resolves the Promise on successful execution

    Permissions needed Condition
    VIEW_CHANNEL if channel is not a DM channel
    READ_MESSAGE_HISTORY if channel is not a DM channel
    ADD_REACTIONS When no other user has reacted with the emoji used and channel is not a DM channel

    Example

    // This example uses a discord emoji
    const client = new SnowTransfer("TOKEN")
    client.channel.createReaction("channel Id", "message Id", encodeURIComponent("awooo:322522663304036352"))

    Example

    // using a utf-8 emoji
    const client = new SnowTransfer("TOKEN")
    client.channel.createReaction("channel Id", "message Id", encodeURIComponent("😀"))

    Parameters

    • channelId: string

      Id of the channel

    • messageId: string

      Id of the message

    • emoji: string

      uri encoded reaction emoji to add you may either use a discord emoji in the format :emoji_name:emoji_id or a unicode emoji, which can be found here

    Returns Promise<void>

  • Creates a public thread off a message in a guild channel

    Returns

    thread channel object

    Permissions needed Condition
    VIEW_CHANNEL always
    CREATE_PUBLIC_THREADS always

    Example

    // Create a thread off a cool art piece to discuss
    const client = new SnowTransfer("TOKEN")
    const thread = await client.channel.createThreadWithMessage("channel id", "message id", { name: "cool-art", reason: "I wanna talk about it!" })

    Parameters

    • channelId: string

      Id of the guild channel

    • messageId: string

      Id of the message

    • options: {
          auto_archive_duration?: 60 | 1440 | 4320 | 10080;
          name: string;
          rate_limit_per_user?: null | number;
          reason?: string;
      }

      Thread meta data

      • Optional auto_archive_duration?: 60 | 1440 | 4320 | 10080
      • name: string
      • Optional rate_limit_per_user?: null | number
      • Optional reason?: string

    Returns Promise<AnnouncementThread | PublicThread>

  • Creates a thread under a guild channel without a message

    Returns

    thread channel object

    Permissions needed Condition
    VIEW_CHANNEL always
    CREATE_PUBLIC_THREADS if creating a public thread
    CREATE_PRIVATE_THREADS if creating a private thread

    Example

    // Creates a private thread that's invitable to talk about someone's birthday
    const client = new SnowTransfer("TOKEN")
    const thread = await client.channel.createThreadWithoutMessage("channel id", { name: "persons-birthday", type: 12, invitable: true, reason: "Shh! It's a surprise" })

    Parameters

    • channelId: string

      Id of the guild channel

    • options: {
          auto_archive_duration?: 60 | 1440 | 4320 | 10080;
          invitable?: boolean;
          name: string;
          rate_limit_per_user?: null | number;
          reason?: string;
          type: 11;
      }

      Thread meta data

      • Optional auto_archive_duration?: 60 | 1440 | 4320 | 10080
      • Optional invitable?: boolean
      • name: string
      • Optional rate_limit_per_user?: null | number
      • Optional reason?: string
      • type: 11

    Returns Promise<PublicThread>

  • Parameters

    • channelId: string
    • options: {
          auto_archive_duration?: 60 | 1440 | 4320 | 10080;
          invitable?: boolean;
          name: string;
          rate_limit_per_user?: null | number;
          reason?: string;
          type: 12;
      }
      • Optional auto_archive_duration?: 60 | 1440 | 4320 | 10080
      • Optional invitable?: boolean
      • name: string
      • Optional rate_limit_per_user?: null | number
      • Optional reason?: string
      • type: 12

    Returns Promise<PrivateThread>

  • Crosspost a message in a news channel to all following channels

    Returns

    discord message object

    Permissions needed Condition
    VIEW_CHANNEL always
    SEND_MESSAGES if the message was sent by the current user
    MANAGE_MESSAGES if the message wasn't sent by the current user

    Example

    // Crosspost a message
    const client = new SnowTransfer("TOKEN")
    client.channel.crosspostMessage("channel id", "message id")

    Parameters

    • channelId: string

      Id of the news channel

    • messageId: string

      Id of the message

    Returns Promise<Message>

  • Delete all reactions from a message in a guild channel

    Returns

    Resolves the Promise on successful execution

    Permissions needed Condition
    VIEW_CHANNEL always
    READ_MESSAGE_HISTORY always
    MANAGE_MESSAGES always

    Example

    const client = new SnowTransfer("TOKEN")
    client.channel.deleteAllReactions("channel Id", "message Id")

    Parameters

    • channelId: string

      Id of the guild channel

    • messageId: string

      Id of the message

    Returns Promise<void>

  • Delete a channel or thread via Id

    This either deletes a Guild Channel/thread or closes a Direct Message Channel

    Be careful with deleting Guild Channels as this cannot be undone!

    When deleting a category, this does not delete the child channels of a category. They will just have their parent_id removed.

    For community guilds, the rules channel and the community updates channel cannot be deleted.

    Returns

    discord channel object

    Permissions needed Condition
    MANAGE_CHANNELS if channel is not a DM channel
    MANAGE_THREADS if channel is a thread

    Example

    // Deletes a channel via id because it wasn't needed anymore
    const client = new SnowTransfer("TOKEN")
    client.channel.deleteChannel("channel id", "No longer needed")

    Parameters

    • channelId: string

      Id of the channel

    • Optional reason: string

      Reason for deleting the channel

    Returns Promise<Channel>

  • Delete a permission overwrite from a guild channel

    Returns

    Resolves the Promise on successful execution

    Permissions needed Condition
    MANAGE_CHANNELS if channel is not a thread
    MANAGE_THREADS if channel is a thread
    MANAGE_ROLES always
    VIEW_CHANNEL always

    Example

    // Deletes the permission overwrite of a user
    const client = new SnowTransfer("TOKEN")
    client.channel.deleteChannelPermission("channel id", "user id", "Abusing channel")

    Parameters

    • channelId: string

      Id of the guild channel

    • permissionId: string

      Id of the permission overwrite

    • Optional reason: string

      Reason for deleting the permission

    Returns Promise<void>

  • Delete a message

    Returns

    Resolves the Promise on successful execution

    Permissions needed Condition
    VIEW_CHANNEL if channel is not a DM channel
    MANAGE_MESSAGES When the bot isn't the author of the message

    Example

    // Delete a message
    const client = new SnowTransfer("TOKEN")
    client.channel.deleteMessage("channel id", "message id")

    Parameters

    • channelId: string

      Id of the channel

    • messageId: string

      Id of the message

    • Optional reason: string

      Reason for deleting the message

    Returns Promise<void>

  • Delete a reaction from a message in a guild channel

    Returns

    Resolves the Promise on successful execution

    Permission Condition
    MANAGE_MESSAGES always
    VIEW_CHANNEL always
    READ_MESSAGE_HISTORY always

    Example

    // This example uses a discord emoji
    const client = new SnowTransfer("TOKEN")
    client.channel.deleteReaction("channel Id", "message Id", encodeURIComponent("awooo:322522663304036352"), "user Id")

    Example

    // using a utf-8 emoji
    const client = new SnowTransfer("TOKEN")
    // If a user Id is not supplied, the emoji from that message will be removed for all users
    client.channel.deleteReaction("channel Id", "message Id", encodeURIComponent("😀"))

    Parameters

    • channelId: string

      Id of the guild channel

    • messageId: string

      Id of the message

    • emoji: string

      reaction emoji

    • Optional userId: string

      Id of the user

    Returns Promise<void>

  • Delete a reaction added by the current user from a message

    Returns

    Resolves the Promise on successful execution

    Permission Condition
    VIEW_CHANNEL if channel is not a DM channel
    READ_MESSAGE_HISTORY if channel is not a DM channel

    Example

    // This example uses a discord emoji
    const client = new SnowTransfer("TOKEN")
    client.channel.deleteReactionSelf("channel Id", "message Id", encodeURIComponent("awooo:322522663304036352"))

    Example

    // using a utf-8 emoji
    const client = new SnowTransfer("TOKEN")
    client.channel.deleteReactionSelf("channel Id", "message Id", encodeURIComponent("😀"))

    Parameters

    • channelId: string

      Id of the channel

    • messageId: string

      Id of the message

    • emoji: string

      reaction emoji

    Returns Promise<void>

  • Modify the permission overwrites of a guild channel

    Returns

    Resolves the Promise on successful execution

    Permissions needed Condition
    MANAGE_CHANNELS if channel is not a thread
    MANAGE_THREADS if channel is a thread
    MANAGE_ROLES always
    VIEW_CHANNEL always

    Example

    // Edits the permissions of a user to allow viewing the channel only
    const client = new SnowTransfer("TOKEN")
    client.channel.editChannelPermission("channel id", "user id", { allow: String(1 << 10), type: 1 })

    Parameters

    • channelId: string

      Id of the guild channel

    • permissionId: string

      Id of the permission overwrite

    • data: Partial<Omit<Overwrite, "id">> & {
          reason?: string;
      }

      modified permission overwrite object

    Returns Promise<void>

  • Edit a message sent by the current user or edit the message flags of another user's message

    Returns

    discord message object

    Permissions needed Condition
    VIEW_CHANNEL if channel is not a DM channel
    MANAGE_MESSAGES When editing someone else's message to set flags

    Example

    // Simple ping response const client = new SnowTransfer("TOKEN") const time = Date.now() const message = await client.channel.createMessage("channel id", "pong") client.channel.editMessage("channel id", message.id, pong ${Date.now() - time}ms)

    Parameters

    • channelId: string

      Id of the channel

    • messageId: string

      Id of the message

    • data: string | EditMessageData

      Data to send

    • options: {
          disableEveryone?: boolean;
      } = ...
      • Optional disableEveryone?: boolean

    Returns Promise<Message>

  • Follow a news channel to another channel

    Returns

    A followed channel object

    Permissions needed Condition
    MANAGE_WEBHOOKS always

    Example

    // Follows a news channel to a text channel
    const client = new SnowTransfer("TOKEN")
    client.channel.followNewsChannel("news channel id", "text channel id")

    Parameters

    • channelId: string

      The Id of the news channel

    • webhookChannelId: string

      The Id of the channel messages will be sent to

    Returns Promise<FollowedChannel>

  • Get a channel via Id

    Returns

    discord channel object

    Example

    const client = new SnowTransfer("TOKEN")
    const channel = await client.channel.getChannel("channel id")

    Parameters

    • channelId: string

      Id of the channel

    Returns Promise<Channel>

  • Gets all threads that are private and archived within a guild channel

    CurrentUser must be a member of the thread if they do not have MANAGE_THREADS permissions

    Returns

    Object containing private threads, thread members of the CurrentUser, and if there are more results in the pagination

    Permissions needed Condition
    VIEW_CHANNEL always
    READ_MESSAGE_HISTORY always
    MANAGE_THREADS if CurrentUser isn't added to Thread

    Example

    const client = new SnowTransfer("TOKEN")
    const result = await client.channel.getChannelArchivedPrivateThreads("channel id")

    Parameters

    • channelId: string

      Id of the Channel

    • Optional query: {
          before?: string;
          limit?: number;
      }
      • Optional before?: string
      • Optional limit?: number

    Returns Promise<{
        has_more: boolean;
        members: ThreadMember[];
        threads: PrivateThread[];
    }>

  • Gets all threads that are private and archived within a guild channel that the CurrentUser is apart of

    CurrentUser must be a member of the thread if they do not have MANAGE_THREADS permissions

    Returns

    Object containing private threads, thread members of the CurrentUser, and if there are more results in the pagination

    Permissions needed Condition
    VIEW_CHANNEL always

    Example

    const client = new SnowTransfer("TOKEN")
    const result = await client.channel.getChannelArchivedPrivateThreadsUser("channel id")

    Parameters

    • channelId: string

      Id of the Channel

    • Optional query: {
          before?: string;
          limit?: number;
      }
      • Optional before?: string
      • Optional limit?: number

    Returns Promise<{
        has_more: boolean;
        members: ThreadMember[];
        threads: PrivateThread[];
    }>

  • Gets all threads that are public and archived within a guild channel

    Returns

    Object containing public threads, thread members of the CurrentUser, and if there are more results in the pagination

    Permissions needed Condition
    VIEW_CHANNEL always
    READ_MESSAGE_HISTORY always

    Example

    const client = new SnowTransfer("TOKEN")
    const result = await client.channel.getChannelArchivedPublicThreads("channel id")

    Parameters

    • channelId: string

      Id of the guild channel

    • Optional query: {
          before?: string;
          limit?: number;
      }
      • Optional before?: string
      • Optional limit?: number

    Returns Promise<{
        has_more: boolean;
        members: ThreadMember[];
        threads: (AnnouncementThread | PublicThread)[];
    }>

  • Get a list of invites for a guild channel

    Returns

    Array of invite objects (with metadata)

    Permissions needed Condition
    VIEW_CHANNEL always
    MANAGE_CHANNELS always

    Example

    const client = new SnowTransfer("TOKEN")
    const invites = await client.channel.getChannelInvites("channel id")

    Parameters

    • channelId: string

      Id of the guild channel

    Returns Promise<(Invite & InviteMetadata)[]>

  • Get a single message via Id

    Returns

    discord message object

    Permissions needed Condition
    VIEW_CHANNEL if channel is not a DM channel
    READ_MESSAGE_HISTORY if channel is not a DM channel

    Example

    // Get a single message from a channel via id
    const client = new SnowTransfer("TOKEN")
    const message = await client.channel.getChannelMessage("channel id", "message id")

    Parameters

    • channelId: string

      Id of the channel

    • messageId: string

      Id of the message

    Returns Promise<Message>

  • Get a list of messages from a channel

    Returns

    Array of discord message objects

    Permissions needed Condition
    VIEW_CHANNEL if channel is not a DM channel
    READ_MESSAGE_HISTORY if channel is not a DM channel, unless you want the API to return an empty Array

    Example

    // Fetch the last 20 messages from a channel
    const client = new SnowTransfer("TOKEN")
    const options = {
    limit: 20
    }
    const messages = await client.channel.getChannelMessages("channel id", options)

    Parameters

    Returns Promise<Message[]>

  • Get a list of pinned messages for a channel

    Returns

    Array of message objects

    Permissions needed Condition
    VIEW_CHANNEL if channel is not a DM channel
    READ_MESSAGE_HISTORY if channel is not a DM channel

    Example

    const client = new SnowTransfer("TOKEN")
    const messages = await client.channel.getPinnedMessages("channel id")

    Parameters

    • channelId: string

      Id of the channel

    Returns Promise<Message[]>

  • Get a list of users that reacted with a certain emoji on a certain message

    Returns

    Array of user objects

    Permissions needed Condition
    VIEW_CHANNEL if channel is not a DM channel
    READ_MESSAGE_HISTORY if channel is not a DM channel

    Example

    // This example uses a discord emoji
    const client = new SnowTransfer("TOKEN")
    const reactions = await client.channel.getReactions("channel Id", "message Id", encodeURIComponent("awooo:322522663304036352"))

    Parameters

    • channelId: string

      Id of the channel

    • messageId: string

      Id of the message

    • emoji: string

      reaction emoji

    • Optional query: {
          after?: string;
          limit?: number;
      }

      Options for getting users

      • Optional after?: string
      • Optional limit?: number

    Returns Promise<User[]>

  • Gets a member of a thread

    Returns

    A thread member

    Permissions needed Condition
    VIEW_CHANNEL always

    Example

    const client = new SnowTransfer("TOKEN")
    const member = await client.channel.getThreadMember("thread id", "user id")

    Parameters

    • threadId: string

      Id of the thread

    • userId: string

      Id of the user

    Returns Promise<ThreadMember>

  • Gets all members within a thread

    Returns

    Array of thread members

    Permissions needed Condition
    VIEW_CHANNEL always
    Intents
    GUILD_MEMBERS

    Example

    const client = new SnowTransfer("TOKEN")
    const members = await client.channel.getThreadMembers("thread id")

    Parameters

    • channelId: string

      Id of the Thread

    Returns Promise<ThreadMember[]>

  • Join a thread

    Returns

    Resolves the Promise on successful execution

    Permissions needed Condition
    VIEW_CHANNEL always

    Example

    const client = new SnowTransfer("TOKEN")
    client.channel.joinThread("thread id")

    Parameters

    • threadId: string

      Id of the thread

    Returns Promise<void>

  • Leave a thread

    Returns

    Resolves the Promise on successful execution

    Example

    const client = new SnowTransfer("TOKEN")
    client.channel.leaveThread("thread id")

    Parameters

    • threadId: string

      Id of the thread

    Returns Promise<void>

  • Remove a pinned message from a channel

    Returns

    Resolves the Promise on successful execution

    Permissions needed Condition
    VIEW_CHANNEL if channel is not a DM channel
    READ_MESSAGE_HISTORY if channel is not a DM channel
    MANAGE_MESSAGES if channel is not a DM channel

    Example

    // Remove a pinned message because mod abuse :(
    const client = new SnowTransfer("TOKEN")
    client.channel.removeChannelPinnedMessage("channel id", "message id", "Mod abuse")

    Parameters

    • channelId: string

      Id of the channel

    • messageId: string

      Id of the message

    • Optional reason: string

      Reason for removing the pinned message

    Returns Promise<void>

  • Remove a user from a thread

    Returns

    Resolves the Promise on successful execution

    Permissions needed Condition
    MANAGE_THREADS if the current user is not the creator of the thread

    Example

    const client = new SnowTransfer("TOKEN")
    client.channel.removeThreadMember("thread id", "user id")

    Parameters

    • threadId: string

      Id of the thread

    • userId: string

      Id of the user to remove

    Returns Promise<void>

  • Send an indicator that the current user is typing within a channel.

    You should generally avoid this method unless used for longer computations (>1s)

    Returns

    Resolves the Promise on successful execution

    Permissions needed Condition
    VIEW_CHANNEL if channel is not a DM channel
    SEND_MESSAGES if channel is not a thread
    SEND_MESSAGES_IN_THREADS if channel is a thread

    Example

    const client = new SnowTransfer("TOKEN")
    client.channel.sendChannelTyping("channel id")

    Parameters

    • channelId: string

      Id of the channel

    Returns Promise<void>

  • Update a guild channel or thread

    Returns

    discord channel object

    Permissions needed Condition
    MANAGE_CHANNELS always
    MANAGE_ROLES If modifying permission overwrites
    SEND_MESSAGES When editing a Thread to change the name, archived, auto_archive_duration, rate_limit_per_user or locked fields
    MANAGE_THREADS When editing a Thread and not modifying the name, archived, auto_archive_duration, rate_limit_per_user or locked fields

    Example

    // This example updates a channel with the passed id to use "New Name" as its name and "Look at this cool topic" as the topic
    const client = new SnowTransfer("TOKEN")
    const updateData = {
    name: "New Name",
    topic: "Look at this cool topic"
    }
    client.channel.updateChannel("channel id", updateData)

    Parameters

    • channelId: string

      Id of the guild channel

    • data: EditChannelData & {
          reason?: string;
      }

      Data to send

    Returns Promise<GuildChannel>

  • Parameters

    • channelId: string
    • data: EditThreadData & {
          reason?: string;
      }

    Returns Promise<ThreadChannel>

Constructors

  • Create a new Channel Method handler

    Usually SnowTransfer creates a method handler for you, this is here for completion

    You can access the methods listed via client.channel.method, where client is an initialized SnowTransfer instance

    Parameters

    • requestHandler: RequestHandler

      request handler that calls the rest api

    • disableEveryone: boolean

      Disable [at]everyone/[at]here on outgoing messages

    Returns ChannelMethods

Properties

disableEveryone: boolean
requestHandler: RequestHandler

Generated using TypeDoc