【发布时间】:2019-05-02 14:52:33
【问题描述】:
我正在制作一个机器人并将其托管在故障上。我希望前缀为“a”,但机器人响应任何单个字母前缀。
{
"prefix": "a",
"devID": "443992049746968586"
}
这是我的 config.json 包含的内容。
//cmd handler
client.commands = new Discord.Collection();
fs.readdir("./commands/", (err, files) => {
if (err) console.log(err);
let jsfile = files.filter(f => f.split(".").pop() === "js")
if(jsfile.length <= 0){
console.log("Couldn't find commands")
return;
}
jsfile.forEach((f, i) =>{
let props = require(`./commands/${f}`);
console.log(`${f} loaded`);
client.commands.set(props.help.name, props);
});
});
client.on("message", msg =>{
let messageArray = msg.content.split(" ");
let cmd = messageArray[0];
let args = messageArray.slice(1);
let commandfile = client.commands.get(cmd.slice(config.prefix.length));
if(commandfile) commandfile.run(client,msg,args);
})
这就是我的 index.js 包含的内容,所有不相关的部分都被删除了。
当我使用我的机器人时会发生什么,我可以去 ping,它会 ping。然后,我可以去 bping,它会 ping,而无需我指定 'b' 是前缀。我该如何应对?
【问题讨论】:
标签: javascript node.js bots discord discord.js