DiscordAPIError[50001]: Missing Access discord.js bot - javascript

So been following a guide to get started on a discord bot, but keep getting this error message when running node deploy-commands.js
DiscordAPIError[50001]: Missing Access
at SequentialHandler.runRequest (C:\Users\voidy\.vscode\python\test-codes\DiscordBot\node_modules\#discordjs\rest\dist\lib\handlers\SequentialHandler.cjs:293:15)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async SequentialHandler.queueRequest (C:\Users\voidy\.vscode\python\test-codes\DiscordBot\node_modules\#discordjs\rest\dist\lib\handlers\SequentialHandler.cjs:99:14)
at async REST.request (C:\Users\voidy\.vscode\python\test-codes\DiscordBot\node_modules\#discordjs\rest\dist\lib\REST.cjs:52:22) {
rawError: { message: 'Missing Access', code: 50001 },
code: 50001,
status: 403,
method: 'PUT',
url: 'https://discord.com/api/v10/applications/1018530446092554290/guilds/1018530446092554290/commands',
requestBody: { files: undefined, json: [ [Object], [Object], [Object] ] }
}
I have already added both the bot and applications.commands scope for my bot, and kicked it and re-added it quite a few times with no luck.
The guildId, clientId and Token are all correct, even reset and used the new token instead.
Here's the code if needed
const { SlashCommandBuilder, Routes } = require('discord.js');
const { REST } = require('#discordjs/rest');
const { clientId, guildId, token } = require('./config.json');
const commands = [
new SlashCommandBuilder().setName('ping').setDescription('Replies with pong!'),
new SlashCommandBuilder().setName('server').setDescription('Replies with server info!'),
new SlashCommandBuilder().setName('user').setDescription('Replies with user info!'),
]
.map(command => command.toJSON());
const rest = new REST({ version: '10' }).setToken(token);
rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands })
.then(() => console.log('Successfully registered application commands.'))
.catch(console.error);

Related

How can I delete a SlashCommand from specific guild? (discord.js)

I am trying to delete a Slash Command in specific guild but when I use the code of documentation it drop me this error:
DiscordAPIError[10063]: Unknown application command at SequentialHandler.runRequest (D:\Bots_Discord\robbie\bot\node_modules\#discordjs\rest\dist\lib\handlers\SequentialHandler.cjs:287:15) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async SequentialHandler.queueRequest (D:\Bots_Discord\robbie\bot\node_modules\#discordjs\rest\dist\lib\handlers\SequentialHandler.cjs:99:14) at async REST.request (D:\Bots_Discord\robbie\bot\node_modules\#discordjs\rest\dist\lib\REST.cjs:52:22) at async Object.run (D:\Bots_Discord\robbie\bot\slashCommands\showCommands.js:15:5) at async Object.run (D:\Bots_Discord\robbie\bot\events\interactionCreate\interactionHandler.js:56:7) { rawError: { message: 'Unknown application command', code: 10063 }, code: 10063, status: 404, method: 'DELETE', url: 'https://discord.com/api/v10/applications/998433286261067807/guilds/998574340419366952/commands/1009128621543264396', requestBody: { files: undefined, json: undefined } }
I use the command id that is in field of guild integrations
https://i.stack.imgur.com/x8iSl.png
const { REST } = require('#discordjs/rest')
const { Routes, SlashCommandBuilder } = require('discord.js')
require('dotenv').config()
const rest = new REST({ version: '10' }).setToken(process.env.SECRET_TOKEN);
module.exports = {
forEveryone: false,
data: new SlashCommandBuilder()
.setName('deletecommand')
.setDescription('delete command'),
async run(client, interaction) {
await rest.delete(Routes.applicationGuildCommand(client.user.id, interaction.guild.id, '1009128621543264396'))
.then(() => console.log('Successfully deleted guild command'))
.catch(console.error)
}
}
Node Version: v16.16.0
Discord.js Version: v14.2.0
Discord documentation: https://i.stack.imgur.com/jUgpg.png
I'm not sure yet, but it looks like you can only delete slash commands from guilds that you have specifically registered the command in ("guild-based commands"). If you have registered the slash command globally, across all guilds, you can't delete it from just one specific guild. The part of the guide that you included a screenshot of has a section right below it on deleting a global command, here's the code snippet from that guide:
// for guild-based commands
rest.delete(Routes.applicationGuildCommand(clientId, guildId, 'commandId'))
.then(() => console.log('Successfully deleted guild command'))
.catch(console.error);
// for global commands
rest.delete(Routes.applicationCommand(clientId, 'commandId'))
.then(() => console.log('Successfully deleted application command'))
.catch(console.error);

DiscordAPIError, my Discordbot cannot embed

I am trying to program a discord chat bot, that when the command '!help' is directed to a certain text channel, the bot writes a direct message to the person who wrote the command in order to answer a series of questions, this is the code that I try:
const {Client, RichEmbed, Intents, MessageEmbed} = require('discord.js');
const bot = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.DIRECT_MESSAGES] });
const token = 'TOKEN';
const PREFIX = '!';
bot.on('ready', () => {
console.log(`Logged in as ${bot.user.tag}!`);
})
bot.on('messageCreate', message => {
let args = message.content.substring(PREFIX.length).split(" ");
switch (args[0]) {
case 'help':
const Embed = new MessageEmbed()
.setTitle("Helper Embed")
.setColor(0xFF0000)
.setDescription("Make sure to use the !help to get access to the commands");
message.author.send(Embed);
break;
}
});
bot.login(token);
However, it throws me a DiscordAPIError error. Which is the following:
node_modules/discord.js/src/rest/RequestHandler.js:350
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Cannot send an empty message
at RequestHandler.execute (/Users/mybot/node_modules/discord.js/src/rest/RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (/Users/mybot/node_modules/discord.js/src/rest/RequestHandler.js:51:14)
at async DMChannel.send (/Users/mybot/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:176:15) {
method: 'post',
path: '/channels/98595393932745/messages',
code: 50006,
httpStatus: 400,
requestData: {
json: {
content: undefined,
tts: false,
nonce: undefined,
embeds: undefined,
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined
},
files: []
}
}
If I'm correct and you are using discord.js v13, you have to use message.author.send({embeds: [Embed]}) to send embeds!
In discord.js v13, you no longer send messages directly, you need to specify if its an embed, components etc. here's an example
message.author.send({content: 'you need help'}) // Normal message
message.author.send({embeds: [Embed]}) // embedded message
message.author.send({content: 'you need help', embeds: [Embed], components: [buttonRow]}) // To send message, embed and components
To make an interaction reply ephemeral, you use the same method, but boolean:
interaction.reply({embeds: [Embed], components: [row], ephemeral: true})

How to fix error 50035 number type coerce when registering commands

I am trying to make a discord bot and I haven't used slash commands before as I haven't made a bot in a while, and I am getting this error when trying to register my commands:
DiscordAPIError[50035]: Invalid Form Body
application_id[NUMBER_TYPE_COERCE]: Value "undefined" is not snowflake.
guild_id[NUMBER_TYPE_COERCE]: Value "undefined" is not snowflake.
at SequentialHandler.runRequest (/home/runner/blkt/node_modules/#discordjs/rest/dist/index.js:708:15)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async SequentialHandler.queueRequest (/home/runner/blkt/node_modules/#discordjs/rest/dist/index.js:511:14) {
rawError: {
code: 50035,
errors: { application_id: [Object], guild_id: [Object] },
message: 'Invalid Form Body'
},
code: 50035,
status: 400,
method: 'put',
url: 'https://discord.com/api/v9/applications/undefined/guilds/undefined/commands',
requestBody: { files: undefined, json: [ [Object] ] }
}
I am following the discordjs.guide tutorial and my deploy-commands.js code is this:
const token = process.env['token'];
const clientId = process.env['clientid'];
const guildId = process.env['testguildid']
const fs = require('node:fs');
const path = require('node:path');
const { REST } = require('#discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const commands = [];
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
commands.push(command.data.toJSON());
}
const rest = new REST({ version: '9' }).setToken(token);
rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands })
.then(() => console.log('Successfully registered application commands.'))
.catch(console.error);
application_id[NUMBER_TYPE_COERCE]: Value "undefined" is not snowflake.
guild_id[NUMBER_TYPE_COERCE]: Value "undefined" is not snowflake.
Please make sure you are inputting right IDs as String
const clientId = process.env['clientid'];
const guildId = process.env['testguildid']
go to your .env file and make sure
clientid=ID
testguildid=ID
and make sure you are initializing config of the .env file with library like dotenv
url: 'https://discord.com/api/v9/applications/undefined/guilds/undefined/commands',
As you see here both have values of undefined

DiscordAPIError: Unknown interaction in ALL interactions

My bot was working completely fine. And then all of a sudden I started getting the Unknown Interaction error.
DiscordAPIError: Unknown interaction
at RequestHandler.execute (/Users/Aplex/Documents/Aplel/node_modules/discord.js/src/rest/RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (/Users/Aplex/Documents/Aplel/node_modules/discord.js/src/rest/RequestHandler.js:51:14)
at async CommandInteraction.reply (/Users/Aplex/Documents/Aplel/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:99:5) {
method: 'post',
path: Path here yk,
code: 10062,
httpStatus: 404,
requestData: {
json: {
type: 4,
data: {
content: 'POING',
tts: false,
nonce: undefined,
embeds: undefined,
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined
}
},
files: []
}
}
This ping command is just an example, I am getting this error in nearly every interaction command I type on Discord. I have been looking for the issue for a very long time now but still couldn't find anything.
This is the ping command:
const { CommandInteraction } = require("discord.js");
module.exports = {
name: "ping",
description: "Ping",
permission: "ADMINISTRATOR",
/**
*
* #param {CommandInteraction} interaction
*/
execute(interaction) {
interaction.reply({content: "POING"})
}
}
It's just a basic command I made to test if the issue is in the commands itself or somewhere else. Seems like it's somewhere else.
This is my interactionCreate event:
const { Client, CommandInteraction, MessageEmbed } = require("discord.js");
module.exports = {
name: "interactionCreate",
/**
*
* #param {CommandInteraction} interaction
* #param {Client} client
*/
async execute(interaction, client){
if(interaction.isCommand() || interaction.isContextMenu()){
const command = client.commands.get(interaction.commandName);
if(!command) return interaction.reply({embeds : [
new MessageEmbed()
.setColor("RED")
.setDescription("⛔ An error occurred while running this command.")
]}) && client.commands.delete(interaction.commandName);
command.execute(interaction, client);
}
}
}

"DiscordAPIError: Cannot send an empty message"

I am trying to make a profanity discord bot. Whenever I run it, it is fine but when I type a word that it's supposed to filter out, it stops. This is the error I get when typing in a blocked word.
DiscordAPIError: Cannot send an empty message
at RequestHandler.execute (C:\Users\loser\Desktop\word filter bot\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (C:\Users\loser\Desktop\word filter bot\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
at async TextChannel.send (C:\Users\loser\Desktop\word filter bot\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:175:15)
at async Client.<anonymous> (C:\Users\loser\Desktop\word filter bot\index.js:33:19) {
method: 'post',
path: '/channels/954840804466257921/messages',
code: 50006,
httpStatus: 400,
requestData: {
json: {
content: undefined,
tts: false,
nonce: undefined,
embeds: undefined,
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined
},
files: []
}
}
and here is my code
const Discord = require('discord.js');
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });
const prefix = '-'
client.once('ready', () => {
console.log('woohoo, Im ready to get online and block some words!')
client.user.setActivity('-help', {type: 'LISTENING'})
})
client.on('message', async message => {
if(message.channel.type === 'dm' || message.author.bot) return;
const logChannel = client.channels.cache.find(channel => channel.id === '954845946326450206')
let words = ["banana", "orange"]
let foundInText = false;
for (var i in words) {
if (message.content.toLowerCase().includes(words[i].toLowerCase())) foundInText = true;
}
if (foundInText) {
let logEmbed = new Discord.MessageEmbed()
.setDescription(`<#${message.author.id}> Said a bad word`)
.addField('The Message', message.content)
.setColor('RANDOM')
.setTimestamp()
logChannel.send(logEmbed)
let embed = new Discord.MessageEmbed()
.setDescription(`That word is not allowed here`)
.setColor('RANDOM')
.setTimestamp()
let msg = await message.channel.send(embed);
message.delete()
msg.delete({timeout: '3500'})
}
})
is there anyway you guys can help me out? I would really like to get this up and running.
I assume you're using discord.js v13.
The send method only take one parameter since v13. You can to use send({ embeds: [your, cool, embeds] }); to send embeds or any message that contain not only contents.
Also the Message.prototype.delete() does not take any parameter now. You have to use setTimeout if you want to delete messages after a certain amount of time.

Categories