亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

TypeError:無法讀取未定義的 Discord,js 的屬性“執行”

TypeError:無法讀取未定義的 Discord,js 的屬性“執行”

MMTTMM 2023-04-14 16:32:03
我有問題,我的代碼正在顯示類型錯誤:無法讀取暫停命令未定義的屬性“執行”。所有其他命令都工作正常。讀取文件。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.on('message', msg => {    if (!msg.content.startsWith(prefix) || msg.author.bot) {        return;    }    const args = msg.content.slice(prefix.length).trim().split(/ +/);    const command = args.shift().toLowerCase();    if (command === 'ping') {        client.commands.get('ping').execute(msg, args);    } else if (command === 'userinfo') {        client.commands.get('userinfo').execute(msg, args);    } else if (command === 'delete') {        const amount = parseInt(args[0]) + 1;        if (isNaN(amount)) {            return msg.reply('Enter a valid number.');        } else if (amount <= 1 || amount > 100) {            return msg.reply('Enter a number between 1 and 99.');        } else {            msg.channel.bulkDelete(amount, true).catch(err => {                console.error(err);                msg.channel.send('There was an error trying to delete messages');            });            msg.channel.send(`Deleted ${args} messages.`);        }    } else if (command === 'p' || command === 'play') {        client.commands.get('play').execute(msg, args);    } else if (command === 'pause') {        client.commands.get('pause').execute(msg);    }});如果我復制代碼并粘貼相同的代碼,Client.on它可以正常工作,但在使用 with 時顯示錯誤module.exports。有什么辦法可以解決這個問題嗎?
查看完整描述

3 回答

?
吃雞游戲

TA貢獻1829條經驗 獲得超7個贊

查看您的 pause.js 導出 -execute不是對象的屬性。嘗試這個:


module.exports = {

    title: 'pause',

    description: "Pause the current song.",

    execute: function (message) {

       const queue = message.client.queue.get(message.guild.id);

       if(!queue) return message.reply("There is nothing playing").catch(console.error);

       if(queue.playing){

           queue.playing = false;

           queue.connection.dispatcher.pause(true);

           return queue.textChannel.send(`? Paused.`).catch(console.error);

       }

    }

};

創建一個名為的屬性execute并將其值分配給您擁有的功能。


查看完整回答
反對 回復 2023-04-14
?
料青山看我應如是

TA貢獻1772條經驗 獲得超8個贊

您正在使用以下代碼添加命令:


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);

}

所以命令名稱是文件 export .name。在您的 expore 文件中,您沒有名稱屬性。相反,你寫了標題。嘗試這個:


module.exports = {

    name: 'pause',

    description: "Pause the current song.",

    execute(message){

       const queue = message.client.queue.get(message.guild.id);

       if(!queue) return message.reply("There is nothing playing").catch(console.error);

       if(queue.playing){

           queue.playing = false;

           queue.connection.dispatcher.pause(true);

           return queue.textChannel.send(`? Paused.`).catch(console.error);

       }

    }

};


查看完整回答
反對 回復 2023-04-14
?
繁星coding

TA貢獻1797條經驗 獲得超4個贊

所以你設置命令按名稱執行但在你的導出中沒有名稱,你在事件端的.get中調用它,這就是它返回未定義的原因,希望它有用



查看完整回答
反對 回復 2023-04-14
  • 3 回答
  • 0 關注
  • 132 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號