Getting the following error when executing an xp leaderboard command:
DiscordAPIError[50035]: Invalid Form Body
user_id[NUMBER_TYPE_COERCE]: Value “null” is not snowflake.
at SequentialHandler.runRequest (C:\Users\jacob\OneDrive\Escritorio\Bot\node_modules@discordjs\rest\dist\index.js:933:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.queueRequest (C:\Users\jacob\OneDrive\Escritorio\Bot\node_modules@discordjs\rest\dist\index.js:712:14)
at async REST.request (C:\Users\jacob\OneDrive\Escritorio\Bot\node_modules@discordjs\rest\dist\index.js:1321:22)
at async UserManager.fetch (C:\Users\jacob\OneDrive\Escritorio\Bot\node_modules\discord.js\src\managers\UserManager.js:91:18)
at async Object.execute (C:\Users\jacob\OneDrive\Escritorio\Bot\src\commands\Community\xpleaderboard.js:33:35)
at async Object.execute (C:\Users\jacob\OneDrive\Escritorio\Bot\src\events\interactionCreate.js:15:13) {
rawError: {
code: 50035,
errors: { user_id: [Object] },
message: ‘Invalid Form Body’
},
code: 50035,
status: 400,
method: ‘GET’,
url: ‘https://discord.com/api/v10/users/null’,
requestBody: { files: undefined, json: undefined }
Code:
const { SlashCommandBuilder } = require('@discordjs/builders');
const { EmbedBuilder, DiscordAPIError } = require('discord.js');
const levelSchema = require(`../../Schemas.js/level`)
module.exports = {
data: new SlashCommandBuilder()
.setName('xp-leaderboard')
.setDescription('This gets a servers xp leaderboard'),
async execute(interaction) {
const { guild, client } = interaction;
let text = "";
const embed1 = new EmbedBuilder()
.setColor("Blue")
.setDescription(`<:redcheck:1015276845077364848> No one is on the leaderboard yet...`)
const Data = await levelSchema.find({ Guild: guild.id})
.sort({
XP: -1,
Level: -1
})
.limit(10)
if (!Data) return await interaction.reply({ embeds: [embed1]})
await interaction.deferReply()
for(let counter = 0; counter < Data.length; ++counter) {
let { User, XP, Level } = Data[counter]
const value = await client.users.fetch(User) || "Unknown Member"
const member = value.tag;
text += `${counter + 1}. ${member} | XP: ${XP} | Level: ${Level} \n`
const embed = new EmbedBuilder()
.setColor("Blue")
.setTitle(`${interaction.guild.name}'s XP Leaderboard:`)
.setDescription(`\`\`\`${text}\`\`\``)
.setTimestamp()
.setFooter({ text: `XP Leaderboard` })
interaction.editReply({ embeds: [embed] })
}
}
}