简体   繁体   中英

make specific commands guild discord.js

i wanna make this welcome command work on my specific server,i have 2 server on same bot.if i invite member to server 2 the command will error because i just set id to server 1.how to put the command just work on my server 1?

const rules = '737279140784242708' // rules and info
const leave = '743838756875796502' //leave message
bot.on('guildMemberAdd', (member) => {
    if (member.guild.id = '580588806571294720') {

        const message = `Hello <@${member.id}>, welcome to **${member.guild.name}**!,Jangan lupa check ${member.guild.channels.cache.get(rules)} yaa`

        const channel = member.guild.channels.cache.get(channelId)
        channel.send(message)
    }
})

bot.on('guildMemberRemove', (member) => {
    if (member.guild.id = '580588806571294720') {

        const message = `<@${member.id}>, telah pergi`

        const channel = member.guild.channels.cache.get(leave)
        channel.send(message)
    }
})

Use an if statement to check if the guild that was joined is server 1, and not server 2.

if (member.guild.id === the_id_of_server_1) {
    //Do all the messaging stuff
}

This way, it will only try to do all of those things if the event was called in server 1, and won't throw any errors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM