【发布时间】:2020-10-15 10:45:45
【问题描述】:
我的问题如下:编译时,我收到未定义属性“执行”的错误。我要做的是打开另一个文件夹中的文件并将其停靠在 if 中,我在命令处理文档的指导下,我不知道错误是否在另一个名为“ping”的文件中.js'。我最近才开始,所以我不完全了解它。 主要代码如下:
const Discord = require('discord.js');
const { token, default_prefix } = require('./conf.json');
const client = new Discord.Client();
const fs = require('fs');
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', async message => {
if (!message.content.startsWith(default_prefix) || message.author.bot) return;
const args = message.content.slice(default_prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'ping') {
client.commands.get('ping').execute(message, args);
}
});
client.login(token);
虽然“ping.js”代码是:
const Discord = require('discord.js');
module.exports = {
description: "Get the latency of the bot.",
usage: {},
examples: {},
aliases: [ "pong", "latency", "uptime" ],
permissionRequired: 0,
checkArgs: (args) => !args.length
}
module.exports.run = async function (client, message, args, config, gdb, prefix, permissionLevel, db) {
let botMsg = await message.channel.send("Pinging")
botMsg.edit({
embed: {
name: "ping",
title: "???? Ping",
color: 0x2ed32e,
description: [
"**Server**: `" + (message.createdAt - message.createdAt) + "ms`",
"**API**: `" + Math.round(client.ws.ping) + "ms`",
"**Uptime**: `" + msToTime(client.uptime) + "`"
].join("\n"),
footer: { text: "Requested by " + message.author.tag, icon_url: message.author.displayAvatarURL }
}
})
}
function msToTime(ms) {...
}
它可以工作,但如果我直接将它添加到主代码中,但我不希望这样。如果您有任何想法或知道解决方案,我将不胜感激。
【问题讨论】:
标签: discord.js