Hey sorry for my bad English I'm French
I am trying to create a RichEmbed constructor for my poll discord.js bot. I expected my code to send a RichEmbed but when I type the command nothing happens, I just get this error message:
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'client' of undefined
Here's my code:
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);
};
I tried to replace MessageEmbed() with RichEmbed(), but I get another error that says:
UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message
I also tried to use an embed object, but I couldn't find a way to use a for loop in that kind of embed.
At the top of my file, I tried to write:
const Discord = require('discord.js')
const client = new Discord.Client({disableEveryone: true})
but it still doesn't work
Thank you for reading this, have a nice day
Try to add on the top of your module file :
const Discord = require('discord.js')
or, you could try to modify this in your app.js/index.js
:
commandFile.run(bot, message, args)
with :
commandFile.run(Client, bot, message, args)
EDIT :
Modify :
let sEmbed = new Discord.MessageEmbed()
With :
let sEmbed = new Discord.RichEmbed()
我通过从 powershell 再次键入yarn add discord.js
更新到版本 12 解决了这个问题(我认为它应该是npm install discord.js
for npm)。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.