如何解决Discord.js 别名
我想在我的代码中添加别名,但我不知道如何嵌入它。你有想法吗?
fs.readdir("./commands/",(err,files) => {
if (err) return console.error(err);
files.forEach(file => {
if (!file.endsWith(".js")) return;
let props = require(`./commands/${file}`);
let commandName = file.split(".")[0];
console.log(`Attempting to load command ${commandName}`);
client.commands.set(commandName,props);
});
});
解决方法
您可以将命令文件设置为在其中包含别名,如下所示:
module.exports = {
name: 'command',description: 'description',aliases: ['cmd','another alias'],execute(message,args) {
// ...
}
};
然后,如果您想通过别名查找命令,可以使用:
client.commands.find(cmd => cmd.aliases.includes("an alias"));
您可以在此guide
中找到有关使用别名的更多信息版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。