.setColor 问题使用 discord.js

Posted

技术标签:

【中文标题】.setColor 问题使用 discord.js【英文标题】:.setColor issue using discord.js 【发布时间】:2021-03-10 14:24:08 【问题描述】:

正如您从下面的代码中看到的那样,我遇到了 .setColor 的问题,所以您知道我确实添加了 Discord.js 作为要求,但我仍然收到错误。我非常如果有一些简单的东西,那就太好了:D。

const  Client, MessageEmbed  = require('discord.js');

const Discord = new Discord.Client();

const token = require("./token");

const prefix = '!';

const exampleEmbed = new Discord.MessageEmbed()

Client.once('ready', () => 
  console.log('International 1657 is online!');
);

Client.on('message', message => 
  var prefix = '!'
  var msg = message.content;

  if (msg === prefix + 'Aethelflaed') 
    message.channel.send( // inside a command, event listener, etc.
    new MessageEmbed()
    .setColor('#0099ff')
    .setTitle('Legendary Commander')
    .setURL('https://discord.js.org/')
    .setAuthor('Aethelflaed', './img/LegendaryCommander/Aethelflaed.png', '#')
    .setDescription('She is one of the most powerful commanders in the game thanks to her skills and absolute strength of rarity.')
    .setThumbnail('./img/LegendaryCommander/Aethelflaed.png')
    .addFields(
          name: 'Skills', value: 'Arrow of Iron - Thunderous Force - Synergy - Fortress of Mercia - Warrior Queen Expertise' ,
          name: '\u200B', value: '\u200B' ,
          name: './img/Leadership.png', value: 'Leadership |', inline: true ,
          name: './img/Peace.png', value: 'Peacekeeping |', inline: true ,
       )
       .addField('./img/Support.png', 'Support', true)
       .setImage('./img/LegendaryCommander/Aethelflaed.png')
       .setTimestamp()
       .setFooter('Britain', './img/LegendaryCommander/Aethelflaed.png'));

       channel.send(exampleEmbed);
      );

Client.on('message', message => 
  if (!message.content.startsWith(prefix) || message.author.bot) return;
  const args = message.content.slice(prefix.length).split(/ +/);
  const command = args.shift().toLowerCase();

  if (command === 'ping') 
    message.reply('pong!');
   else if (command === 'kingdom') 
    message.reply('We are in Kingdom 1657 and Our alliance is 57kl');
   else if (command === 'power') 
    message.reply();
  )

Client.login(token);

【问题讨论】:

const Discord = new Discord.Client(); ^ ReferenceError: Cannot access 'Discord' before initialization 这是我现在看到的错误。 【参考方案1】:

您的message.channel.send() 方法中似乎缺少new MessageEmbed()

const  Client, MessageEmbed  = require('discord.js');

message.channel.send( // inside a command, event listener, etc.
  new MessageEmbed()
    .setColor('#0099ff')
    .setTitle('Legendary Commander')
...
...
...
)

【讨论】:

谢谢,我觉得我的整个代码都搞砸了。 :(

以上是关于.setColor 问题使用 discord.js的主要内容,如果未能解决你的问题,请参考以下文章

使嵌入在一段时间内改变颜色 discord.js

如何在 discord.js 上提及

如何定义嵌入?

循环显示帮助命令

我将如何使用两个不同版本的 discord.js | Discord.js 机器人

使用 Discord 按钮的建议命令 Discord.JS