why are aliases not getting executed?(为什么别名没有被执行?)
问题描述
您好,我在 discord.js 中遇到了别名问题,别名不起作用,我不知道为什么?
Hello, I'm having an issue with aliases in discord.js the aliases don't work, I don't know why?
client.on('message', message =>{
// Exit when the message from the bot
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
if (!client.commands.has(commandName)) return;
const command = client.commands.get(commandName) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
try {
command.execute(message, args, commandName, client, Discord);
} catch (error) {
console.error(error);
message.reply('there was an error trying to execute that command!');
}
});
推荐答案
不能使用别名,因为你放了
You can’t use aliases because you put
if(!client.commands.has(commandName)) return;
如果您尝试使用别名或其他任何不在您的 client.commands
键中的东西,这将返回 false.删除此行并改用此行:
This returns false if you try an alias, or anything else that isn’t in your client.commands
keys. Remove this line and use this instead:
const args = message.content.slice(prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
const command = client.commands.get(commandName) || client.commands.find(cmd => cmd.aliases?.includes(commandName));
if(!command) return;
//...
这会查找命令首先,然后如果没有找到命令、名称或别名,则返回
This looks for the command first and then if no command is found, name or alias, it returns
这篇关于为什么别名没有被执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么别名没有被执行?


基础教程推荐
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 直接将值设置为滑块 2022-01-01