【问题标题】:Set Activity/Presence Command for Discord.js-Commando为 Discord.js-Commando 设置活动/状态命令
【发布时间】:2020-04-13 21:53:44
【问题描述】:

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

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 命令。)

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

【问题讨论】:

    标签: javascript node.js discord.js


    【解决方案1】:

    尝试改变

    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 是一个用户是否是机器人的布尔值。

    【讨论】:

    • 如果我这样做,我会得到TypeError: this.client.user.setActivity is not a function 另外,我要做的是编写一个命令来将播放行更改为其他内容。
    • 我已经查看了文档,但它只显示了如何直接设置它,而不是通过 args (或者我对此太陌生,无法理解如何将它们放在一起) .
    • 您是否尝试过从 client.bot.setActivity 之前删除 .this?另外,您是否定义了您设置的状态类型(即播放、观看、流式传输)?
    • 我必须添加this. 否则它会吐出ReferenceError: client is not defined 并且设置状态类型也没有效果。 this.client.bot.setActivity(game, { type: 'PLAYING'})
    猜你喜欢
    • 2020-12-31
    • 2019-08-21
    • 2021-08-10
    • 2021-01-13
    • 2021-10-17
    • 2021-01-17
    • 2021-08-03
    • 2018-09-17
    • 2018-10-15
    相关资源
    最近更新 更多