为 Discord.js-Commando 设置活动/状态命令



所以我有这个命令来设置机器人的"正在播放"状态:

const commando = require('discord.js-commando');
const { RichEmbed } = require('discord.js');
class sets extends commando.Command {
constructor(client) {
super(client, {
name: 'setgame',
group: 'owner',
memberName: 'setgame',
description: 'Sets the Bots' activity',
examples: ['Playing __on many servers!__'],
args: [
{
key: "game",
prompt: "What do you want to set my game as?",
type: "string"
}
]
});
}
async run(message, { game } ) {
if (message.author.id !== "442918106378010635"){
message.channel.send("That's for TheRSC only!");
}

else {
this.client.bot.setActivity(game)
const embed = new RichEmbed()
.setColor(0x00AE86)
.setDescription("Game set!");
message.channel.send({embed});;
}
}  
}
module.exports = sets;;

我之前遇到过一些错误并设法修复了它们,但这个难倒了我。无论我如何编码,我都会不断得到:TypeError: Cannot read property 'setActivity' of undefined我已经尝试了一些事情,在运行中定义文本,将args.game放入.setActivity((中,它不断吐出该错误。我尝试了拆分 args 方法,但这也不起作用。有什么想法吗?(作为旁注,如果可能的话,我还想将其转换为 .setPresence 命令。

注意:我是编码初学者,所以我可能正在做一些普通编码人员不会做的事情。

尝试更改

client.bot.setActivity(game)

client.user.setActivity(game)

如果您需要更多帮助,或者我的解决方案不起作用,您可以查看 setActivity(( 官方文档提供的此示例。

client.user.setActivity('YouTube', { type: 'WATCHING' })
.then(presence => console.log(`Activity set to ${presence.game ? presence.game.name : 'none'}`))
.catch(console.error);

编辑:我仍然认为它与.bot部分有关,因为.bot文档的唯一参考是用户是否是机器人的布尔值。

最新更新