简体   繁体   中英

discord.js | Putting a role in quick.db

basically I tried making a command to set a muterole, which is using quick.db. Basically using o.set muterole @role should put the role into the db and show in the settings panel.

Instead of showing in the settings panel when doing:

let muterole = await db.fetch(`muterole_${message.guild.id}`)

It will just say [ object Object ] in the section.

So I tried doing

let mrdb = await db.fetch(`muterole_${message.guild.id}`)

let muterole = message.guild.roles.cache.get(mrdb)

And then it appeared as undefined.

This is the second attempt. 这是第二次尝试。

How can I make it so using quick.db I can make the muterole process through the Database properly.

(sorry if unclear)

From the way you've described it, it appears that you're storing the role itself in the database, rather than the ID, therefore calling message.guild.roles.cache.get() returns undefined.

Instead of storing the role itself to the database, store the role's ID.

Your muterrole is an object as indicated in your first attempt. This means that when you set your field to that value it will appear as [Object object] . This is the Javascript representation of an invalid object assignation. To fix this issue, you may wish to console.log() your muter role:

console.log(muterrole)

To find out the structure of the object. An example can be found below:

example_role = {name: "Anonymous", date: "25th April 2020"};
console.log(example_role)         // {name: "Anonymous", date: "25th April 2020"}
console.log(example_role.name)    // Anonymous

Using what is mentioned above in code, you can console.log() your object to find what element you need and use the.x function on it to get that value.

Hope this helps, feel free to comment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM