pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

Discord.js V12 消息收集器“錯誤"?

Discord.js V12 Message Collector quot;bugquot;?(Discord.js V12 消息收集器“錯誤?)
本文介紹了Discord.js V12 消息收集器“錯誤"?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在創建一個名冊命令,這是我到目前為止的代碼,錯誤是當涉及到管理員時,它會像圖片中一樣出現錯誤并且它不會繼續......它還保存了所有答案在一個文件中.因此,管理員執行 $roster setup 并開始為每個文件的名稱保存回復.這是我目前唯一完成的部分,所以設置.我在那里遇到了那個錯誤,控制臺中沒有錯誤.

I am making a roster command, and this is my code so far, the error is when it comes to the admin it bugs out like in the picture and it doesn't continue... It also saves all of the answers in a file. So an admin does $roster setup and it starts saving replies for the names of each file. This is the only part I've done for now, so the setup. And I am getting that bug there, there's no error in the console.

client.on('message', async message => {
    if (message.content.startsWith(prefix + "roster")) {
    if (!message.member.hasPermission('ADMINISTRATOR')) return message.channel.send('You do not have that permission! :x:').then(message.react(':x:'))
    if (message.author.bot){}
        else {
            !fs.existsSync(`./roster/` + message.guild.id) && fs.mkdirSync(`./roster/` + message.guild.id, { recursive: true })
            const args = message.content.slice(prefix.length + 7).split(/ +/)
            let uReply = args[0];
            if(!uReply) return message.channel.send("Please use the following options: `setup`, `send`, `add` or `remove`!")

            //SETUP
            if(uReply === "setup") {
                const collector = new Discord.MessageCollector(message.channel, m => m.author.id === message.author.id, { time: 10000 });
            
                message.channel.send("Please write the exact role name of leader role (with emojis if it has).")
                collector.on('collect', message => {
                    let leaderRole = message.content
                    fs.writeFileSync(`./roster/${message.guild.id}/`+ `Leader`+".txt", message.content, (err) => console.error);
                    message.channel.send(`Ok, the leader role is called `${leaderRole}`.`) 
                    collector.off
                

                message.channel.send("Now, whats the role name of co-leader or co-owner role (with emojis if it has)?")
                collector.on('collect', message => {
                    let coleaderRole = message.content
                    fs.writeFileSync(`./roster/${message.guild.id}/`+ `Co-Leader`+".txt", message.content, (err) => console.error);
                    message.channel.send(`Ok, the co-leader/co-owner role is called `${coleaderRole}`.`) 
                    collector.off


                message.channel.send("Now, whats the role name of admin role (with emojis if it has)?")
                collector.on('collect', message => {
                    let adminRole = message.content
                    fs.writeFileSync(`./roster/${message.guild.id}/`+ `Admin`+".txt", message.content, (err) => console.error);
                    message.channel.send(`Ok, the admin role is called `${adminRole}`.`) 
                    collector.off
 

                message.channel.send("Awesome, now whats the role name of staff role (with emojis if it has)?")
                collector.on('collect', message => {
                    let staffRole = message.content
                    fs.writeFileSync(`./roster/${message.guild.id}/`+ `Staff`+".txt", message.content, (err) => console.error);
                    message.channel.send(`Ok, the staff role is called `${staffRole}`.`)
                    collector.off


                message.channel.send("Cool, now whats the role name of tiny-staff role (with emojis if it has)?")
                collector.on('collect', message => {
                    let tinyStaffRole = message.content
                    fs.writeFileSync(`./roster/${message.guild.id}/`+ `Tiny-Staff`+".txt", message.content, (err) => console.error);
                    message.channel.send(`Ok, the tiny-staff role is called `${tinyStaffRole}`.`)
                    collector.off


                message.channel.send("Just a few more, now whats the role name of higher ranked members role (with emojis if it has)?")
                collector.on('collect', message => {
                    let HigherRankedRole = message.content
                    fs.writeFileSync(`./roster/${message.guild.id}/`+ `HigherRanked`+".txt", message.content, (err) => console.error);
                    message.channel.send(`Ok, the higher ranked members role is called `${HigherRankedRole}`.`)
                    collector.off


                message.channel.send("Last one, whats the role name of the normal members role (with emojis if it has)?")
                collector.on('collect', message => {
                    let NormalMembersRole = message.content
                    fs.writeFileSync(`./roster/${message.guild.id}/`+ `NormalMembers`+".txt", message.content, (err) => console.error);
                    message.channel.send(`Awesome, the normal members role is called `${NormalMembersRole}`.`)
                    message.channel.send("That's it for setup.")
                    collector.off


                })})})})})})})





            }
            
        }
    }});

圖片:

推薦答案

我認為錯誤來自原始 MessageCollector 偵聽器未正確禁用,因此原始偵聽器仍然會為每條附加消息觸發.

I believe that the error comes from the original MessageCollector listener not being properly disabled, so the original listener still triggers for each additional message.

看起來您嘗試使用 collector.off 來停止原始偵聽器,但因為這是一個語句而不是函數調用,所以它沒有做任何事情.此外,如果它確實起作用,它將結束父收集器,并且后續的 collector.on 回調將不起作用.

It looks like you tried to stop the original listener with collector.off, but because this is a statement instead of a function call, it doesn't do anything. Furthermore, if it did function, it would end the parent collector and none of the subsequent collector.on callbacks would work.

相反,我會將 collector.on 函數替換為 collector.once 并刪除 collector.off 語句.將其更改為 collector.once 會在偵聽器接收到第一個事件后自動結束它,這正是您在這種情況下想要的.如果您想接收多個事件,則必須使用其他東西.

Instead, I would replace the collector.on functions with collector.once and remove the collector.off statements. Changing it to collector.once automatically ends the listener after it receives the first event, which is what you want in this scenario. If you wanted to receive more than one event, you'd have to use something else.

例如,監聽器看起來像這樣:

For example, the listener would look something like this:

collector.once('collect', message => {
    let leaderRole = message.content
    fs.writeFileSync(`./roster/${message.guild.id}/`+ `Leader`+".txt", message.content, (err) => console.error);
    message.channel.send(`Ok, the leader role is called `${leaderRole}`.`)

    /* ... Rest of code ... */

}

這篇關于Discord.js V12 消息收集器“錯誤"?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 服務器時的歡迎消息)
主站蜘蛛池模板: 背压阀|减压器|不锈钢减压器|减压阀|卫生级背压阀|单向阀|背压阀厂家-上海沃原自控阀门有限公司 本安接线盒-本安电路用接线盒-本安分线盒-矿用电话接线盒-JHH生产厂家-宁波龙亿电子科技有限公司 | 浇钢砖,流钢砖_厂家价低-淄博恒森耐火材料有限公司 | 铁素体测量仪/检测仪/铁素体含量测试仪-苏州圣光仪器有限公司 | 飞扬动力官网-广告公司管理软件,广告公司管理系统,喷绘写真条幅制作管理软件,广告公司ERP系统 | Magnescale探规,Magnescale磁栅尺,Magnescale传感器,Magnescale测厚仪,Mitutoyo光栅尺,笔式位移传感器-苏州连达精密量仪有限公司 | 流程管理|流程管理软件|企业流程管理|微宏科技-AlphaFlow_流程管理系统软件服务商 | 伸缩器_伸缩接头_传力接头-巩义市润达管道设备制造有限公司 | 西安文都考研官网_西安考研辅导班_考研培训机构_西安在职考研培训 | 户外环保不锈钢垃圾桶_标识标牌制作_园林公园椅厂家_花箱定制-北京汇众环艺 | 纯水电导率测定仪-万用气体检测仪-低钠测定仪-米沃奇科技(北京)有限公司www.milwaukeeinst.cn 锂辉石检测仪器,水泥成分快速分析仪-湘潭宇科分析仪器有限公司 手术室净化装修-手术室净化工程公司-华锐手术室净化厂家 | 液压升降货梯_导轨式升降货梯厂家_升降货梯厂家-河南东圣升降设备有限公司 | 碎石机设备-欧版反击破-欧版颚式破碎机(站)厂家_山东奥凯诺机械 高低温试验箱-模拟高低温试验箱订制-北京普桑达仪器科技有限公司【官网】 | 郑州外墙清洗_郑州玻璃幕墙清洗_郑州开荒保洁-河南三恒清洗服务有限公司 | 土壤墒情监测站_土壤墒情监测仪_土壤墒情监测系统_管式土壤墒情站-山东风途物联网 | 可程式恒温恒湿试验箱|恒温恒湿箱|恒温恒湿试验箱|恒温恒湿老化试验箱|高低温试验箱价格报价-广东德瑞检测设备有限公司 | 水平筛厂家-三轴椭圆水平振动筛-泥沙震动筛设备_山东奥凯诺矿机 包装设计公司,产品包装设计|包装制作,包装盒定制厂家-汇包装【官方网站】 | 沈飞防静电地板__机房地板-深圳市沈飞防静电设备有限公司 | 盘扣式脚手架-附着式升降脚手架-移动脚手架,专ye承包服务商 - 苏州安踏脚手架工程有限公司 | 山东成考网-山东成人高考网 | 首页 - 张店继勇软件开发工作室 兰州UPS电源,兰州山特UPS-兰州万胜商贸 | 德州万泰装饰 - 万泰装饰装修设计软装家居馆 | 信阳市建筑勘察设计研究院有限公司 | ★塑料拖链__工程拖链__电缆拖链__钢制拖链 - 【上海闵彬】 | PE拉伸缠绕膜,拉伸缠绕膜厂家,纳米缠绕膜-山东凯祥包装 | 磁粉制动器|张力控制器|气胀轴|伺服纠偏控制器整套厂家--台灵机电官网 | 微型驱动系统解决方案-深圳市兆威机电股份有限公司 | 翻斗式矿车|固定式矿车|曲轨侧卸式矿车|梭式矿车|矿车配件-山东卓力矿车生产厂家 | 水厂自动化|污水处理中控系统|水利信息化|智慧水务|智慧农业-山东德艾自动化科技有限公司 | 真空包装机-诸城市坤泰食品机械有限公司| 首页|成都尚玖保洁_家政保洁_开荒保洁_成都保洁| 北京普辉律师事务所官网_北京律师24小时免费咨询|法律咨询 | 北京森语科技有限公司-模型制作专家-展览展示-沙盘模型设计制作-多媒体模型软硬件开发-三维地理信息交互沙盘 | 杭州双螺杆挤出机-百科 | 水质传感器_水质监测站_雨量监测站_水文监测站-山东水境传感科技有限公司 | 数年网路-免费在线工具您的在线工具箱-shuyear.com | 全自动包装秤_全自动上袋机_全自动套袋机_高位码垛机_全自动包装码垛系统生产线-三维汉界机器(山东)股份有限公司 | 作文导航网_作文之家_满分作文_优秀作文_作文大全_作文素材_最新作文分享发布平台 | 无线联网门锁|校园联网门锁|学校智能门锁|公租房智能门锁|保障房管理系统-KEENZY中科易安 | 赛尔特智能移动阳光房-阳光房厂家-赛尔特建筑科技(广东)有限公司 | 河南不锈钢水箱_地埋水箱_镀锌板水箱_消防水箱厂家-河南联固供水设备有限公司 | 彩信群发_群发彩信软件_视频短信营销平台-达信通 |