简体   繁体   English

如何更改 Discord.js 机器人的状态?

[英]How to change the status of a Discord.js bot?

I want to change the status of my Discord bot.我想更改我的 Discord 机器人的状态。 I tried the one below, but it didn't work.我尝试了下面的一个,但没有奏效。

const { Client, MessageAttachment } = require('discord.js');

const client = new Client();

client.once('ready', () => {
 console.log('Status:Ready');
 client.user.setPresence({
  game: {
   name: 'to radio',
   type: 'LISTENING',
  },
  status: 'online',
 });
});

you can with this line你可以用这条线

client.user.setActivity('your status', {
 type: 'a type like STREAMING',
 url: 'url of streaming',
});

You can use client.user.setActivity .您可以使用client.user.setActivity The first parameter in this method is what you want the name of your activity to be.此方法中的第一个参数是您希望活动的名称。

In the second parameter, you can specify what activity type you want in your status ( WATCHING , PLAYING , STREAMING , and LISTENING ).在第二个参数中,您可以指定您想要的活动类型WATCHINGPLAYINGSTREAMINGLISTENING )。 For example:例如:

client.on("ready", () => {
  // Playing in my support server
  client.user.setActivity("in my support server", { type: "PLAYING" });

  // Streaming <name of stream>
  client.user.setActivity({ type: "STREAMING", url: "<twich url>" });

  // Watching over xx servers
  client.user.setActivity(`over ${client.guilds.cache.size} servers`, {
    type: "WATCHING",
  });

  // Listening to xxx users
  client.user.setActivity(
    `to ${client.guilds.cache
      .map((guild) => guild.memberCount)
      .reduce((p, c) => p + c)} users`,
    { type: "LISTENING" }
  );
});
´´´
client.once('ready', () => {
    client.user.setActivity('something',{type: 'PLAYING'});
});
´´´

this is probably the easiest way to do it, the types of the presence can be PLAYING, WATCHING and STREAMING, but you can add a url to the last two.这可能是最简单的方法,存在的类型可以是播放、观看和流媒体,但您可以在最后两个中添加一个 url。

client.once('ready', () => {
    client.user.setActivity('something',{type: 'PLAYING'});
});

can be PLAYING STREAMING WATCHING可以播放流媒体观看

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM