英文:
Creating Pokemon box-like command in Discord.js using MongoDB - how to resolve 'Cannot send an empty message' error
问题
I'm trying to create a Pokemon-type command where you catch friends on Discord. I was able to get it to create the information for catching different users to Mongo DB, but it creates separate queries for each new user caught. I'm having issues creating an embed that shows a box for the user that shows each of the users caught and how many times they have.
I've tried a few different ways using collections and other methods, but nothing has worked.
Catch command (not the full command since it's over 1000 lines of code):
// Check if the Forgemon exists in the database.
let nameBox = await fmBoxSchema.findOne({
User: user,
Username: user.username,
Guild: interaction.guild.id,
name: fmTarget.forgemon,
});
If more code is needed I can always paste the whole thing in a paste bin and share it, but this is what I use and have that works with adding the information to Mongo DB.
Below is what I currently have for trying to show the user who all they've caught and how many times, but keep getting an error saying "Cannot send an empty message". Full error at bottom.
// Get the user's Pokémon from the database.
const userForgemon = await fmBoxSchema.findOne({ User });
// Create a message that lists the user's Pokémon.
let message = "```";
if (userForgemon) {
for (const [name, caught] of Object.entries(userForgemon)) {
message += `${name} - Caught ${caught} times\n`;
}
} else {
message = "You have not caught any Pokémon yet.";
}
message += "```";
// Send the message to the user.
let userPFP = user.displayAvatarURL();
boxEmbed = new EmbedBuilder()
.setTitle(`${user.username}'s Box.`)
.setThumbnail(userPFP)
.setDescription(message);
interaction.reply({ embed: boxEmbed });
Error:
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^
DiscordAPIError[50006]: Cannot send an empty message
at handleErrors (D:\Bots\TestBot - V14\node_modules\@discordjs\rest\dist\index.js:640:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async BurstHandler.runRequest (D:\Bots\TestBot - V14\node_modules\@discordjs\rest\dist\index.js:736:23)
at async REST.request (D:\Bots\TestBot - V14\node_modules\@discordjs\rest\dist\index.js:1387:22)
at async ChatInputCommandInteraction.reply (D:\Bots\TestBot - V14\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:111:5) {
requestBody: {
files: [],
json: {
type: 4,
data: {
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,
thread_name: undefined
}
}
},
rawError: { message: 'Cannot send an empty message', code: 50006 },
code: 50006,
status: 400,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1115070713695567924/aW50ZXJhY3Rpb246MTExNTA3MDcxMzY5NTU2NzkyNDpjbHN0d2ZzTGcxRXJUMUdKMEE0WWdZRDdtR3NJTnhWN1hMSnBqblpkV3Y0bFplWUZibnBoOXhPdlVkU2ZqNVY4VGpRb0lCaUJscVVhWnZ3NmdhSHdvZlhVOWx5S2ZlN2tqa0UzNkYyUlZkTVdVYkk1c2VSS3E4MmJUVDZDVXhYNw/callback'
}
英文:
I'm trying to create a Pokemon-type command where you catch friends on Discord. I was able to get it to create the information for catching different users to Mongo DB, but it creates separate queries for each new user caught. I'm having issues creating an embed that shows a box for the user that shows each of the users caught and how many times they have.
I've tried a few different ways using collections and other methods, but nothing has worked.
Catch command(not the full command since it's over 1000 lines of code):
// Check if the Forgemon exists in the database.
let nameBox = await fmBoxSchema.findOne({
User: user,
Username: user.username,
Guild: interaction.guild.id,
name: fmTarget.forgemon,
});
// Forgemon is not caught yet, add it to the data
if (!nameBox) {
nameBox = new fmBoxSchema({
User: user,
Username: user.username,
Guild: interaction.guild.id,
name: fmTarget.forgemon,
caught: 0,
});
await nameBox.save();
// Set the Forgemon's "caught" count.
nameBox.caught = 1;
await nameBox.save();
If more code is needed I can always paste the whole thing in a paste bin and share it, but this is what I use and have that works with adding the information to Mongo DB.
Below is what I currently have for trying to show the user who all they've caught and how many times, but keep getting and error saying "Cannot send an empty message". Full error at bottom.
// Get the user's Pokémon from the database.
const userForgemon = await fmBoxSchema.findOne({ User });
// Create a message that lists the user's Pokémon.
let message = "```";
if (userForgemon) {
for (const [name, caught] of Object.entries(
userForgemon
)) {
message += `${name} - Caught ${caught} times\n`;
}
} else {
message = "You have not caught any Pokémon yet.";
}
message += "```";
// Send the message to the user.
let userPFP = user.displayAvatarURL();
boxEmbed = new EmbedBuilder()
.setTitle(`${user.username}'s Box.`)
.setThumbnail(userPFP)
.setDescription(message)
interaction.reply({ embed: boxEmbed })
Error:
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^
DiscordAPIError[50006]: Cannot send an empty message
at handleErrors (D:\Bots\TestBot - V14\node_modules\@discordjs\rest\dist\index.js:640:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async BurstHandler.runRequest (D:\Bots\TestBot - V14\node_modules\@discordjs\rest\dist\index.js:736:23)
at async REST.request (D:\Bots\TestBot - V14\node_modules\@discordjs\rest\dist\index.js:1387:22)
at async ChatInputCommandInteraction.reply (D:\Bots\TestBot - V14\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:111:5) {
requestBody: {
files: [],
json: {
type: 4,
data: {
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,
thread_name: undefined
}
}
},
rawError: { message: 'Cannot send an empty message', code: 50006 },
code: 50006,
status: 400,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1115070713695567924/aW50ZXJhY3Rpb246MTExNTA3MDcxMzY5NTU2NzkyNDpjbHN0d2ZzTGcxRXJUMUdKMEE0WWdZRDdtR3NJTnhWN1hMSnBxblpkV3Y0bFplWUZibnBoOXhPdlVkU2ZqNVY4VGpRb0lCaUJscVVhWnZ3TmhuSHdvZlhVOWx5S2ZlN2tqa0UzNkYyUlZkTVdVYkk1c2VSS3E4MmJUVDZDVXhYNw/callback'
}
答案1
得分: 0
将interaction.reply({ embed: boxEmbed })
中的部分替换为embeds: [boxEmbed]
。
英文:
In line with interaction.reply({ embed: boxEmbed })
Replace
embed: boxEmbed
With
embeds: [boxEmbed]
答案2
得分: 0
答案是我的嵌入类型,然后在那之后的错误需要我将boxEmbed
更改为[boxEmbed]
以适应数组。
英文:
The answer to the main questions was my type of embeds and then the error after that needed me to change boxEmbed to [boxEmbed] for the array.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论