discord-interactions
discord-interactions copied to clipboard
Error: Request failed with status code 403
code:
const Discord = require("discord.js");
const interactions = require("discord-slash-commands");
// create a new client
const client = new Discord.Client();
const token = "BOT TOKEN";
// attach the interaction client to discord.js client
client.interactions = new interactions.Client(token, "BOT ID");
// attach and event listener for the ready event
client.on("ready", () => {
console.log("Client is ready!");
// Create a new command that we can test
client.interactions
.createCommand({
name: "blep",
description: "Send a random adorable animal photo",
options: [
{
name: "animal",
description: "The type of animal",
type: 3,
required: true,
choices: [
{
name: "Dog",
value: "animal_dog",
},
{
name: "Cat",
value: "animal_dog",
},
{
name: "Penguin",
value: "animal_penguin",
},
],
},
{
name: "only_smol",
description: "Whether to show only baby animals",
type: 5,
required: false,
},
],
})
.catch(console.error)
.then(console.log);
});
// attach and event listener for the interactionCreate event
client.on("interactionCreate", (interaction) => {
if (interaction.name === "ping") {
interaction.channel.send("pong");
}
});
// login
client.login(token);
Error:
Error: Request failed with status code 403
Change the require to discord-slash-commands-client. There is a typo in the example. See if that resolves!
I think, you need to authorize bot on the current guild to add slash commands there. Use: