英文:
why app is not responding with discord.js?
问题
我想编写一个代码,可以发送一个带有所有命令的嵌入式消息,所以我编写了一个可以工作的代码,但在发送嵌入式消息后,它在嵌入式消息上方显示了一个错误:embed。以下是代码:
const { Client, GatewayIntentBits, CommandInteraction, EmbedBuilder } = require('discord.js')
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
// ...
]
});
client.on('ready', async () => {
console.log(`Logged in as ${client.user.tag}!`);
const commands = [
{
name: 'pomoc',
description: 'Wyświetla wszystkie komendy'
}
];
const commandData = commands.map(command => ({
name: command.name,
description: command.description
}));
const commandManager = await client.application?.commands.set(commandData);
console.log(`Registered ${commandManager.size} slash commands`);
});
client.on('interactionCreate', interaction => {
if (!interaction.isCommand()) return;
if (interaction.commandName === 'pomoc') {
const embed = new EmbedBuilder()
.setTitle('some title')
.setDescription('some description')
interaction.channel.send({ embeds: [embed] });
}
});
client.login(process.env.CLIENT_TOKEN);
我尝试了这种方法:
interaction.channel.send({
embeds: [{
title: 'some title',
description: 'some description',
image: { url: 'image url' }
}]
})
英文:
I wanted to write a code that will send an embed with all the commands so I wrote a code that works but after sending the embed it shows an error above the embed: embed. Here's the code:
const { Client, GatewayIntentBits, CommandInteraction, EmbedBuilder } = require('discord.js')
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
// ...
]
});
client.on('ready', async () => {
console.log(`Logged in as ${client.user.tag}!`);
const commands = [
{
name: 'pomoc',
description: 'Wyświetla wszystkie komendy'
}
];
const commandData = commands.map(command => ({
name: command.name,
description: command.description
}));
const commandManager = await client.application?.commands.set(commandData);
console.log(`Registered ${commandManager.size} slash commands`);
});
client.on('interactionCreate', interaction => {
if (!interaction.isCommand()) return;
if (interaction.commandName === 'pomoc') {
const embed = new EmbedBuilder()
.setTitle('some title')
.setDescription('some description')
interaction.channel.send({embeds: })
}
});
client.login(process.env.CLIENT_TOKEN);
I tried this method:
interaction.channel.send({
embeds: [{
title: 'some title',
description: 'some description',
image: {url: 'image url'}
}]
})
答案1
得分: 0
问题在于您在交互渠道中发送消息,而不是回复交互本身。
在调用斜杠命令时,Discord会向您的服务器发送请求并等待响应。这个错误是由于响应超时,因为您的服务器会发出单独的请求,而不是响应初始请求。
而不是使用 interaction.channel.send(details)
,您应该使用 interaction.reply(details)
来回复交互。
英文:
The issue is that you're sending a message in the interaction channel, rather than replying to the interaction itself.
Upon calling a slash command, discord will send a request to your server and await a response. This error is due to the response timing out, as your server makes a separate request rather than responding to the initial request.
Rather than using interaction.channel.send(details)
, you should be using interaction.reply(details)
to respond to the interaction.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论