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);
}
}
}
Related
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);
I've tried getting this to work for a few days and cannot find anything to work, the discord bot keeps crashing instead of returning.
The current permission check I'm using along with the mess of code i shouldn't need.
if (message.guild.members.me.permissions.has(PermissionsBitField.Flags.SendMessages)) {
try {
if (message.content.toLowerCase().startsWith(prefix) && !Icommand){
message.channel.send(`Use b.help in the commands channel.`);
}
if (!Icommand) return;
try {
Icommand.execute(message, args, mention, client, PermissionsBitField);
}
catch (error) {
console.error(error);
message.reply('This command could not be run! The Dev has been notified.');
}
}
catch (error) {
console.log(error);
return
}
} else return
Error as below
/home/pi/british-bot/node_modules/discord.js/src/rest/RequestHandler.js:350
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Missing Permissions
at RequestHandler.execute (/home/pi/british-bot/node_modules/discord.js/src/rest/RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (/home/pi/british-bot/node_modules/discord.js/src/rest/RequestHandler.js:51:14)
at async TextChannel.send (/home/pi/british-bot/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:175:15) {
method: 'post',
path: '/channels/1001430667416064050/messages',
code: 50013,
httpStatus: 403,
requestData: {
json: {
content: 'Pong.',
tts: false,
nonce: undefined,
embeds: undefined,
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: 0,
message_reference: { message_id: '1017162983622848512', fail_if_not_exists: true },
attachments: undefined,
sticker_ids: undefined
},
files: []
}
}
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})
I wanted to make a command for my bot that returns the user avatar, but I am getting an error:
DiscordAPIError: Cannot send an empty message
at RequestHandler.execute (C:\Users\Pooyan\Desktop\PDM Bot Main\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\Pooyan\Desktop\PDM Bot Main\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
at async TextChannel.send (C:\Users\Pooyan\Desktop\PDM Bot Main\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:175:15) {
method: 'post',
path: '/channels/885608990418010202/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: []
}
}
My code:
module.exports = {
name: 'avatar',
aliases: ['icon', 'pfp', 'profilepic'],
permissions: [],
cooldown: 5,
description: '!',
execute(message, args, client, Discord) {
if (!message.mentions.users.size) {
return message.channel.send(`**آواتار شما:** ${message.author.displayAvatarURL({ dynamic: true })}`);
}
const avatar_list = message.mentions.users.map(user => {
return ` آواتار**<#${user.id}>** ${user.displayAvatarURL({ dynamic: true })}`;
});
message.channel.send(avatar_list);
}
}
I am using Discord.js v13, node 16
Collection#map returns an array and you try to send that. As you can only send a string, you can join the returned array using the Array#join method:
const avatar_list = message.mentions.users.map((user) => {
return ` آواتار**<#${user.id}>** ${user.displayAvatarURL({ dynamic: true })}`;
});
message.channel.send(avatar_list.join('\n'));
This question already has an answer here:
Discord.js v12 code breaks when upgrading to v13
(1 answer)
Closed 1 year ago.
I am having issues with sending discord embeds. This is my code:
module.exports = {
name: 'tiktok',
description: "sends tiktok link",
execute(message, args, Discord) {
const newEmbed = new Discord.MessageEmbed()
.setColor('#228B22')
.setTitle('Tiktok')
.setURL('https://www.tiktok.com/#elcattuccino?lang=en')
.setDescription('tiktok link for the discord server')
.addFields(
{name: 'Tiktok', value:'heres the tiktok link'},
)
.setImage('https://cdn.discordapp.com/avatars/752212130870329384/6a16609eafc28f95ad8f64e80ffcc24e.png?size=80')
.setFooter('check out the tiktok');
message.channel.send(newEmbed);
}
}
But I get this error:
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Cannot send an empty message
at RequestHandler.execute (C:\Users\willm\OneDrive\Desktop\Discord Bot\node_modules\discord.js\src\rest\RequestHandler.js:349:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (C:\Users\willm\OneDrive\Desktop\Discord
Bot\node_modules\discord.js\src\rest\RequestHandler.js:50:14)
at async TextChannel.send (C:\Users\willm\OneDrive\Desktop\Discord Bot\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:172:15)
{ method: 'post', path: '/channels/910099863180550144/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 you're using discord.js v13, you should send an embed like this as you can send up to 10 embeds now:
message.channel.send({ embeds: [newEmbed] });
The embed option was removed and replaced with an embeds array, which must be in the options object. More info
Use message.channel.send({ embeds: [newEmbed] });
Also field has changed
.addField('LINK', '[LINK](TIKTOK LINK)', true)
like this