javascript - bot.command.has 功能
问题描述
const Discord = require('discord.js');
module.exports.run = async (bot, message, args) => {
let helpArray = message.content.split(' ');
let helpArgs = helpArray.slice(1);
if (helpArgs[0] === 'gaming') {
return message.reply('Gamings');
}
if (!helpArgs[0]) {
const embed = new Discord.MessageEmbed()
.setColor(`#f900ff`)
.setTitle(`**Dragonite Commands:**`)
.addFields(
{
name: '**:police_officer: Moderation:**',
value:
'**`!mute`**, **`!kick`**, **`!ban`**, **`!unban`**, **`!nickname`**, **`!clear`**',
},
{
name: '**:sparkles: Misc:**',
value:
'**`!avatar`**, **`!ping`**, **`!info`**, **`!user`**, **`!server`**, **`!mute`**',
}
)
.setFooter(
'Dragonite | Requested by ' + message.author.tag,
'https://i.imgur.com/3Oxc3I8.png'
);
return message.channel.send(embed);
}
if (helpArgs[0]) {
let command = helpArgs[0];
if (bot.command.has(command)) {
command = bot.commands.get(command);
const embed = new Discord.MessageEmbed()
.setTitle(`Command Help: ${command.config.name}`)
.setColor(`#f900ff`).setDescription(`
**Name: ${command.config.name} || "N/A"
**Description: ${command.config.description} || "N/A"
**Usage: ${command.config.usage} || "N/A"
**Example: ${command.config.example} || "N/A"
`);
} else
return message.channel.send("**This command isn't available :warning:!**.");
}
};
module.exports.help = {
name: 'help',
description: "Check a Dragonite's commands.",
usage: 'user [@user | user ID]',
example: 'user LeRegedit#1281',
};
错误:
(node:43856) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'has' of undefined
请忽略这一点:敏捷的棕色狐狸跳过懒惰的狗,敏捷的棕色狐狸跳过懒惰的狗,敏捷的棕色狐狸跳过懒惰的狗。
解决方案
应该是bot.commands.has(...)
(您缺少“s”)
推荐阅读
- sql - 为什么 SQL Server 将 SS 视为 Umlaut-S (ß)?
- java - NetBeans + Glassfish --> NoSuchMethodError directExecutor()Ljava/util/concurrent/Executor
- spring-boot - Spring Cloud Stream:处理消息需要很长时间时对StreamListener的正确处理
- django - 如何在 django 的一个地方存储多个 python gui 工具?
- android - 在nestedscrollview滚动问题内的片段中的Recyclerview
- linux - 在 shell 中使用 perl -e 命令时引用问题
- python - SQLAlchemy 经典映射器自定义数据类型,来自列的 dict
- android - React Native 分享文章和视频
- javascript - 请求错误:没有为该请求指定连接;使用 express.js 连接到 Sql 服务器时?
- nginx - PHP分页的NGINX重写规则