【问题标题】:Discord Bot - MessageEmbedDiscord Bot - MessageEmbed
【发布时间】:2021-01-19 00:56:21
【问题描述】:

我对 javascript 非常陌生,而且我不了解很多实际代码。 但是,我有一个查询,如何使“cahbResponses”出现在 MessageEmbed 中? 我从 Discord JS 指南中查看了有关 MessageEmbeds 的文献,但我仍然没有任何线索。

我正在处理的代码是:

client.on('message', function(message) {
 if (message.author.bot) return;
 if (!message.content.startsWith(prefix)) return;
 var args = message.content.substring('!'.length).split(' ');
 switch (args[0].toLowerCase()) {
  case 'cahb':
   var response =
    cahbResponses[Math.floor(Math.random() * cahbResponses.length)];

   message.channel
    .send(response)
    .then()
    .catch(console.error);
   break;
  default:
   break;
 }
});

【问题讨论】:

  • cahbResponses 在哪里定义?代码是否会引发错误?
  • 我在代码中还有const cahbResponses = [,但由于它有数百个响应,我只是将其从我的问题中删除。在那,有没有更好的方法来存储数百个响应?目前,这只是该行代码下方的一长串列表。

标签: javascript node.js discord discord.js


【解决方案1】:

首先,确保您正在导入 Discord

// you probably have this on the beginning of your file
const Discord = require("discord.js");

然后

var response = cahbResponses [Math.floor(Math.random()*cahbResponses .length)];

// Create a MessageEmbed object and set the description
const embed = new Discord.MessageEmbed().setDescription(response);
// Then send the embed
message.channel.send(embed);

在此处阅读其他 MessageEmbed 方法和属性:https://discord.js.org/#/docs/main/stable/class/MessageEmbed

【讨论】:

    猜你喜欢
    • 2021-06-15
    • 2021-07-03
    • 2022-10-21
    • 2021-08-02
    • 2021-01-20
    • 1970-01-01
    • 1970-01-01
    • 2020-07-16
    • 1970-01-01
    相关资源
    最近更新 更多