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

huangapple go评论99阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年2月26日 20:49:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/75572081.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定