在javascript中更改不和谐机器人的前缀
Posted
技术标签:
【中文标题】在javascript中更改不和谐机器人的前缀【英文标题】:Change prefix for discord bot in javascript 【发布时间】:2017-09-13 06:14:36 【问题描述】:我正在制作一个机器人,并希望有一个前缀来调用该机器人。当您没有组时,它可以改变。但是如何更改前缀“!”我什么时候使用群组?
我的主要代码
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;
【问题讨论】:
如果您需要帮助,我们需要代码。编辑您的问题以包含Minimal, Complete, Verifiable Example。 【参考方案1】:我知道有点晚了,但是
const bot = new commando.Client(
commandPrefix: ':D'
);
用那个替换第二行和第三行。 您可以将 :D 更改为您想要的任何前缀。
【讨论】:
【参考方案2】: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'
);
希望这有帮助!
【讨论】:
【参考方案3】:您不必使用const bot = new commando.Client(
commandPrefix: prefix
);
您可以像这样使用一行:bot.commandPrefix = "YOUR PREFIX"
我不是专家,所以不要试图证明我的代码有问题!
【讨论】:
【参考方案4】:您将不得不在 node_module 目录中编辑“client.js”。 \node_modules\discord.js-commando\src\client.js
这是第 28 行:
"if(typeof options.commandPrefix === 'undefined') options.commandPrefix = 'YOUR PREFIX HERE';
【讨论】:
以上是关于在javascript中更改不和谐机器人的前缀的主要内容,如果未能解决你的问题,请参考以下文章