我正在制作一个机器人,并希望有一个前缀来调用机器人。当你没有组的时候,它就会改变。但是我如何改变前缀"!“当我使用组的时候?
我的主代码
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;发布于 2017-07-04 01:08:16
我知道有点晚了,但是
const bot = new commando.Client({
commandPrefix: ':D'
});用它替换第二行和第三行。您可以将:D更改为所需的任何前缀。
发布于 2018-05-18 07:12:47
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'
);希望这能有所帮助!
发布于 2019-02-24 02:39:16
你不必使用const bot = new commando.Client({ commandPrefix: prefix });,你可以像这样使用一行:bot.commandPrefix = "YOUR PREFIX",我不是专家,所以不要试图用我的代码来证明专业人士是错的!
https://stackoverflow.com/questions/43454680
复制相似问题