首页 > 解决方案 > 试图做到这一点,所以我的命令只适用于一个公会 Discord.js

问题描述

在 discord.js 中,我试图让我的代码仅在用户位于特定行会时执行,我将如何执行此操作?

module.exports = client => {

const channelId = '798241375572328479' 
const infoId = '<#798241375136776215>'
const serverId = '798241375098896414'
client.on('guildMemberAdd', (member) => {
    console.log(member)

    if (client.guild.id(serverId)) {

        const message = `Welcome to **awbtawtnawtb** ${member.user}!\n Please take some time to read through ${infoId}. \nI have also Direct Messaged you some quick information`

        const welcomeEmbed = new Discord.MessageEmbed()
        .setDescription(message);


        client.channels.cache.get(channelId).send(welcomeEmbed)
        const welcomeDMEmbed = new Discord.MessageEmbed()
            .setColor('#9000D2')
            .setTitle(`Welcome To The awbeyvatw Discord ${member.user.tag}!`)
            .setDescription(`\n\nBy joining this server you are abide by the #info-read rules. Breaking one of these rules will result in punishments accordingly.\nIf you require help create a ticket in #support\nIf you have any further concerns you may DM me @JohnDoe#5032 as a last resort!\n\nI Hope you enjoy your time!\n\n-JohnDoe`)
            .setAuthor(``);
        const welcomedmipEmbed = new Discord.MessageEmbed()
            .setColor('#00F0FF')
            .setTitle(`Server Address: wvawbattbvga`)

    
    } else {
        
    } console.log(`Didn't send message due to not being in the same guild!`)

标签: javascriptdiscord.js

解决方案


您将使用比较运算符。

if (member.guild.id === serverId) {
   // Your code
}


推荐阅读