Reputation: 188
I am getting this error UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'username' of undefined
which is caused by client.user.username
in embed
's .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)
}
};
Upvotes: 0
Views: 133
Reputation: 5174
According to your comment here
try { command.execute(message, args); } catch (error) { console.error(error); message.reply('There was an error trying to execute that command!'); } });
You are not passing client
into execute()
, you need to do that.
You also need to use await
on channels.fetch()
since it returns a promise so replace client.channels.fetch("702825446248808519").send(embed)
with:
const channel = await client.channels.fetch("702825446248808519")
channel.send(embed)
Upvotes: 1