Change prefix for discord bot in javascript - Stack Overflow

admin2025-04-18  0

I'm making a bot and want to have a prefix to call the bot. It works to change when you don't have groups. But how do I change the prefix "!" when I use groups?

My main code

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

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

bot.login('Botcode'
);

My group

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

class DiceRollCommand extends mando.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;

I'm making a bot and want to have a prefix to call the bot. It works to change when you don't have groups. But how do I change the prefix "!" when I use groups?

My main code

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

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

bot.login('Botcode'
);

My group

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

class DiceRollCommand extends mando.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;
Share Improve this question edited Apr 17, 2017 at 16:14 user67318 asked Apr 17, 2017 at 15:43 user67318user67318 111 gold badge1 silver badge2 bronze badges 1
  • If you want help, we'll need code. Edit your question to include a Minimal, Complete, Verifiable Example. – Tyler Roper Commented Apr 17, 2017 at 15:45
Add a ment  | 

4 Answers 4

Reset to default 1

I know it's a bit late, but

    const bot = new mando.Client({
    mandPrefix: ':D'
    });

replace line two and three with that. You can change the :D to any prefix you want.

const mando = require('discord.js-mando');
const prefix = ":D";
const bot = new mando.Client({
    mandPrefix: prefix
});

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

bot.login('Botcode'
);

Hope this helped!

You don't have to use the const bot = new mando.Client({ mandPrefix: prefix }); You can use a single line like this: bot.mandPrefix = "YOUR PREFIX" I am not an expert so dont try and prove pros wrong with my code!

You're going to have to edit 'client.js' in your node_module directory. \node_modules\discord.js-mando\src\client.js

This is on line 28:

"if(typeof options.mandPrefix === 'undefined') options.mandPrefix = 'YOUR PREFIX HERE';
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744970575a277461.html

最新回复(0)