имя пользователя бота не определено - PullRequest
0 голосов
/ 27 апреля 2020

Я получаю эту ошибку 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)
    }
};

1 Ответ

1 голос
/ 28 апреля 2020

Согласно вашему комментарию здесь

try {command.execute (message, args); } catch (error) {console.error (error); message.reply («Произошла ошибка при попытке выполнить эту команду!»); }});

Вы не передаете client в execute(), вам необходимо это сделать.

Вам также необходимо использовать await для channels.fetch(), так как он возвращает обещание, поэтому замените client.channels.fetch("702825446248808519").send(embed) на:

const channel = await client.channels.fetch("702825446248808519")
channel.send(embed)
...