【问题标题】:Trying to make it so my command only works in one guild Discord.js试图做到这一点,所以我的命令只适用于一个公会 Discord.js
【发布时间】:2021-05-17 20:13:24
【问题描述】:

在 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!`)

【问题讨论】:

标签: javascript discord.js


【解决方案1】:

您将使用比较运算符。

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

【讨论】:

  • Cannot read property 'id' of undefined 是这样做时出现的问题
  • 对不起。应该是member.guild。我已经编辑了我的答案
猜你喜欢
  • 1970-01-01
  • 2011-01-30
  • 1970-01-01
  • 2020-07-05
  • 2021-07-23
  • 1970-01-01
  • 2015-04-11
  • 1970-01-01
  • 2020-09-14
相关资源
最近更新 更多