Discord.js v12中不会显示Discord自定义状态

问题描述

嘿,我想在Discord.js中创建一个音乐机器人并设置自定义状态,但是它无法正常工作。有人可以帮我吗?

const Discord = require('discord.js');
const client = new Discord.Client();


client.on("ready",() =>{
    console.log(`Ready to play music! Logged in as ${client.user.tag}!`);
    client.user.setPresence({
        status: "online",game: {
            name: "to your Music!,or!help",type: "LISTENING"
        }
    });
 });

client.on('message',message => {
  if (message.content === 'or!ping') {
    message.channel.send(`:ping_pong: The Latency is ${Date.now() - message.createdTimestamp}ms. The API Latency is ${Math.round(client.ws.ping)}ms`);
  }
  el
});

//Token
client.login('TOKEN')

解决方法

如果您正在使用v12(我认为是这样),则在设置状态时需要使用right syntax

在您的示例中,它将是activity而不是game

client.user.setPresence({
    status: "online",activity: {
        name: "to your Music!,or!help",type: "LISTENING"
    }
});

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...