如何设置机器人自定义状态?

How to set bot custom status?

我需要设置机器人自定义状态。我试过这段代码:

client.on("ready", () =>{
    console.log(`Logged in as ${client.user.tag}!`);
    client.user.setPresence({
        status: "online",  //You can show online, idle....
        game: {
            name: "Using !help",  //The message shown
            type: "STREAMING" //PLAYING: WATCHING: LISTENING: STREAMING:
        }
    });
 });

还有这个:

client.user.setActivity('discord.js', { type: 'WATCHING' });

还有这个:

client.user.setStatus('available');
    client.user.setActivity(`Using !help`, { //msg shown
    type: "STREAMING",
    url: "" //optional

    });

此错误显示在控制台中:

error

现在我使用了这个代码:

client.on("ready", () => {
client.user.setPresence({ activity: { name: "Using .help" }, status: "idle" })})

但这只是闲置。我需要看文字

但没有任何效果。有人可以帮助我吗?

尝试使用 .setActivity 而不是 .setPresence,并使用此格式:

client.once('ready', () => {
client.user.setStatus('available');
    client.user.setActivity(`Using !help`, { //msg shown
    type: "STREAMING",
    url: "" //optional

    });
});
client.on('ready', (client) => {
   client.user.setPresence({
       status: "streaming"
   });
});

.setPresence 设置你小小的存在,例如 dndidleonlineoffline

client.user.setActivity({
   type: "STREAMING",
   name: `over ${client.guilds.cache.size} servers.`,
   url: "https://www.twitch.tv/your_twitch_streaming" //optional
});

.setActivity 设置你的 activity 例如 playing, watching, etc

我认为因为它不适用于您的代码文件,所以您没有在 ready

之后添加 client

您可以将它们同时放入您的 ready event

client.on('ready', (client) => {
   client.user.setPresence({
       status: "streaming"
   });

client.user.setActivity({
       type: "STREAMING",
       name: `over ${client.guilds.cache.size} servers.`,
       url: "https://www.twitch.tv/your_twitch_streaming" //optional
    });
});

这是我的状态码(discord.js 的 v13.6):

client.user.setActivity('+help', {type: "PLAYING"});

client.on代码如下:

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