简体   繁体   中英

Cannot get presence informations even thought developer portal switches are enabled discord.js

I have my code here:

// ...
    run: (client,message,args) =>{
        let member = message.member
        console.log(member.presence) // null
        if(!member.presence) return message.say(`${n} - I cannot access **${member.nickname || member.user.tag}**'s presence.`)
        if(!member.presence.activities[0]) return message.reply(`${n} - No activity detected from \`${member.user.tag} !\``)
        message.reply('Informations logged on the console.')
        console.log(member.presence)
    }

I keep having my bot sending this:

未检测到活动

After having checked if other people got the same issue I only saw people who didn't activated the following check boxes:

开关

The thing is I already did and no matter how many times I rerun my bot, member.presence keeps being null and I can't understand why.

Okay so I've been checking around a little more and I found out it's just because I didn't put GUILD_PRESENCES in my intents, silly me. So I just had to change

const client = new Discord.Client({
  intents : [
    "GUILDS",
    "GUILD_MEMBERS",
    "GUILD_MESSAGES"
  ]
})

to

const client = new Discord.Client({
  intents : [
    "GUILDS",
    "GUILD_MEMBERS",
    "GUILD_MESSAGES",
    "GUILD_PRESENCES"
  ]
})

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