对不起,我的英语不好,我是法语
我正在尝试为民意测验discord.js机器人创建RichEmbed构造函数。我希望我的代码发送一个RichEmbed,但是当我键入命令时什么也没发生,我只会收到以下错误消息:
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'client' of undefined
这是我的代码:
module.exports.run = async (bot, message, args) => {
function extractAllText(str){
const re = /"(.*?)"/g;
const result = [];
let current;
while (current = re.exec(str)) {
result.push(current.pop());
}
return result.length > 0
? result
: [str];
}
result = extractAllText(message.content)
//Here
const embed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle(result[0])
.setAuthor(message.author)
.setDescription('Sondage')
.setTimestamp()
.setFooter('Vous pouvez voter en cliquant sur les réactions ci-dessous.');
for (let i = 1; i < result.length; i++) {
embed.addField(i, result[i])
}
message.channel.send(embed);
};
我尝试用RichEmbed()替换MessageEmbed(),但又收到另一个错误消息:
UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message
我也尝试使用embed对象,但是我找不到在这种embed中使用for循环的方法。
在文件顶部,我尝试编写:
const Discord = require('discord.js')
const client = new Discord.Client({disableEveryone: true})
但是它仍然不起作用
感谢您阅读本文,祝您有愉快的一天
答案 0 :(得分:0)
尝试添加到模块文件的顶部:
const Discord = require('discord.js')
或者,您可以尝试在app.js/index.js
中进行修改:
commandFile.run(bot, message, args)
与:
commandFile.run(Client, bot, message, args)
编辑:
修改:
let sEmbed = new Discord.MessageEmbed()
使用:
let sEmbed = new Discord.RichEmbed()
答案 1 :(得分:0)
我通过从powershell再次键入yarn add discord.js
(我认为npm应该为npm install discord.js
)将discord.js更新到版本12来解决此问题。