Modules@robinpath/discord
discord

@robinpath/discord

0.1.1Node.jsPublic

Discord module for RobinPath.

Discord

Discord module for RobinPath.

Package: @robinpath/discord | Category: Messaging | Type: Integration

Authentication

discord.setToken "your-bot-token"

Call this once at the start of your script before using any other function. Credentials persist for the duration of the script execution.

Use Cases

Use the discord module when you need to:

  • Send a message via a Discord webhook URL (no bot token needed) -- Use discord.sendWebhook to perform this operation
  • Send a message to a Discord channel -- Use discord.sendMessage to perform this operation
  • Edit an existing message in a channel -- Use discord.editMessage to perform this operation
  • Delete a message from a channel -- Use discord.deleteMessage to perform this operation
  • Get information about a channel -- Use discord.getChannel to perform this operation

Quick Reference

FunctionDescriptionReturns
setTokenStore a Discord bot token for subsequent API calls{ok: true}
sendWebhookSend a message via a Discord webhook URL (no bot token needed)Webhook response or {ok: true}
sendMessageSend a message to a Discord channelDiscord Message object
editMessageEdit an existing message in a channelUpdated Discord Message object
deleteMessageDelete a message from a channel{ok: true}
getChannelGet information about a channelDiscord Channel object
listChannelsList all channels in a guild/serverArray of Discord Channel objects
createChannelCreate a new channel in a guild (0=text, 2=voice, 4=category, 13=stage, 15=forum)Created Discord Channel object
deleteChannelDelete a channelDeleted Channel object
addReactionAdd a reaction emoji to a message{ok: true}
removeReactionRemove own reaction from a message{ok: true}
pinMessagePin a message in a channel{ok: true}
unpinMessageUnpin a message from a channel{ok: true}
getGuildGet information about a guild/serverDiscord Guild object
listGuildMembersList members of a guild/serverArray of Guild Member objects
getGuildMemberGet a specific member of a guildGuild Member object
addRoleAdd a role to a guild member{ok: true}
removeRoleRemove a role from a guild member{ok: true}
listRolesList all roles in a guild/serverArray of Role objects
createRoleCreate a new role in a guild/serverCreated Role object
banMemberBan a member from a guild/server{ok: true}
unbanMemberRemove a ban for a user from a guild/server{ok: true}
kickMemberKick a member from a guild/server{ok: true}
createThreadCreate a new thread in a channelCreated Thread Channel object
sendEmbedSend a rich embed message to a channelDiscord Message object with embed
getUserGet information about a Discord userDiscord User object
listMessagesList messages in a channelArray of Discord Message objects
createInviteCreate an invite for a channelDiscord Invite object with code

Functions

setToken

Store a Discord bot token for subsequent API calls

Module: discord | Returns: object -- {ok: true}

discord.setToken "your-bot-token"
ParameterTypeRequiredDescription
botTokenstringYesDiscord bot token

sendWebhook

Send a message via a Discord webhook URL (no bot token needed)

Module: discord | Returns: object -- Webhook response or {ok: true}

discord.sendWebhook "https://discord.com/api/webhooks/..." "Hello!" {"username": "MyBot"}
ParameterTypeRequiredDescription
webhookUrlstringYesDiscord webhook URL
contentstringNoMessage text content
optionsobjectNo{embeds?, username?, avatarUrl?}

sendMessage

Send a message to a Discord channel

Module: discord | Returns: object -- Discord Message object

discord.sendMessage "123456789" "Hello from RobinPath!"
ParameterTypeRequiredDescription
channelIdstringYesChannel ID
contentstringNoMessage text content
optionsobjectNo{embeds?, components?}

editMessage

Edit an existing message in a channel

Module: discord | Returns: object -- Updated Discord Message object

discord.editMessage "123456789" "987654321" "Updated text"
ParameterTypeRequiredDescription
channelIdstringYesChannel ID
messageIdstringYesMessage ID to edit
contentstringNoNew message text content
optionsobjectNo{embeds?, components?}

deleteMessage

Delete a message from a channel

Module: discord | Returns: object -- {ok: true}

discord.deleteMessage "123456789" "987654321"
ParameterTypeRequiredDescription
channelIdstringYesChannel ID
messageIdstringYesMessage ID to delete

getChannel

Get information about a channel

Module: discord | Returns: object -- Discord Channel object

discord.getChannel "123456789"
ParameterTypeRequiredDescription
channelIdstringYesChannel ID

listChannels

List all channels in a guild/server

Module: discord | Returns: array -- Array of Discord Channel objects

discord.listChannels "123456789"
ParameterTypeRequiredDescription
guildIdstringYesGuild/server ID

createChannel

Create a new channel in a guild (0=text, 2=voice, 4=category, 13=stage, 15=forum)

Module: discord | Returns: object -- Created Discord Channel object

discord.createChannel "123456789" "general-chat" 0 {"topic": "General discussion"}
ParameterTypeRequiredDescription
guildIdstringYesGuild/server ID
namestringYesChannel name
typenumberNoChannel type (0=text, 2=voice). Default: 0
optionsobjectNo{topic?, parentId?, nsfw?, rateLimitPerUser?, bitrate?, userLimit?}

deleteChannel

Delete a channel

Module: discord | Returns: object -- Deleted Channel object

discord.deleteChannel "123456789"
ParameterTypeRequiredDescription
channelIdstringYesChannel ID to delete

addReaction

Add a reaction emoji to a message

Module: discord | Returns: object -- {ok: true}

discord.addReaction "123456789" "987654321" "👍"
ParameterTypeRequiredDescription
channelIdstringYesChannel ID
messageIdstringYesMessage ID
emojistringYesEmoji (Unicode or custom format name:id)

removeReaction

Remove own reaction from a message

Module: discord | Returns: object -- {ok: true}

discord.removeReaction "123456789" "987654321" "👍"
ParameterTypeRequiredDescription
channelIdstringYesChannel ID
messageIdstringYesMessage ID
emojistringYesEmoji (Unicode or custom format name:id)

pinMessage

Pin a message in a channel

Module: discord | Returns: object -- {ok: true}

discord.pinMessage "123456789" "987654321"
ParameterTypeRequiredDescription
channelIdstringYesChannel ID
messageIdstringYesMessage ID to pin

unpinMessage

Unpin a message from a channel

Module: discord | Returns: object -- {ok: true}

discord.unpinMessage "123456789" "987654321"
ParameterTypeRequiredDescription
channelIdstringYesChannel ID
messageIdstringYesMessage ID to unpin

getGuild

Get information about a guild/server

Module: discord | Returns: object -- Discord Guild object

discord.getGuild "123456789"
ParameterTypeRequiredDescription
guildIdstringYesGuild/server ID

listGuildMembers

List members of a guild/server

Module: discord | Returns: array -- Array of Guild Member objects

discord.listGuildMembers "123456789" {"limit": 100}
ParameterTypeRequiredDescription
guildIdstringYesGuild/server ID
optionsobjectNo{limit?, after?}

getGuildMember

Get a specific member of a guild

Module: discord | Returns: object -- Guild Member object

discord.getGuildMember "123456789" "987654321"
ParameterTypeRequiredDescription
guildIdstringYesGuild/server ID
userIdstringYesUser ID

addRole

Add a role to a guild member

Module: discord | Returns: object -- {ok: true}

discord.addRole "123456789" "987654321" "111222333"
ParameterTypeRequiredDescription
guildIdstringYesGuild/server ID
userIdstringYesUser ID
roleIdstringYesRole ID to add

removeRole

Remove a role from a guild member

Module: discord | Returns: object -- {ok: true}

discord.removeRole "123456789" "987654321" "111222333"
ParameterTypeRequiredDescription
guildIdstringYesGuild/server ID
userIdstringYesUser ID
roleIdstringYesRole ID to remove

listRoles

List all roles in a guild/server

Module: discord | Returns: array -- Array of Role objects

discord.listRoles "123456789"
ParameterTypeRequiredDescription
guildIdstringYesGuild/server ID

createRole

Create a new role in a guild/server

Module: discord | Returns: object -- Created Role object

discord.createRole "123456789" "Moderator" {"color": 3447003, "hoist": true}
ParameterTypeRequiredDescription
guildIdstringYesGuild/server ID
namestringYesRole name
optionsobjectNo{color?, permissions?, hoist?, mentionable?}

banMember

Ban a member from a guild/server

Module: discord | Returns: object -- {ok: true}

discord.banMember "123456789" "987654321" "Spam"
ParameterTypeRequiredDescription
guildIdstringYesGuild/server ID
userIdstringYesUser ID to ban
reasonstringNoReason for the ban (appears in audit log)

unbanMember

Remove a ban for a user from a guild/server

Module: discord | Returns: object -- {ok: true}

discord.unbanMember "123456789" "987654321"
ParameterTypeRequiredDescription
guildIdstringYesGuild/server ID
userIdstringYesUser ID to unban

kickMember

Kick a member from a guild/server

Module: discord | Returns: object -- {ok: true}

discord.kickMember "123456789" "987654321" "Inactive"
ParameterTypeRequiredDescription
guildIdstringYesGuild/server ID
userIdstringYesUser ID to kick
reasonstringNoReason for the kick (appears in audit log)

createThread

Create a new thread in a channel

Module: discord | Returns: object -- Created Thread Channel object

discord.createThread "123456789" "Discussion" {"autoArchiveDuration": 1440}
ParameterTypeRequiredDescription
channelIdstringYesChannel ID
namestringYesThread name
optionsobjectNo{autoArchiveDuration?, messageId?, type?, invitable?}

sendEmbed

Send a rich embed message to a channel

Module: discord | Returns: object -- Discord Message object with embed

discord.sendEmbed "123456789" {"title": "Status", "description": "All systems operational", "color": 5763719}
ParameterTypeRequiredDescription
channelIdstringYesChannel ID
embedobjectYesEmbed object with title, description, color, fields, footer, etc.

getUser

Get information about a Discord user

Module: discord | Returns: object -- Discord User object

discord.getUser "987654321"
ParameterTypeRequiredDescription
userIdstringYesUser ID

listMessages

List messages in a channel

Module: discord | Returns: array -- Array of Discord Message objects

discord.listMessages "123456789" {"limit": 50}
ParameterTypeRequiredDescription
channelIdstringYesChannel ID
optionsobjectNo{limit?, before?, after?, around?}

createInvite

Create an invite for a channel

Module: discord | Returns: object -- Discord Invite object with code

discord.createInvite "123456789" {"maxAge": 86400, "maxUses": 10}
ParameterTypeRequiredDescription
channelIdstringYesChannel ID
optionsobjectNo{maxAge?, maxUses?, temporary?, unique?}

Error Handling

All functions throw on failure. Common errors:

ErrorCause
Bot token not set. Call discord.setToken first.Check the error message for details
Discord API error (${response.status}): ${msg}Check the error message for details
Bot token is required.Check the error message for details
Webhook URL is required.Check the error message for details
Discord webhook failed (${response.status}): ${errText}Check the error message for details
channelId is required.Check the error message for details
messageId is required.Check the error message for details
guildId is required.Check the error message for details
@desc "Send webhook and validate result"
do
  set $result as discord.sendWebhook "https://discord.com/api/webhooks/..." "Hello!" {"username": "MyBot"}
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. List and iterate Channel

Retrieve all items and loop through them.

@desc "Setup authentication"
do
  discord.setToken $token
enddo

@desc "Get channel and iterate results"
do
  set $result as discord.getChannel "123456789"
  each $item in $result
    print $item
  end
enddo

2. Create a new item with sendWebhook

Create a new resource and capture the result.

@desc "Setup authentication"
do
  discord.setToken $token
enddo

@desc "Send webhook"
do
  set $result as discord.sendWebhook "https://discord.com/api/webhooks/..." "Hello!" {"username": "MyBot"}
  print "Created: " + $result
enddo

3. Create and update workflow

Create an item and then update it.

@desc "Setup authentication"
do
  discord.setToken $token
enddo

@desc "Send webhook and edit message"
do
  set $created as discord.sendWebhook "https://discord.com/api/webhooks/..." "Hello!" {"username": "MyBot"}
  # Update the created item
  discord.editMessage "123456789" "987654321" "Updated text"
enddo

4. Check before creating

List existing items and only create if needed.

@desc "Setup authentication"
do
  discord.setToken $token
enddo

@desc "Get channel and send webhook"
do
  set $existing as discord.getChannel "123456789"
  if $existing == null
    discord.sendWebhook "https://discord.com/api/webhooks/..." "Hello!" {"username": "MyBot"}
    print "Item created"
  else
    print "Item already exists"
  end
enddo

5. Multi-step Discord workflow

Chain multiple discord operations together.

@desc "Setup authentication"
do
  discord.setToken $token
enddo

@desc "Send webhook, send message, and more"
do
  set $r_sendWebhook as discord.sendWebhook "https://discord.com/api/webhooks/..." "Hello!" {"username": "MyBot"}
  set $r_sendMessage as discord.sendMessage "123456789" "Hello from RobinPath!"
  set $r_editMessage as discord.editMessage "123456789" "987654321" "Updated text"
  print "All operations complete"
enddo

6. Safe sendWebhook with validation

Check results before proceeding.

@desc "Setup authentication"
do
  discord.setToken $token
enddo

@desc "Send webhook and validate result"
do
  set $result as discord.sendWebhook "https://discord.com/api/webhooks/..." "Hello!" {"username": "MyBot"}
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • slack -- Slack module for complementary functionality
  • teams -- Teams module for complementary functionality
  • telegram -- Telegram module for complementary functionality
  • whatsapp -- WhatsApp module for complementary functionality
  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.1latest1 months ago
Install
$ robinpath add @robinpath/discord

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.1
LicenseMIT
Unpacked Size8.7 KB
Versions1
Weekly Downloads26
Total Downloads26
Stars0
Last Publish1 months ago
Created1 months ago