问题描述
嘿,我想在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"
}
});