javascript 无法读取请求的响应(Discord JS)

u5rb5r59  于 2022-11-20  发布在  Java
关注(0)|答案(1)|浏览(173)

我无法从我的请求中得到响应值。该方法工作正常,但每当我试图将值嵌入时,它都不工作。
代码:

async execute(interaction) {
  const ip = interaction.options.getString('server-ip');
  const port = interaction.options.getString('port');

  util.status(ip, parseInt(port)).then((result) => {
    const embed = new EmbedBuilder()
      .setThumbnail('attachment://favicon.png')
      .setColor('#BFCDEB')
      .setTitle('Mc server status')
      .addFields(
        { name: 'Players Online', value: online },
        { name: 'Max Player Cap', value: result.players.max },
        { name: 'Server Version', value: result.version.name },
        { name: 'MOTD', value: result.motd.clean },
        {
          name: 'Ping (from proxies like bungee/waterfall)',
          value: result.roundTripLatency,
        },
      )
      .setFooter('MC Server Checker');
  });

  interaction.channel.send(embed);
}

我尝试将值作为常量获取,但不起作用

olhwl3o2

olhwl3o21#

如果您这样做,它将正常工作:

async execute(interaction) {

const ip = interaction.options.getString('server-ip');
  const port = interaction.options.getString('port');

  util.status(ip, parseInt(port)).then((result) => {
    const embed = new EmbedBuilder()
      .setThumbnail('attachment://favicon.png')
      .setColor('#BFCDEB')
      .setTitle('Mc server status')
      .addFields(
        { name: 'Players Online', value: online },
        { name: 'Max Player Cap', value: result.players.max },
        { name: 'Server Version', value: result.version.name },
        { name: 'MOTD', value: result.motd.clean },
        {
          name: 'Ping (from proxies like bungee/waterfall)',
          value: result.roundTripLatency,
        },
      )
      .setFooter('MC Server Checker');
      interaction.channel.send(embed);

  });

  
}

我只需要把interaction.channel.send(send)放进.then()承诺里

相关问题