首页 文章

在javascript中更改discord bot的前缀

提问于
浏览
0

我正在制作机器人,并希望有一个前缀来调用机器人 . 当你没有组时,它可以改变 . 但是如何更改前缀“!”当我使用群组?

我的主要代码

const commando = require('discord.js-commando');
const bot = new commando.Client();
const prefix = ":D";

bot.registry.registerGroup('random', 'Random');
bot.registry.registerCommandsIn(__dirname + "/commands");

bot.login('Botcode'
);

我的组

const commando = require('discord.js-commando');

class DiceRollCommand extends commando.Command {
  constructor(client) {
    super(client, {
      name: 'roll', 
      group: 'random',
      memberName: 'roll',
      description: 'Roll a die'
    });
  }

  async run(message, args){
    var roll = Math.floor(Math.random() * 6) + 1;
    message.reply("You rolled a " + roll);
  }
}

module.exports = DiceRollCommand;

4 回答

  • 0

    您将不得不在node_module目录中编辑'client.js' . \ node_modules \ discord.js,突击队的\ src \ client.js

    这是第28行:

    "if(typeof options.commandPrefix === 'undefined') options.commandPrefix = 'YOUR PREFIX HERE';
    
  • 1
    const commando = require('discord.js-commando');
    const prefix = ":D";
    const bot = new commando.Client({
        commandPrefix: prefix
    });
    
    bot.registry.registerGroup('random', 'Random');
    bot.registry.registerCommandsIn(__dirname + "/commands");
    
    bot.login('Botcode'
    );
    

    希望这有帮助!

  • 0

    你不必使用 const bot = new commando.Client({ commandPrefix: prefix }); 你可以像这样使用一行: bot.commandPrefix = "YOUR PREFIX" 我不是专家所以不要试图证明我的代码有问题!

  • 0

    我知道这有点晚了,但是

    const bot = new commando.Client({
        commandPrefix: ':D'
        });
    

    用那个替换第二和第三行 . 您可以将:D更改为您想要的任何前缀 .

相关问题