【问题标题】:SyntaxError: Invalid left-hand side in assignmentSyntaxError:分配中的左侧无效
【发布时间】:2020-09-30 17:10:03
【问题描述】:

当我使用“guildMemberAdd”创建事件时,我会出错:SyntaxError: Invalid left-hand side in assignment。代码:

const Discord = require('discord.js')
const fs = require('fs')

bot.on('GUILD_MEMBER_ADD' = async (bot, message, guild) => {
    let nameserv = guild.name
    let emb = new Discord.MessageEmbed()
        .setTitle('Приветствие.')
        .setDescription(`Добро пожаловать на сервер **${nameserv}**!`)
        .setColor('BLUE')
        .setTimestamp()
        .setFooter('EVENT SYSTEM')
    guild.member.send(emb)
})

【问题讨论】:

    标签: javascript


    【解决方案1】:

    您不应尝试将 "bot.on('GUILD_MEMBER_ADD'" 设置为 async 函数。'GUILD_MEMBER_ADD' 和 async 函数都是 bot.on 函数的参数,应由 a 分隔,而不是 = .

    const Discord = require('discord.js')
    const fs = require('fs')
    
    bot.on('GUILD_MEMBER_ADD', async (bot, message, guild) => {
        let nameserv = guild.name
        let emb = new Discord.MessageEmbed()
            .setTitle('Приветствие.')
            .setDescription(`Добро пожаловать на сервер **${nameserv}**!`)
            .setColor('BLUE')
            .setTimestamp()
            .setFooter('EVENT SYSTEM')
        guild.member.send(emb)
    })
    

    【讨论】:

    • 你是对的。此外,GUILD_MEMBER_ADD 不是 discord.js 的有效事件,它是 guildMemberAdd。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-07
    • 1970-01-01
    • 1970-01-01
    • 2018-10-02
    相关资源
    最近更新 更多