discord-interactions icon indicating copy to clipboard operation
discord-interactions copied to clipboard

Error: Request failed with status code 403

Open Samir-OP opened this issue 4 years ago • 2 comments

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

Samir-OP avatar Dec 22 '20 08:12 Samir-OP

Change the require to discord-slash-commands-client. There is a typo in the example. See if that resolves!

MatteZ02 avatar Dec 22 '20 11:12 MatteZ02

I think, you need to authorize bot on the current guild to add slash commands there. Use: image

SashaShtal avatar Jan 03 '21 23:01 SashaShtal