猿问

bot 的用户名未定义

我收到这个错误UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'username' of undefined,这是由client.user.usernamein引起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)

    }

};


白衣非少年
浏览 192回答 1
1回答

喵喔喔

根据您在这里的评论尝试 { command.execute(message, args); } 捕捉(错误){ 控制台.错误(错误);message.reply('尝试执行该命令时出错!'); } });您没有client进入execute(),您需要这样做。您还需要使用awaitonchannels.fetch()因为它返回一个承诺,所以替换client.channels.fetch("702825446248808519").send(embed)为:const channel = await client.channels.fetch("702825446248808519") channel.send(embed)
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答