Discord.js TypeError:无法读取属性';执行';未定义的不一致Bot js

Discord.js TypeError:无法读取属性';执行';未定义的不一致Bot js,discord.js,Discord.js,我的问题如下:编译时,我得到一个错误,即没有定义属性“execute”。我试图做的是打开另一个文件夹中的文件并将其停靠在if中,我是在命令处理文档的指导下,我不知道错误是否在另一个名为“ping.js”的文件中。我最近才开始,所以我不完全理解它。 主要代码如下: const Discord = require('discord.js'); const { token, default_prefix } = require('./conf.json'); const client = new Di

我的问题如下:编译时,我得到一个错误,即没有定义属性“execute”。我试图做的是打开另一个文件夹中的文件并将其停靠在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: "That's because you named it 
run
and not
execute
on this line:

module.exports.run = async function ()

change it to execute and it should work fine, if you wanna keep the keyword
run
, instead of
client.commands.get('ping').execute(message, args)
, use
 client.commands.get('ping').run(message, args)

Also I should mention you have a lot of parameters:

execute function (client, message, args, config, gdb, prefix, permissionLevel, db) {
   //...
}
const Discord=require('Discord.js');
module.exports={
描述:“获取bot的延迟。”,
用法:{},
例如:{},
别名:[“pong”、“延迟”、“正常运行时间”],
所需许可证:0,
checkArgs:(args)=>!args.length
}
module.exports.run=异步函数(客户端、消息、参数、配置、gdb、前缀、权限级别、数据库){
let botMsg=wait message.channel.send(“ping”)
编辑({
嵌入:{
姓名:"平",,

标题:“这是因为您在这一行中命名它为
run
,而不是
execute

module.exports.run=async函数()

如果您想保留关键字
run
,而不是
client.commands.get('ping')。执行(消息,参数)
,使用
client.commands.get('ping')。运行(消息,参数)

我还应该提到,您有很多参数:

任何after args都将是未定义的,因为您只传入消息和args,如下所示:


client.commands.get('ping').execute(message,args)
这是因为您将其命名为
run
,而不是
execute

module.exports.run=async函数()

如果您想保留关键字
run
,而不是
client.commands.get('ping')。执行(消息,参数)
,使用
client.commands.get('ping')。运行(消息,参数)

我还应该提到,您有很多参数:

任何after args都将是未定义的,因为您只传入消息和args,如下所示:


client.commands.get('ping').execute(message,args)
它说
execute是未定义的
,因为您没有在
ping.js
中定义
execute

您可以执行以下任一操作:

  • ping.js
    中更改
    module.exports.run
    module.exports.execute
  • 或者在主文件中,将
    client.commands.get('ping')。执行
    client.commands.get('ping')。运行

原因是调用
命令.execute()时
您试图在命令模块中调用名为“execute”的函数。由于您将其命名为
run
而不是
execute
,因此它会查找错误的函数,但没有找到它。

它说
execute未定义
,因为您没有在
ping.js
中定义
execute

您可以执行以下任一操作:

  • ping.js
    中更改
    module.exports.run
    module.exports.execute
  • 或者在主文件中,将
    client.commands.get('ping')。执行
    client.commands.get('ping')。运行
原因是调用
命令时。execute()
您试图调用命令模块中名为“execute”的函数。由于您将其命名为
run
,而不是
execute
,因此它会查找错误的函数,但没有找到它