如何编写自定义丰富存在的代码我尝试这样做但给出了错误
how to code a custom rich presence i tried doing one but gives error
const client = require("../index");
client.on("ready", () =>
console.log(`${client.user.tag} is up and ready to go!`)
);
client.user.setPresence({
status: "online", // You can show online, idle... Do not disturb is dnd
game: {
name: "p!help • poketwo.net", // The message shown
type: "PLAYING" // PLAYING, WATCHING, LISTENING, STREAMING,
}
});
这是我丰富存在的代码,但我收到如下错误
F:\akash\code\p22222\events\ready.js:6
client.user.setPresence({
^
TypeError: Cannot read properties of null (reading 'setPresence')
at Object.<anonymous> (F:\akash\code\p22222\events\ready.js:6:13)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at F:\akash\code\p22222\handler\index.js:27:31
at Array.map (<anonymous>)
at module.exports (F:\akash\code\p22222\handler\index.js:27:16)
我不知道如何解决请让我知道该怎么做
由于我不知道客户端是从哪里来的,所以无法给你一个合适的解决方案。不过,我会告诉你我是如何工作的。
客户代码:
const client = new Discord.Client({
intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_WEBHOOKS", "DIRECT_MESSAGES", "GUILD_BANS", "GUILD_MEMBERS", "GUILD_VOICE_STATES"], //must use intents
allowedMentions: ["users"] //stops people from using +say @everyone
});
关于代码:
//state: on
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`);
console.log("Connected to server(s):");
client.guilds.cache.forEach((guild) => {
console.log(" - " + guild.name + "\n ID: " + guild.id +"\n");
guild_number += 1;
});
console.log(`The number of guilds connected: ${guild_number}`);
client.user.setActivity('World of Tanks', {type: "PLAYING"});
client.user.setStatus('dnd');
});
您应该将所有客户端初始化器(定义、打开等)放入您的 index.js
。
const client = require("../index");
client.on("ready", () =>
console.log(`${client.user.tag} is up and ready to go!`)
);
client.user.setPresence({
status: "online", // You can show online, idle... Do not disturb is dnd
game: {
name: "p!help • poketwo.net", // The message shown
type: "PLAYING" // PLAYING, WATCHING, LISTENING, STREAMING,
}
});
这是我丰富存在的代码,但我收到如下错误
F:\akash\code\p22222\events\ready.js:6
client.user.setPresence({
^
TypeError: Cannot read properties of null (reading 'setPresence')
at Object.<anonymous> (F:\akash\code\p22222\events\ready.js:6:13)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at F:\akash\code\p22222\handler\index.js:27:31
at Array.map (<anonymous>)
at module.exports (F:\akash\code\p22222\handler\index.js:27:16)
我不知道如何解决请让我知道该怎么做
由于我不知道客户端是从哪里来的,所以无法给你一个合适的解决方案。不过,我会告诉你我是如何工作的。
客户代码:
const client = new Discord.Client({
intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_WEBHOOKS", "DIRECT_MESSAGES", "GUILD_BANS", "GUILD_MEMBERS", "GUILD_VOICE_STATES"], //must use intents
allowedMentions: ["users"] //stops people from using +say @everyone
});
关于代码:
//state: on
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`);
console.log("Connected to server(s):");
client.guilds.cache.forEach((guild) => {
console.log(" - " + guild.name + "\n ID: " + guild.id +"\n");
guild_number += 1;
});
console.log(`The number of guilds connected: ${guild_number}`);
client.user.setActivity('World of Tanks', {type: "PLAYING"});
client.user.setStatus('dnd');
});
您应该将所有客户端初始化器(定义、打开等)放入您的 index.js
。