[英]RichEmbed discord.js
嘿對不起我的英語不好我是法國人
我正在嘗試為我的 poll discord.js bot 創建 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
我也嘗試使用嵌入對象,但我找不到在那種嵌入中使用 for 循環的方法。
在我的文件的頂部,我試圖寫:
const Discord = require('discord.js')
const client = new Discord.Client({disableEveryone: true})
但它仍然不起作用
感謝您閱讀本文,祝您有美好的一天
嘗試在模塊文件的頂部添加:
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()
我通過從 powershell 再次鍵入yarn add discord.js
更新到版本 12 解決了這個問題(我認為它應該是npm install discord.js
for npm)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.