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

时间:2019-12-22 02:32:43

标签: javascript node.js discord.js

所以我有此命令来设置机器人的“正在播放”状态:

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 我尝试了一些事情,在运行中定义了 text ,将args.game放到.setActivity()中,它不断吐出该错误。我尝试了分割args方法,但是那也不起作用。有任何想法吗? (作为补充,如果可能的话,我也想将其转换为.setPresence命令。)

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

1 个答案:

答案 0 :(得分:0)

尝试更改

client.bot.setActivity(game)

client.user.setActivity(game)

如果需要更多帮助,或者我的解决方案不起作用,可以看一下the official documentation on setActivity()提供的示例。

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

编辑:我仍然认为它与.bot部分有关,因为唯一的reference on the documentation of .bot是用户是否为机器人的布尔值。