Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ChannelMethods

Methods for interacting with Channels and Messages

Hierarchy

  • ChannelMethods

Index

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: <internal>.RequestHandler

      request handler that calls the rest api

    • disableEveryone: boolean

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

    Returns <internal>.ChannelMethods

Properties

disableEveryone: boolean
requestHandler: <internal>.RequestHandler

Methods

  • addChannelPinnedMessage(channelId: string, messageId: string, reason?: string): Promise<void>
  • Pin a message within a channel

    Parameters

    • channelId: string

      Id of the channel

    • messageId: string

      Id of the message

    • Optional reason: string

      Reason for pinning the message

    Returns Promise<void>

    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
  • addThreadMember(channelId: string, userId: string): Promise<void>
  • Add a user to a thread

    Parameters

    • channelId: string

      Id of the channel

    • userId: string

      Id of the user to add

    Returns Promise<void>

    Resolves the Promise on successful execution

    Permissions needed Condition
    CurrentUser added to Thread always
    SEND_MESSAGES_IN_THREADS always
  • bulkDeleteMessages(channelId: string, messages: string[], reason?: string): Promise<void>
  • Bulk delete messages, messages may not be older than 2 weeks

    Parameters

    • channelId: string

      Id of the channel

    • messages: string[]

      array of message ids to delete

    • Optional reason: string

      Reason for deleting the messages

    Returns Promise<void>

    Resolves the Promise on successful execution

    Permissions needed Condition
    VIEW_CHANNEL always
    MANAGE_MESSAGES always
  • Creates a new Message within a channel

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

    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's 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 to sent a message to

    • data: string | <internal>.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

    • Optional options: { disableEveryone?: boolean }
      • Optional disableEveryone?: boolean

    Returns Promise<<internal>.Message>

    (https://discord.com/developers/docs/resources/channel#message-object) object

    Permissions needed Condition
    VIEW_CHANNEL always
    SEND_MESSAGES if the message was sent by the current user and not in a thread channel
    SEND_MESSAGES_IN_THREADS if the message was sent by the current user and is in a thread channel
  • createReaction(channelId: string, messageId: string, emoji: string): Promise<void>
  • Adds a reaction to a message

    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>

    Resolves the Promise on successful execution

    Permissions needed Condition
    VIEW_CHANNEL always
    READ_MESSAGE_HISTORY always
    ADD_REACTIONS When no other user has reacted with the emoji used
  • Creates a public thread off a message in a channel

    Parameters

    • channelId: string

      Id of the channel

    • messageId: string

      Id of the message

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

      Thread meta data

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

    Returns Promise<<internal>.NewsThread | <internal>.PublicThread>

    (https://discord.com/developers/docs/resources/channel#channel-object) object

    Permissions needed Condition
    VIEW_CHANNEL always
    CREATE_PUBLIC_THREADS always
  • Creates a thread under a channel without a message

    Parameters

    • channelId: string

      Id of the channel

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

      Thread meta data

      • auto_archive_duration: 60 | 1440 | 4320 | 10080
      • Optional invitable?: boolean
      • name: string
      • Optional reason?: string
      • type: 10 | 12 | 11

    Returns Promise<<internal>.NewsThread | <internal>.PublicThread | <internal>.PrivateThread>

    (https://discord.com/developers/docs/resources/channel#channel-object) object

    Permissions needed Condition
    VIEW_CHANNEL always
    CREATE_PUBLIC_THREADS if creating a public thread
    CREATE_PRIVATE_THREADS if creating a private thread
  • Crosspost a message in a news channel to all following channels

    Parameters

    • channelId: string

      Id of the news channel

    • messageId: string

      Id of the message

    Returns Promise<<internal>.Message>

    (https://discord.com/developers/docs/resources/channel#message-object) object

    Permissions needed Condition
    VIEW_CHANNEL always
    SEND_MESSAGES if the message was sent by the current user and not in a thread channel
    SEND_MESSAGES_IN_THREADS if the message was sent by the current user and is in a thread channel
    MANAGE_MESSAGES if the message wasn't sent by the current user
  • deleteAllReactions(channelId: string, messageId: string): Promise<void>
  • Delete all reactions from a message

    Parameters

    • channelId: string

      Id of the channel

    • messageId: string

      Id of the message

    Returns Promise<void>

    Resolves the Promise on successful execution

    Permissions needed Condition
    VIEW_CHANNEL always
    READ_MESSAGE_HISTORY always
    MANAGE_MESSAGES always
  • Delete a channel or thread via Id

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

    Be careful with deleting Guild Channels as this can not be undone!

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

    Parameters

    • channelId: string

      Id of the channel

    • Optional reason: string

      Reason for deleting the channel

    Returns Promise<<internal>.Channel>

    (https://discord.com/developers/docs/resources/channel#channel-object) object

    Permissions needed Condition
    VIEW_CHANNEL always
    MANAGE_CHANNELS When deleting a Guild Channel
    MANAGE_THREADS When channelId is a Thread's Id
  • deleteChannelPermission(channelId: string, permissionId: string, reason?: string): Promise<void>
  • Delete a permission overwrite from a channel

    Parameters

    • channelId: string

      Id of the channel

    • permissionId: string

      Id of the permission overwrite

    • Optional reason: string

      Reason for deleting the permission

    Returns Promise<void>

    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
  • deleteMessage(channelId: string, messageId: string, reason?: string): Promise<void>
  • Delete a 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>

    Resolves the Promise on successful execution

    Permissions needed Condition
    VIEW_CHANNEL always
    MANAGE_MESSAGES When the bot isn't the author of the message
  • deleteReaction(channelId: string, messageId: string, emoji: string, userId?: string): Promise<void>
  • Delete a reaction from a message

    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 channel

    • messageId: string

      Id of the message

    • emoji: string

      reaction emoji

    • Optional userId: string

      Id of the user

    Returns Promise<void>

    Resolves the Promise on successful execution

    Permission Condition
    MANAGE_MESSAGES always
    VIEW_CHANNEL always
    READ_MESSAGE_HISTORY always
  • deleteReactionSelf(channelId: string, messageId: string, emoji: string): Promise<void>
  • Delete a reaction added by the current user from a message

    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>

    Resolves the Promise on successful execution

    Permission Condition
    VIEW_CHANNEL always
    READ_MESSAGE_HISTORY always
  • Modify the permission overwrites of a channel

    Parameters

    Returns Promise<void>

    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
  • Edit a message sent by the current user or edit the message flags of another user's message

    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 | <internal>.EditMessageData

      Data to send

    • Optional options: { disableEveryone?: boolean }
      • Optional disableEveryone?: boolean

    Returns Promise<<internal>.Message>

    (https://discord.com/developers/docs/resources/channel#message-object) object

    Permissions needed Condition
    VIEW_CHANNEL always
    MANAGE_MESSAGES When editing someone else's message to set flags
  • Get a list of invites for a channel

    Parameters

    • channelId: string

      Id of the channel

    Returns Promise<<internal>.Invite[]>

    Array of invite objects (with metadata)

    Permissions needed Condition
    VIEW_CHANNEL always
    MANAGE_CHANNELS always
  • Get a single message via Id

    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<<internal>.Message>

    (https://discord.com/developers/docs/resources/channel#message-object) object

    Permissions needed Condition
    VIEW_CHANNEL always
    READ_MESSAGE_HISTORY always
  • Get a list of messages from a channel

    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<<internal>.Message[]>

    Array of discord message objects

    Permissions needed Condition
    VIEW_CHANNEL always
    READ_MESSAGE_HISTORY always
  • Get a list of pinned messages for a channel

    Parameters

    • channelId: string

      Id of the channel

    Returns Promise<<internal>.Message[]>

    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
  • Gets all members within a thread

    Parameters

    • channelId: string

      Id of the Thread

    Returns Promise<<internal>.ThreadMember[]>

    Array of thread member objects

    Permissions needed Condition
    VIEW_CHANNEL always
    GUILD_MEMBERS gateway intent always
  • Get a list of users that reacted with a certain emoji on a certain message

    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

    Returns Promise<<internal>.User[]>

    Array of user objects

    Permissions needed Condition
    VIEW_CHANNEL always
    READ_MESSAGE_HISTORY always
  • joinThread(channelId: string): Promise<void>
  • Join a thread

    Parameters

    • channelId: string

      Id of the channel

    Returns Promise<void>

    Resolves the Promise on successful execution

    Permissions needed Condition
    VIEW_CHANNEL always
  • leaveThread(channelId: string): Promise<void>
  • Leave a thread

    Parameters

    • channelId: string

      Id of the channel

    Returns Promise<void>

    Resolves the Promise on successful execution

  • removeChannelPinnedMessage(channelId: string, messageId: string, reason?: string): Promise<void>
  • Remove a pinned message from a channel

    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>

    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
  • removeThreadMember(channelId: string, userId: string): Promise<void>
  • Remove a user from a thread

    Parameters

    • channelId: string

      Id of the channel

    • userId: string

      Id of the user to remove

    Returns Promise<void>

    Resolves the Promise on successful execution

    Permissions needed Condition
    MANAGE_THREADS if the current user is not the creator of the thread
  • startChannelTyping(channelId: string): 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)

    Parameters

    • channelId: string

      Id of the channel

    Returns Promise<void>

    Resolves the Promise on successful execution

    Permissions needed Condition
    VIEW_CHANNEL always
    SEND_MESSAGES if channel is not a thread
    SEND_MESSAGES_IN_THREADS if channel is a thread
  • Update a channel or thread

    example

    // This example updates a channel with the passed id to use "New Name" as it's 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

    Returns Promise<<internal>.Channel>

    (https://discord.com/developers/docs/resources/channel#channel-object) object

    Permissions needed Condition
    VIEW_CHANNEL always
    MANAGE_CHANNELS always
    MANAGE_THREADS When editing a Thread to change the name, archived, auto_archive_duration, rate_limit_per_user or locked fields

Generated using TypeDoc