簡體   English   中英

(DISCORD.JS) 如何修復我的 discord“cmds”命令?

[英](DISCORD.JS) how do i fix my discord "cmds" command?

我想知道如何修復我的“cmds”命令? 我似乎無法讓它正常工作。 它應該獲取所有命令並向嵌入添加一個包含命令名稱和描述的字段,但顯示此錯誤,文件樹也在這里

module.exports = {
    name:'cmds',
    description:'Literally shows the commands thats it.',
    aliases:'',
    execute(client,msg,args,blacklisted){
        const fs = require('fs')
        const {MessageEmbed} = require("discord.js")
        const embed = new MessageEmbed()
        function getCommand(cmd){
            return client.commands.get(`${cmd}`)
       }
       const commandFiles = fs.readdirSync('.').filter(file => file.endsWith('.js'));
       for (const file of commandFiles){
        const command = require(`./${file}`)
        embed.addField(command.name,```${command.description}```)
        }
        const author = msg.author
        const user = msg.mentions.members.first() || msg.author;
        const useronly = msg.mentions.users.first()
        if (blacklisted.includes(author.id)){
            msg.reply(`You have been blacklisted from using this bot. if you think this is a mistake contact the bot owner.`)
        }else{
        embed.setTitle(`Commands`)
        embed.setColor('RANDOM')
        msg.reply({embeds : [embed] })
        }
    }
}

../archive.js不是./archive.js archive.js 文件不在命令文件夾中,因此您不能使用./archive.js

我通過這樣做自己解決了

 function getCommand(cmd){
        return client.commands.get(`${cmd}`)
   }
   console.log(getCommand('avatar').name)
    const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
    for (const file of commandFiles){
        const command = require(`./${file}`)
        embed.addField(`${command.name}`,`\`\`\ ${command.description} \`\`\ `)
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM