0
votes

So I'm making a verification bot for one of my Discord Servers, and I've come across a problem.

Purpose: When the user first joins, they will be only allowed to talk in one specific channel, the verification channel. When they type $verify {username on-site}, the bot will reply in-server telling the user to check their DMs to continue. A unique string linked to a verification row in the database will be given, and the discord user will be told to change their status on-site to the given unique ID. Once they do that, they will be given the "Verified" role and will be able to speak on the discord.

The problem: When everything goes right, and the user is ready to be given the role on the discord server, the bot will not give the role. I'm assuming this is because the user that the bot is trying give the role to is not linked to the actual discord server for it, because it's in DMs.

What I'm looking for: If possible, give me an example on how to give a role to a user on a discord server from DMs, or documentation. That would be really helpful!

Code: I'll only include the part that is important, there is no other errors.

snekfetch.get("https://vertineer.com/api/getUniq.php?discord_id="+message.author.id).then(function(r){
                    console.log("here 2");
                    let uniq = JSON.parse(r.text);
                    if(uniq.id == uniq.status){
                        message.member.addRole("Verified");
                        message.reply("Success!");
                    } else {
                        message.reply("Looks like you didn't change your status to `"+uniq.id+"`, try again with `$finish`.");
                    }
                });
1
You can only add a role for member and not author.Ru Chern Chong
So how would I get the member class from the DM user? Also thank you for spotting that error, but that still doesn't fix it.dukeispie

1 Answers

1
votes

If this is only to work for one server you can do:

client.guilds.get('myguildID').members.get(message.author.id).addRole('193654001089118208')

And also, to give a role to a user you can't use the name. You need to use the ID or the Role Object.
If you would prefer to use the name you would need to do something like this:

var role = client.guilds.get('myguildID').roles.find(role => role.name === "Verified");
client.guilds.get('myguildID').members.get(message.author.id).addRole(role);