我收到此错误 UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'username' of undefined
这是由 client.user.username
引起的在embed
的.setFooter()
.
module.exports = {
name: 'suggest',
aliases: ['sug', 'suggestion'],
description: 'Suggest something for the Bot',
execute(message, client, args) {
const Discord = require('discord.js');
const filter = m => m.author.id === message.author.id;
message.channel.send(`Please provide a suggestion for the Bot or cancel this command with "cancel"!`)
message.channel.awaitMessages(filter, { max: 1, })
.then(async (collected) => {
if (collected.first().content.toLowerCase() === 'cancel') {
message.reply("Your suggestion has been cancelled.")
}
else {
let embed = new Discord.MessageEmbed()
.setFooter(client.user.username, client.user.displayAvatarURL)
.setTimestamp()
.addField(`New Suggestion from:`, `**${message.author.tag}**`)
.addField(`New Suggestion:`, `${collected.first().content}`)
.setColor('0x0099ff');
client.channels.fetch("702825446248808519").send(embed)
message.channel.send(`Your suggestion has been filled to the staff team. Thank you!`)
}
})
},
catch(err) {
console.log(err)
}
};
最佳答案
根据您的评论here
try { command.execute(message, args); } catch (error) { console.error(error); message.reply('There was an error trying to execute that command!'); } });
您没有将 client
传递给 execute()
,您需要这样做。
您还需要在 channels.fetch()
上使用 await
,因为它返回一个 Promise,因此请替换 client.channels.fetch("702825446248808519")。发送(嵌入)
:
const channel = await client.channels.fetch("702825446248808519")
channel.send(embed)
关于javascript - 机器人的用户名未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61467073/