javascript 为什么应用程序没有响应discord.js?

agxfikkp  于 2023-02-28  发布在  Java
关注(0)|答案(1)|浏览(154)

我想写一个代码,将发送一个嵌入与所有的命令,所以我写了一个代码的工作,但在发送嵌入后,它显示了一个错误以上的嵌入: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'}
  }]
})
hc8w905p

hc8w905p1#

问题在于您在交互通道中发送消息,而不是回复交互本身
当调用一个斜杠命令时,discord会向服务器发送一个请求并等待响应。这个错误是由于响应超时,因为服务器发出了一个单独的请求而不是响应初始请求。
您应该使用interaction.reply(details)来响应交互,而不是使用interaction.channel.send(details)

相关问题