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

如何添加 ID 保存在 JSON 文件 discord.js v12 中的角色

How to add a role with an ID that is saved in an JSON file discord.js v12?(如何添加 ID 保存在 JSON 文件 discord.js v12 中的角色?)
本文介紹了如何添加 ID 保存在 JSON 文件 discord.js v12 中的角色?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在發出警告命令,但我遇到了角色分配問題.首先,我有一個命令為公會設置警告角色.它對 &setwarnedrole {role ID} 做出反應.它將角色 ID 保存到公會 ID 旁邊的 JSON 文件中.然后,warn 命令讀取文件,并獲取與執行命令的公會 ID 一起存儲的角色 ID.您使用 &warn {user ping/user ID} 來警告人們.但是當我這樣做時,它給了我一個錯誤:

I'm making a warn command and I've run into a problem with the role giving. First, I have a command that sets the warned role for the guild. It reacts to &setwarnedrole {role ID}. It saves the role ID into a JSON file, next to the guild ID. Then, the warn command reads the file, and gets the role ID that was stored with the guild ID the command is executed in. You use &warn {user ping/user ID} to warn people. But when I do that, it gives me an error:

TypeError [INVALID_TYPE]: Supplied roles is not a Role, Snowflake or Array or Collection of Roles or Snowflakes.

我的 &setwarnedrole 代碼:

My code for &setwarnedrole:

const { DiscordAPIError } = require("discord.js");
const Discord = require('discord.js');
const fs = require("fs");
let warnedRoleList = JSON.parse(fs.readFileSync("./roleIDs/warnedRole.json", "utf-8"));

module.exports = {
    name: 'setwarnedrole',
    description: "Set the warned role for your guild with this command",
    execute(message, args){
        const fs = require("fs");
        let warnedRoleList = JSON.parse(fs.readFileSync("./roleIDs/warnedRole.json", "utf-8"));
        if (!message.member.hasPermission("MANAGE_GUILD")) return message.reply("you are missing the manage server permissions")
        let guildID = message.guild.id;
        const warnedRole = message.guild.roles.cache.get(args[0]);
        const warnedRoleID = warnedRole.id
        if (!warnedRole) {
            return message.reply('invalid role ID')
        };

        message.reply(`warned role succesfully set to ${warnedRole}`)

        if(!warnedRoleList[guildID])warnedRoleList[guildID] = {
            warnedRoleList: warnedRoleID
        };
    
        fs.writeFile("./roleIDs/warnedRole.json", JSON.stringify(warnedRoleList), err => {
            if (err) console.log(err)
        });

        console.log(`Warned role ID = ${warnedRoleID}`)
        console.log(`Guild ID = ${guildID}`)
    }
}

我的 &warn 代碼:

My code for &warn:

const { DiscordAPIError } = require("discord.js");
const Discord = require('discord.js');
const fs = require("fs");
let warnedRoleList = JSON.parse(fs.readFileSync("./roleIDs/warnedRole.json", "utf-8"));
const commands = require("./commands");

module.exports = {
    name: 'warn',
    description: "The bot will warn the mentioned user",
    execute(message, args){
        let warnedRoleList = JSON.parse(fs.readFileSync("./roleIDs/warnedRole.json", "utf-8"));
        let guildID = message.guild.id;
        if(message.member.permissions.has('MANAGE_MESSAGES')){
            var role = message.guild.roles.cache.get(`${warnedRoleList[guildID]}`);
            var member = message.mentions.members.first() || message.guild.members.cache.get(args[0]);
            if(!member) {
                message.reply('please specify the user that should be warned')
                return
            }
            if(!role) {
                message.reply('there is not a role set as the warned role, set it by doing &setwarnedrole (that requires manage server permissions)')
            }
            if (member.roles.cache.has(`${warnedRoleList[guildID]}`)) {
                message.reply('this user is already warned!')
            } else
            member.roles.add(role)
            .then(memberAdded => {
             message.channel.send(`${member.displayName} was succesfully warned by ${message.author.tag}`);
            })
            .catch(error => {
            console.log(error);
            });    
        } else message.reply(`you don't have permissions to execute this command.`);
        console.log(`${role}`)
        console.log(`${warnedRoleList[guildID]}`)
    }
}

最后,這是角色 ID 與公會 ID 一起保存在 JSON 文件中的方式:

and finally, this is how the role ID is saved with the guild ID in the JSON file:

{"745376827324760245":{"warnedRoleList":"751119465868951643"}}

第一個數字是公會 ID,第二個數字是警告角色 ID.但是即使我刪除了"簽名,制作:

with the first number being the guild ID and the second number being the warned role ID. But even if I remove the "" sign, making it:

{"745376827324760245":{"warnedRoleList":751119465868951643}}

還是不行.如果我將 role 設置為特定數字,則警告命令有效.此外,記錄 role 告訴 role = undefined.嘗試記錄 warnedRoleList[guildID] 會導致獲取 [objectObject].我做錯了什么?謝謝:)

it still doesn't work. The warn command works if I set role to a specific number. Also, logging role tells that role = undefined. Trying to log warnedRoleList[guildID] results into getting [objectObject]. What have I done wrong? Thanks :)

推薦答案

好的,我發現了錯誤.我將 &warn 中的 role 設置為 message.guild.roles.cache.get(`${warnedRoleList[guildID]}`);,但它應該是為 message.guild.roles.cache.get(`${warnedRoleList[guildID].warnedRoleList}`);.結案.

Ok, I found the mistake. I was setting the role in &warn to message.guild.roles.cache.get(`${warnedRoleList[guildID]}`);, but it is supposed to be message.guild.roles.cache.get(`${warnedRoleList[guildID].warnedRoleList}`);. Case closed.

這篇關于如何添加 ID 保存在 JSON 文件 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 服務器時的歡迎消息)
主站蜘蛛池模板: 你懂的av| 蜜桃视频在线观看免费视频网站www | 国产精品久久久久久久久久久免费看 | 精品欧美激情精品一区 | 欧美影院 | 国产亚洲区 | 在线视频 亚洲 | 国产一级精品毛片 | 亚洲二区在线 | 久久大陆| 亚洲精品一区二区三区中文字幕 | 精品国产欧美一区二区三区成人 | 一区二区三区电影网 | 久草综合在线视频 | 日韩精品视频一区二区三区 | 成人小视频在线免费观看 | 一区二区在线免费观看视频 | 欧美亚洲在线视频 | 精品成人av | 精品欧美乱码久久久久久1区2区 | 99精品免费久久久久久久久日本 | 日韩av最新网址 | 91精品国产色综合久久不卡蜜臀 | av网站免费观看 | 色综合久久天天综合网 | 亚洲第一色av | 欧美激情精品久久久久久 | 中文字幕在线一区二区三区 | 亚洲毛片在线观看 | 久久免费精品 | 一级做a| 情侣av| 欧美一区不卡 | av天天爽| 精品国产一区二区在线 | 久久综合久久久 | 国产一区欧美 | 日韩视频在线一区 | 亚洲综合色丁香婷婷六月图片 | 一区二区精品视频 | 午夜天堂精品久久久久 |