I would like to be able to give a role to someone from the DMs if they say yes with the code underneath. I can't find the solution to understand the bot to add the role on the server to the person.
const Discord = require ("discord.js"),
Client = new Discord.Client({ partials: ["CHANNEL"], intents: [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MEMBERS,
Discord.Intents.FLAGS.GUILD_MESSAGES,
Discord.Intents.FLAGS.DIRECT_MESSAGES
]
}),
yaml = require('js-yaml'),
fs = require("fs");
var fichier = yaml.load(fs.readFileSync(`./data/keys.yml`, 'utf8'));
console.log(fichier.key)
Client.on("ready", () => {
console.log("bot opérationnel")
});
Client.on("messageCreate", message =>{
console.log("Non");
if (message.channel.type == 'DM') {
console.log('Dm recieved!')
}
if (message.content == "yes"){
console.log("ok");
}
});
Client.on("guildMemberAdd", async member => {
member.send("Bienvenue, possédez-vous une clé d'activation ? Si oui envoyer la dans le channel");
});
You can just do like this for adding a role when yes and when no
let guildId = "..." // Put the guild Id here
let yesRoleId = "..." // Put the "yes" role Id here
let noRoleId = "..." // Put the "no" role Id here
Client.on('messageCreate', async message => {
if (message.channel.type === "DM") {
let guild = client.guilds.cache.get(guildId)
let toDo = false
let role;
if (message.content.toLowerCase() === "yes") {
role = guild.roles.cache.get(yesRoleId)
toDo = true
} else if (message.content.toLowerCase() === "no") {
role = guild.roles.cache.get(noRoleId)
toDo = true
}
if (toDo = true) {
toDo = false
guild.members.cache.get(message.author.id).roles.add(role)
console.log(`Le role ${role.name} a été ajouté à ${message.author.tag}`)
}
}
})