久久久久久久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 服務器時的歡迎消息)
主站蜘蛛池模板: 狠狠ri| 天堂视频免费 | 久久99一区二区 | 国产色婷婷精品综合在线手机播放 | 亚洲福利在线观看 | 久久大陆 | 在线成人| 中文字幕av第一页 | 97色在线视频 | 国产精品视频一区二区三区不卡 | 亚洲精品视频免费观看 | 中文在线一区二区 | 在线男人天堂 | 性生活毛片 | 日韩精品一区二区三区 | 国产精品一区一区三区 | 欧美日本韩国一区二区 | 户外露出一区二区三区 | 欧美日韩亚洲国产 | 能免费看的av| 国产美女一区二区 | www.伊人.com| 在线免费黄色小视频 | 国产探花在线精品一区二区 | 亚洲区一区二区 | 久久人人爽人人爽 | 一级毛片观看 | 丁香婷婷在线视频 | 免费欧美 | 色综网 | 久久精品亚洲精品国产欧美 | 精品国产一区二区三区久久久久久 | 亚洲日本一区二区三区四区 | 国产精品一区二区三区四区五区 | 成人在线精品 | 草久久 | 亚洲精品久久视频 | 日韩欧美操 | 亚洲欧美日韩精品久久亚洲区 | 国产精品亚洲综合 | 一本久久a久久精品亚洲 |