Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
186 views
in Technique[技术] by (71.8m points)

database - Command returning null when it should be setting as a channelID

Ok, so I am trying to make a discord.js command that essentially creates a channel for a user gives them Manage_Messages perms in it, gets said channel's ID, and sets the ID as the user's channel in the database (I'm using quick.db).

The script is below -

const Discord = require('discord.js');
const db = require('quick.db');

module.exports = {
    name: 'userchannel',
    description: 'options for the user economy channels',
    execute (client, message, args) {
        if (!message.author.id === '559200051629654026') return;
        let character = message.author;
        let option = args[0];
        let characterChannelID = db.get(`${character.id}.econChannelID`);

        // Create channel -------------------------
        if (option === 'create') {
            if (characterChannelID === null) {
                let econChannel = message.guild.channels.create(`${character.username}-businesses`, {
                    type: 'text',
                    permissionOverrides: [
                        {
                            id: character.id,
                            allow: ['MANAGE_MESSAGES'],
                        },
                    ],
                }).then(channel => {
                    let category = message.guild.channels.cache.find(c => c.id === '738079217513791578' && c.type === 'category');
                    channel.setParent(category.id);
                }).catch(console.error)

                message.guild.channels.cache.find(c => {
                    c.name === `${character.username}-businesses`
                    db.set(`${character.id}.econChannelID`, c.id);
                    console.log(characterChannelID)
                })

                message.channel.send(`Channel created! See it at <#${characterChannelID}>`);
            } else if (!characterChannelID === null) {
                let alreadyHasChannel = new Discord.MessageEmbed()
                    .setColor('RANDOM')
                    .setDescription(`You already have a businesses channel! Hyperlink: <#${characterChannelID}>`)
                message.channel.send(alreadyHasChannel)
            }
        }
    }
}

I'm thinking is something with the discord.js portion, however I'm not 100% sure. Been looking on stack and on codegrepper a bit, as well as just experimentation, but none of that has worked as of now. >_<

question from:https://stackoverflow.com/questions/65837436/command-returning-null-when-it-should-be-setting-as-a-channelid

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...