Skip to main content

Discord

Discord is the easiest way to talk over voice, video, and text. With this integration, you can easily use Discord API.

Tagsmessagingbot

Credential configuration

The token field corresponds to the token of the bot you want to use. If you don't have a bot, you can create one and get the token following these steps.

For more information about Discord intents, visit this page.

In the extra options field, you can include most of the parameters found here.

Here is an example of a filled credential configuration form in YepCode:

Discord Snippets available in editor

note

The title is the triggering text for YepCode to autocomplete the script.

Integration

New integration from credential
const discordClient = yepcode.integration.discord("credential-slug");
New integration from plain authentication data
const { Client, Intents } = require("discord.js");

// You can use the intents you want, or an empty list
const discordClient = new Client({ intents: [Intents.FLAGS.GUILDS] });

discordClient.login("token")

Close Connection

Close connection
discordClient.destroy()

Get Servers which Bot is in

Get servers which bot is in
discordClient.guilds.fetch({ limit: 10 }).then(servers => {
servers.forEach(server => console.log(`Found server with id: ${server.id}`))
})

Get Server

Get server
const server = await discordClient.guilds.fetch("guildId");

console.log(server)

Get Server Channels

Get server channels
const server = await discordClient.guilds.fetch("guildId");

const channels = await server.channels.fetch();

channels.forEach((channel) => {
console.log(`Found channel: id: ${channel.id} - name: ${channel.name} - type: ${channel.type}`);
});

Get Channel Messages

Get channel messages
const channel = await discordClient.channels.fetch("channelId");

channel.messages.fetch({ limit: 10 }).then((messages) => {
messages.forEach((message) => {
console.log(`Found message with content: ${message.content}`);
});
});

Create a Command

Create a command
const command = await discordClient.application.commands
.create({
name: "command name",
description: "command description",
});

console.log(`Created command with id ${command.id}`)

Delete a Command

Delete a command
discordClient.application.commands.delete(command-id)
.then(() => console.log("Deleted command"))
.catch(console.error);