【问题标题】:ReferenceError: Cannot access 'embed' before initialization (hi)ReferenceError:在初始化之前无法访问“嵌入”(嗨)
【发布时间】:2021-08-03 05:45:14
【问题描述】:
module.exports = {
    name: "slowmode",
    description: "Set the slowmode of a channel.",
    execute(message, args, Discord) {
        if(!message.member.hasPermission("ADMINISTRATOR")) {
            return message.reply("You don't have enough perms to use this command!")
        }
    
        let duration = args[0]
        if(isNaN(duration)) return message.reply("Please give the time in seconds.")
        let reason = args.slice(1).join(" ")
        if(!reason) return message.reply("Please specify a reason!")

        const embed = new Discord.MessageEmbed()

            .setTitle("SlowMode!")
            .addFields(
                {name: 'Mod', value: 'message.author.tag'},
                {name: 'Reason', value: 'message.author.tag has set the slowmode to ${duration} because ${reason}'},

                message.channel.sendEmbed(embed)

            )
    }
}

这是我的代码,每当我尝试发送嵌入时,我都会收到错误 ReferenceError: Cannot access 'embed' before initialization.

【问题讨论】:

标签: javascript node.js


【解决方案1】:

该错误表示您在声明之前尝试访问 embed 的值。

问题是您将函数返回值分配给embed,而不是创建实例然后调用函数。

你应该做的是这样的事情:

const embed = new Discord.MessageEmbed();
embed.setTitle("SlowMode!")
    .addFields(
    { name: 'Mod', value: 'message.author.tag' },
    { name: 'Reason', value: 'message.author.tag has set the slowmode to ${duration} because ${reason}'}
);
message.channel.sendEmbed(embed)

【讨论】:

    猜你喜欢
    • 2020-09-17
    • 1970-01-01
    • 2020-12-29
    • 2021-09-10
    • 2020-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多