久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

(節點:10388)UnhandledPromiseRejectionWarning:TypeError:無法

(node:10388) UnhandledPromiseRejectionWarning: TypeError: Cannot read property #39;cache#39; of undefined((節點:10388)UnhandledPromiseRejectionWarning:TypeError:無法讀取未定義的屬性“緩存) - IT屋-程序員軟件開發技術分享
本文介紹了(節點:10388)UnhandledPromiseRejectionWarning:TypeError:無法讀取未定義的屬性“緩存"的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我遇到了上述錯誤,我只是在測試是否可以在特定公會的頻道中發送違規者的標簽,并且代碼看起來很像下面(忽略一些不一致的部分.下面是cmd文件中的代碼.

I have been getting the above error, where I am just testing to see if I can send the offender's tag in a specific guild's channel, and the code looks pretty much like below (ignore some parts that are inconsistent. Below is the code in the cmd file.

const { prefix } = require("../config.json");

module.exports = {
    name: "report",
    description: "This command allows you to report a user for smurfing.",
    catefory: "misc",
    usage: "To report a player, do $report <discord name> <reason>",
    async execute(message, client) {

        const args = message.content.slice(1).trim().split(/ +/);
        const offender = message.mentions.users.first();

        if (args.length < 2 || !offender.username) {
            return message.reply('Please mention the user you want to report and specify a reason.');
        }


        const reason = args.slice(2).join(' ');

        client.channels.cache.get('xxxxx').send(offender);

        message.reply("You reported"${offender} for reason: ${reason}`);
    }
}

這個命令在沒有下面一行的情況下完全可以正常工作.

This command works without the below line completely fine.

client.channels.cache.get('xxxxx').send(offender);

但是一旦包含此行運行,我就會收到此錯誤.

but once run with this line included, I get this error.

(node:10388) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'cache' of undefined

下面是我的索引文件.

const fs = require('fs');
const Discord = require("discord.js");
const { prefix, token } = require('./config.json');
const client = new Discord.Client();
client.prefix = prefix;
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);
}
const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));

for (const file of eventFiles) {
    const event = require(`./events/${file}`);
    if (event.once) {
        client.once(event.name, (...args) => event.execute(...args,client));
    } else {
        client.on(event.name, (...args) => event.execute(...args,client));
    }
}

client.login(token);

事件:

message.js

module.exports = {
    name: "message",
    execute(message,client){
        if (!message.content.startsWith(client.prefix) || message.author.bot) return;
        const args = message.content.slice(client.prefix.length).trim().split(/ +/);
        const command = args.shift().toLowerCase();
        if (!client.commands.has(command)) return;
        try {
            client.commands.get(command).execute(message ,args, client);
        } catch (error) {
            console.error(error);
            message.reply('there was an error trying to execute that command!');
        }
    }
}

ready.js

module.exports = {
    name: "ready",
    once: true,
    execute(client){
        console.log("successfully logged in!");
        client.user.setActivity("VTB", {
            type: "STREAMING",
            url: "https://www.twitch.tv/monstercat"
      });
    }
}

推薦答案

你的問題可能來自這行:

Your issue likely comes from this line:

(...args) => event.execute(...args, client)

這基本上意味著獲取所有參數并將它們傳遞給 event.execute";因此,您傳遞的參數數量不確定(取決于事件類型),并且 client 不能保證是您期望的第二個.

Which means basically "take all of the parameters and pass them to event.execute" so you are passing an undetermined amount of parameters (depending on the event type) and the client is not guaranteed to be the second one as you expect.

為了提供更多細節,Discord 客戶端可以發送多種不同類型的事件,并且每種類型的事件在回調中提供不同數量的參數.換句話說,通過這樣寫: (...args) =>event.execute(...args,client) 您正在檢索未知數量的參數,并將它們全部傳遞給 event.execute 函數,因此 的位置client 參數可能會有所不同,它不一定是函數簽名中所期望的第二個:async execute(message, client) {

To provide some more details, the Discord client can send multiple different types of events, and every type of event provides a different amount of parameters in the callback. In other words by writing this: (...args) => event.execute(...args,client) you are retrieving an unknown amount of parameters, and passing them all to the event.execute function, so the position of the client parameter could vary, and it's not necessarily the second one as you expect in the function signature: async execute(message, client) {

如果不需要其他參數,您可以只檢索第一個參數,如下所示:

You could either retrieve only the first parameter if you don't need others, like this:

client.once(event.name, arg => event.execute(arg, client));

如果您絕對需要所有參數,請先傳遞客戶端,這樣它就永遠不會移動,如下所示:

And if you absolutely need all of the parameters, pass the client as first so it never moves, like this:

client.once(event.name, (...args) => event.execute(client, ...args));

同時修改 execute 簽名:

async execute(client, ...args) {

這篇關于(節點:10388)UnhandledPromiseRejectionWarning:TypeError:無法讀取未定義的屬性“緩存"的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機器人提及發出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復必須使用導入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務器時的歡迎消息)
主站蜘蛛池模板: 国产高清一二三区 | 伊人青青久久 | 亚州毛片 | 香蕉大人久久国产成人av | 中文字幕av在线 | 久久69精品久久久久久国产越南 | 永久av| 337p日本欧洲亚洲大胆鲁鲁 | 四虎影视在线 | 中国一级特黄视频 | 日韩在线免费看 | 人人干人人草 | av在线播放一区二区 | 国产精品一区免费 | 一区二区三区久久 | 国产专区在线 | 日韩精品一区在线观看 | 综合久久亚洲 | 91精品国产综合久久婷婷香蕉 | 一区二区三区久久久 | 久久激情网| 欧洲精品一区 | 久久久这里都是精品 | 夜夜草视频 | 亚洲一区二区三区在线视频 | 亚洲 中文 欧美 日韩 在线观看 | 操亚洲| 国产在线精品一区 | 日韩在线成人 | 久久国产精品一区 | 亚洲综合一区二区三区 | 综合中文字幕 | k8久久久一区二区三区 | 亚洲不卡在线视频 | 亚洲精品乱码久久久久久蜜桃91 | 久久久久久久久久久久久久av | 国产精品日本一区二区不卡视频 | 久草热在线 | 成人教育av | 巨大黑人极品videos精品 | 久草视频在线播放 |