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

156
Views
Recopilación del ID de usuario del primero en responder

Recientemente hice este comando donde los usuarios tienen 15 segundos para escribir 'atrapar' para ganar monedas. El único problema es que no estoy seguro de cómo hacer que las monedas vayan a la persona que escribió 'atrapar' primero. En este momento está configurado para que las monedas siempre vayan a la persona que activó el comando. Intenté usar la guía discord.js para coleccionistas pero seguía recibiendo errores. Todavía soy bastante nuevo en esto, cualquier cosa ayuda gracias.

 const profileModel = require("../models/profileSchema"); module.exports = { name: "catch", description: "users must type catch first to catch the animal", async execute(client, message, msg, args, cmd, Discord, profileData) { const prey = [ "rabbit", "rat", "bird", ]; const caught = [ "catch", ]; const chosenPrey = prey.sort(() => Math.random() - Math.random()).slice(0, 1); const whenCaught = caught.sort(() => Math.random() - Math.random()).slice(0, 1); const earnings = Math.floor(Math.random() * (20 - 5 + 1)) + 5; const filter = ({ content }) => whenCaught.some((caught) => caught.toLowerCase() == content.toLowerCase()); const collector = message.channel.createMessageCollector({ max: 1, filter, time: 15000 }); collector.on('collect', async (m) => { if(m.content?.toLowerCase() === 'catch') { message.channel.send(`You caught the ${chosenPrey}! You gained ${earnings} coins.`); } await profileModel.findOneAndUpdate( { userID: message.author.id, }, { $inc: { coins: earnings, }, } ); }); collector.on('end', (collected, reason) => { if (reason == "time") { message.channel.send('Too slow'); } }); message.channel.send(`Look out, a ${chosenPrey}! Type CATCH before it gets away!`); } }

El profileSchema por si acaso

 const profileModel = require("../../models/profileSchema"); const cooldowns = new Map(); module.exports = async (Discord, client, message) => { let profileData; try { profileData = await profileModel.findOne({ userID: message.author.id }); if(!profileData){ let profile = await profileModel.create({ name: message.member.user.tag, userID: message.author.id, serverID: message.guild.id, coins: 0, }); profile.save(); } } catch (err) { console.log(err); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Parece que tu recopilador está usando dos variables diferentes para el mensaje:

 collector.on('collect', async (m) => { if(m.content?.toLowerCase() === 'catch') { message.channel.send(`You caught the ${chosenPrey}! You gained ${earnings} coins.`); } await profileModel.findOneAndUpdate( { userID: message.author.id, }, { $inc: { coins: earnings, }, } ); });

Está verificando si el mensaje m (recopilado por su recopilador) tiene el contenido 'atrapar', y luego encuentra el ID de usuario del usuario que verifica el autor del message (desde sus parámetros de ejecución () arriba, entonces, el mensaje que activó este comando) cuando debería estar usando m .

Entonces, para solucionar esto, debe cambiar el ID de usuario: mensaje.autor.id a ID de userID: m.author.id userID: message.author.id

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!