README
discord-interactions-helper
This package enables the use of interactions.
This is for Discord.js version 12 only.
First
const Discord = require('discord.js');
const client = new Discord.Client();
require('discord-interactions-helper')(client);
// Enter the code here
client.login(TOKEN);
⚠️ Warning ⚠️
Bad...
const { Client, MessageSelectMenu } = require('discord.js');
const client = new Client();
require('discord-interactions-helper')(client);
// MessageSelectMenu is undefined.
OK.
const Discord = require('discord.js');
const client = new Discord.Client();
require('discord-interactions-helper')(client);
const { MessageSelectMenu } = Discord;
// MessageSelectMenu is a constructor.
Example
Create a Guild Slash Command
client.on('ready', () => {
const guild = client.guilds.resolve(GUILD_ID);
guild.commands.create({
name: "goodmorning",
description: "Good morning command"
});
});
See GuildApplicationCommandManager#create.
Create a Global Slash Command
client.on('ready', () => {
client.commands.create({
name: "goodmorning",
description: "Good morning command"
});
});
See ApplicationCommandManager#create.
Fetch and Edit a Guild Slash Command
client.on('ready', () => {
const guild = client.guilds.resolve(GUILD_ID);
const command = await guild.commands.fetch(COMMAND_ID);
command.edit({
description: "Good morning command"
});
});
See GuildApplicationCommandManager#fetch and ApplicationCommand#edit.
Fetch and Edit a Global Slash Command
client.on('ready', () => {
const command = await client.commands.fetch(COMMAND_ID);
command.edit({
description: "Good morning command"
});
});
See ApplicationCommandManager#fetch and ApplicationCommand#edit.
Receive a Slash Command Interaction and Respond to the Interaction
client.on("interactionCreate", interaction => {
if (!interaction.isCommand()) return;
console.log("Receive!");
interaction.reply("Recieved!");
interaction.followUp("Followup Message 1");
interaction.followUp("Followup Message 2");
});
See CommandInteraction#reply and CommandInteraction#followUp.
Send a message with Buttons
const Discord = require('discord.js');
const client = new Discord.Client();
require('discord-interactions-helper')(client);
client.on("message", message => {
if (message.author.bot) return;
const button = new Discord.MessageButton()
.setCustomId("custom-id")
.setLabel("The Button!")
.setStyle("PRIMARY");
const actionRow = new Discord.MessageActionRow();
actionRow.addComponents(button);
message.channel.send("Message with Components!", {
components: [ actionRow ]
});
});
Send a message with Select Menus
const Discord = require('discord.js');
const client = new Discord.Client();
require('discord-interactions-helper')(client);
client.on("message", message => {
if (message.author.bot) return;
const selectMenu = new Discord.MessageSelectMenu()
.setCustomId("custom-id")
.addOptions({
label: "Choice 1",
value: "choice-1"
}, {
label: "Choice 2",
value: "choice-2"
});
const actionRow = new Discord.MessageActionRow();
actionRow.addComponents(selectMenu);
message.channel.send("Message with Components!", {
components: [ actionRow ]
});
});