Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
Agrega un rol desde el DM con Discord Bot JS

Me gustaría poder darle un rol a alguien de los DM si dice que sí con el código debajo. No puedo encontrar la solución para entender el bot para agregar el rol en el servidor a la persona.

 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"); });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede hacer esto para agregar un rol cuando sí y cuando 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}`) } } })
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!