COdeingNinja
COdeingNinja

Reputation: 387

How to add a user to a private channel by discord bot code in node and javascript?

I am trying to add a user of the server to the channel once they verify there email id. Once they are verified they should be added to a private channel which already exists of discord server. However I am new here and not able to find what to do here. My code is as below:

      client.on('message',(message)=>{
       if(message.content=="!join-clan1"){
            if (message.author.bot) return;
            message.reply("Check your DM please");
            message.author.send("Enter your email Id please? you have some time").then((newmsg)=>{
                newmsg.channel.awaitMessages(response => response.content,{
                    max:1,
                    time:500000,
                    errors:['time'],
                }).then((collected)=>{
                    newmsg.channel.send(`Email id is : ${collected.first().content}`);
                    if(collected.first().content == "DATABASE ID OF MEMBER"){
                   //COde here to add the member to private channel
                    }
                })
            });

Any help will be appreciated

Upvotes: 1

Views: 4943

Answers (2)

COdeingNinja
COdeingNinja

Reputation: 387

Well I figured out an another way. It is simply to give a role in your private channel. The way to do it is simply this

let role = message.guild.roles.cache.find(r => r.name === "Normal User");
                let member = message.member;
                member.roles.add(role).catch(console.error);

It worked for me.

Upvotes: 0

Yankue
Yankue

Reputation: 378

First, you'd have to get the voice channel, like:

const myChannel = message.guild.channels.cache.get('id-here');

Then, assuming the default permission for @everyone is view_channel: false and send_messages: false, you can do this to allow the member to see it:

myChannel.updateOverwrite(message.member, {
    SEND_MESSAGES: true,
    VIEW_CHANNEL: true
});

Upvotes: 2

Related Questions