英文:
How can i get my discord.js v14 bot to stop saying "The application did not respond" if the slash command works?
问题
以下是您要翻译的代码部分:
const Discord = require('discord.js');
const { EmbedBuilder, SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
// command name
.setName('totalfrozencheckouts')
// command description
.setDescription('Add up every message in the frozen checkouts channel after a specific message ID')
.addStringOption(option =>
option.setName('messageid')
.setDescription('The message ID')
.setRequired(true)),
async execute(interaction) {
const channel = '<#' + process.env.FROZENCHECKOUTS + '>';
const messageId = interaction.options.getString("messageid");
// 检查通道提及是否有效
if (!channel.startsWith('<#') || !channel.endsWith('>')) {
return interaction.channel.send(`无效的频道提及。请使用以下格式:${this.usage}`);
}
// 从频道提及中提取频道ID
const channelId = channel.slice(2, -1);
// 尝试从请求的通道和消息ID获取消息
interaction.guild.channels.cache.get(channelId).messages.fetch({ after: messageId })
.then(messages => {
// 创建一个包含数字的消息内容数组
const numbers = messages.map(message => message.content).filter(content => !isNaN(content));
// 检查是否有消息
if (numbers.length === 0) {
return interaction.channel.send(`在 ${channel} 中找不到消息ID后的消息:https://discord.com/channels/1059607354678726666/1060019655663689770/${messageId}`);
}
// 累加消息
const sum = numbers.reduce((accumulator, currentValue) => accumulator + parseInt(currentValue), 0);
// 创建一个嵌入对象
const embed = new EmbedBuilder()
.setColor(0x4bd8c1)
.setTitle('今天 #frozen-checkouts 的总结是:')
.addFields(
{name: '总结', value: sum.toString() , inline: true},
)
.setThumbnail('https://i.imgur.com/7cmn8uY.png')
.setTimestamp()
.setFooter({ text: 'Frozen ACO', iconURL: 'https://i.imgur.com/7cmn8uY.png' });
// 发送嵌入对象
interaction.channel.send({embeds: [embed]});
})
.catch(error => {
console.error(error);
interaction.channel.send('尝试获取消息时发生错误。请稍后再试。');
});
}
}
希望这能帮助您理解代码并解决问题。
英文:
i have multiple commands that work perfectly fine but i always get this message in return.
here is the code for that command. it works perfectly fine i guess it just doesn't respond to the interaction even though i feel like it should be?
how can i get it to ignore this message or reply properly?
const Discord = require('discord.js');
const { EmbedBuilder, SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
// command name
.setName('totalfrozencheckouts')
// command description
.setDescription('Add up every message in the frozen checkouts channel after a specific message ID')
.addStringOption(option =>
option.setName('messageid')
.setDescription('The message ID')
.setRequired(true)),
async execute(interaction) {
const channel = '<#' + process.env.FROZENCHECKOUTS + '>';
const messageId = interaction.options.getString("messageid");
// Check if the channel mention is valid
if (!channel.startsWith('<#') || !channel.endsWith('>')) {
return interaction.channel.send(`Invalid channel mention. Please use the format: ${this.usage}`);
}
// Extract the channel ID from the channel mention
const channelId = channel.slice(2, -1);
// Try to fetch the messages from the requested channel and message ID
interaction.guild.channels.cache.get(channelId).messages.fetch({ after: messageId })
.then(messages => {
// Create an array of the message contents that are numbers
const numbers = messages.map(message => message.content).filter(content => !isNaN(content));
// Check if there are any messages
if (numbers.length === 0) {
return interaction.channel.send(`No messages were found in ${channel} after message ID https://discord.com/channels/1059607354678726666/1060019655663689770/${messageId}`);
}
// Adds up the messages
const sum = numbers.reduce((accumulator) => accumulator + 1, 1);
// Create an embed object
const embed = new EmbedBuilder()
.setColor(0x4bd8c1)
.setTitle(`Total Checkouts in #frozen-checkouts for today is:`)
.addFields(
{name: 'Total Checkouts', value: sum.toString() , inline: true},
)
.setThumbnail('https://i.imgur.com/7cmn8uY.png')
.setTimestamp()
.setFooter({ text: 'Frozen ACO', iconURL: 'https://i.imgur.com/7cmn8uY.png' });
// Send the embed object
interaction.channel.send({embeds: });
})
.catch(error => {
console.error(error);
interaction.channel.send('An error occurred while trying to fetch the messages. Please try again later.');
});
}
}
I don't really know what to try because it literally works I just don't know how to get it to either ignore that message or respond with nothing. It doesn't break the bot its just annoying to look at.
答案1
得分: 1
使用interaction.reply
而不是interaction.channel.send
来回复。
英文:
Use interaction.reply
instead of interaction.channel.send
to reply.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论