简体   繁体   English

类型错误:无法读取 null discord.js v13 的属性“setPresence”

[英]TypeError: Cannot read property 'setPresence' of null discord.js v13

I have a little problem.我有一个小问题。 I'm doing the event ready, with an event handler, but I come across this error:我正在使用事件处理程序准备好事件,但我遇到了这个错误:

    client.user.setPresence({
                ^

TypeError: Cannot read property 'setPresence' of null

I don't really know what I'm doing wrong, here is the code:我真的不知道我做错了什么,这是代码:

const mongo = require('../../mongo');
const mongoose = require('mongoose');
const messageCount = require('../../message-counter')
const Discord = require('discord.js')

module.exports = async (Discord, client) => {
    let serverIn = client.guilds.cache.size;
    console.log('[INFO] Doose is online');
    client.user.setPresence({
        status: "dnd",
        activity: {
            name: `${serverIn} servers! | BETA | d.help`,
            type: "WATCHING"
        }
    });

    console.log('[INFO] Connected to MongoDB')

    messageCount(client)
};

MUST READ: Extra Info必读:额外信息

Using discord.js V13使用 discord.js V13

Presence can be set via the options parameter in the Discord.Client(options) constructor like so: Presence 可以通过Discord.Client(options)构造函数中的options参数设置,如下所示:

const client = new Client({
    presence: {
        status: 'online',
        afk: false,
        activities: [{
            name: ...,
            type: ...,
        }],
    },
    intents: [...],
    partials: [...],
});

This should help !!这应该有帮助!!

client.on('ready', () => {

client.user.setActivity(`!help || ${client.guilds.cache.size} Servers `, { type: "LISTENING" })
console.log(`Logged in as ${client.user.tag}`);

})

and for the other , you can use something like this ⬇️对于另一个,你可以使用这样的东西⬇️

client.user.setPresence({
                status: "idle"
            })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 DISCORD.JS V13 TypeError:无法读取未定义的属性“具有” - DISCORD.JS V13 TypeError: Cannot read property 'has' of undefined node.js/discord.js:类型错误:无法读取 null 的属性“setPresence” - node.js/discord.js: TypeError: Cannot read property 'setPresence' of null TypeError:无法在 discord.js v13 中读取未定义的属性(读取“路径”) - TypeError: Cannot read properties of undefined (reading 'path') in discord.js v13 使用 NPM、node.js 和 discord.js,我不断收到 TypeError: Cannot read property 'setPresence' of Z37A6259CC0C1DAE0294 - Using NPM, node.js and discord.js, I keep getting TypeError: Cannot read property 'setPresence' of null discord.js v13 permissions.has() function 不工作(TypeError: Cannot read properties of undefined (reading 'has')) - discord.js v13 permissions.has() function not working (TypeError: Cannot read properties of undefined (reading 'has')) 无法发送空消息 - Discord.JS v13 - Cannot send empty message - Discord.JS v13 无法在 discord.js v13 上发送空消息 - Cannot send an empty message on discord.js v13 Discord.js v13 - 反应 - Discord.js v13 - Reactions Discord JS V13 member.presence.status(无法读取 null 的属性(读取“状态”)) - Discord JS V13 member.presence.status (Cannot read properties of null (reading 'status')) Discord.JS | TypeError:无法读取null的属性“运行” - Discord.JS | TypeError: Cannot read property 'run' of null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM