【问题标题】:.setColor issue using discord.js.setColor 问题使用 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 这是我现在看到的错误。

标签: javascript discord.js


【解决方案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')
...
...
...
)

【讨论】:

  • 谢谢,我觉得我的整个代码都搞砸了。 :(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-07-01
  • 2020-07-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-07
  • 2020-12-05
相关资源
最近更新 更多