好的,所以我有一个内置的机器人discord.js-commando
。我一直在对其进行一些调整,主要是尝试添加更多功能,例如按名称记录命令等到通道以及添加 console.error 日志记录。
现在我尝试获取通道日志记录在命令中是可见的,但是机器人不断抛出 TypeError.... 我不知道是什么导致了这个错误,也不知道如何修复它。
有人可以看看我的代码并帮助我找出导致 TypeError 的原因吗?
这是我不断收到的错误:
console.error
2020-09-30T23:08:24.272196+00:00 app[worker.1]: TypeError: this.commands.filterArray is not a function
2020-09-30T23:08:24.272208+00:00 app[worker.1]: at CommandRegistry.findCommands (/app/node_modules/discord.js-commando/src/registry.js:438:41)
2020-09-30T23:08:24.272208+00:00 app[worker.1]: at CommandDispatcher.matchDefault (/app/node_modules/discord.js-commando/src/dispatcher.js:254:34)
2020-09-30T23:08:24.272209+00:00 app[worker.1]: at CommandDispatcher.parseMessage (/app/node_modules/discord.js-commando/src/dispatcher.js:238:21)
2020-09-30T23:08:24.272209+00:00 app[worker.1]: at CommandDispatcher.handleMessage (/app/node_modules/discord.js-commando/src/dispatcher.js:114:18)
2020-09-30T23:08:24.272210+00:00 app[worker.1]: at CommandoClient.<anonymous> (/app/node_modules/discord.js-commando/src/client.js:68:51)
2020-09-30T23:08:24.272210+00:00 app[worker.1]: at CommandoClient.emit (events.js:315:20)
2020-09-30T23:08:24.272211+00:00 app[worker.1]: at MessageCreateAction.handle (/app/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
2020-09-30T23:08:24.272212+00:00 app[worker.1]: at Object.module.exports [as MESSAGE_CREATE] (/app/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
2020-09-30T23:08:24.272213+00:00 app[worker.1]: at WebSocketManager.handlePacket (/app/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
2020-09-30T23:08:24.272213+00:00 app[worker.1]: at WebSocketShard.onPacket (/app/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
这是我的主要机器人文件:
index.js
const { Client } = require('discord.js-commando');
const { RichEmbed } = require('discord.js')
const path = require('path');
const prefix = (process.env.BOT_PREFIX);
const twitch_url = (process.env.TWITCH_URL);
const embed_color = (process.env.EMBED_COLOR);
const embed_img = (process.env.EMBED_IMG);
const embed_url = (process.env.EMBED_URL);
const avatar_url = (process.env.AVATAR_URL);
const thumbnail_url = (process.env.THUMBNAIL_URL);
const welcome_channel = (process.env.WELCOME_CHANNEL_NAME);
const member_role = (process.env._MEMBER_ROLE_NAME);
require('dotenv').config();
const client = new Client({
commandPrefix: prefix
})
client.registry
.registerDefaultTypes()
.registerGroups([
['admin', 'Administration'],
['mod', 'Moderation'],
['fun', 'Fun'],
['misc', 'Miscellanious'],
['util', 'Utility']
])
.registerDefaultGroups()
.registerDefaultCommands()
.registerCommandsIn(path.join(__dirname, 'commands'))
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}(${client.user.id})`)
client.user.setActivity(`${prefix}help`, {
type: "STREAMING",
url: twitch_url
})
});
client.on("guildMemberAdd", (member) => {
console.log(`New User "${member.user.username}" has joined "${member.guild.name}"`);
guildMember.addRole(guildMember.guild.roles.find(role => role.name === member_role));
let channel = member.guild.channels.find(c => c.name === welcome_channel);
const embed = new RichEmbed()
.setAuthor("Yuzuki Yukari", avatar_url)
.setUrl(embed_url)
.setColor(embed_color)
.setImage(embed_img)
.setThumbnail(thumbnail_url)
.setFooter("Yuzuki Yukari", avatar_url)
.addField("Welcome", `${member.user.username} has joined ${member.guild.name}`)
return channel.send(embed).catch(console.error);
});
client.on('guildMemberRemove', (member) => {
let channel = member.guild.channels.find(c => c.name === welcome_channel);
const embed = new RichEmbed()
.setAuthor("Yuzuki Yukari", avatar_url)
.setUrl(embed_url)
.setColor(embed_color)
.setImage(embed_img)
.setThumbnail(thumbnail_url)
.setFooter("Yuzuki Yukari", avatar_url)
.addField("Goodbye", `${member.user.username} has left ${member.guild.name}`)
return channel.send(embed).catch(console.error);
});
client.on('error', console.error)
client.login(process.env.BOT_TOKEN);
这是我的 package.json 文件:
package.json
{
"name": "yuzuki",
"version": "1.0.0",
"description": "A Discord Moderation Bot built using Discord.js commando",
"main": "index.js",
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js"
},
"author": "Nimbi",
"license": "ISC",
"dependencies": {
"discord.js": "^12.0.1",
"discord.js-commando": "^0.10.0",
"path": "^0.12.7",
"snekfetch": "^4.0.4",
"sqlite": "^4.0.14",
"uws": "^100.0.1",
"nodemon": "^1.13.3",
"dotenv": "^8.2.0"
},
"engines": {
"node": "^12.0.0"
}
}
我的依赖项及其版本可以在 my 中看到package.json
,但是我的 node.js 版本是^12.0.0
,我的 discord.js 版本是, 如果有帮助的话,^12.0.1
我的 discord.js-commando 版本是。^0.10.0