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

402
Views
¿Cómo hacer que un bot de discordia extraiga una celda aleatoria de una hoja de Google cada vez que se usa un comando?

Estoy usando Autocode, así que tengo la API de Google vinculada a mi bot de discordia. Descubrí cómo hacer que el bot recupere una celda distinta, pero quiero que extraiga una al azar cada vez que se usa el comando.

Por ejemplo, un usuario quiere arrojar algo (una lista de palabras en una hoja de Google) a otro usuario. El Usuario1 escribiría "/lanzar @Usuario2" y devolvería un mensaje en discordia que dice "Usuario1 arrojó ranas a @Usuario2" o algo similar.

A continuación se muestra mi código actual, pero sé que no es correcto (especialmente la línea con la descripción)

 module.exports = async (event, context) => { if (event.content === `${process.env.prefix}throw` || event.content === `${process.env.prefix}throwing`) { let text = event.content.split(' ');//splits every word in your message let database = await lib.googlesheets.query['@0.3.0'].distinct({ range: `throw!A:A`, bounds: `FIRST_EMPTY_ROW`, where: [{ }], field: `Throw` }); await lib.discord.channels['@0.1.1'].messages.create({ channel_id: event.channel_id, content: ``, embed: { title: ` `, type: 'rich', color: 0xff7700, description: `${.getRange(resultCellRow,resultCellColumn).setValue( vA[Math.floor(Math.random()*vA.length)]);} g ${database.distinct.values[0]}`,//tagged user and cell pulled from Gsheet } }) } }
over 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Después de muchas pruebas y errores y la ayuda del soporte de Autocode, esta es la solución que se me ocurrió.

 module.exports = async (event, context) => { if (event.content === `${process.env.prefix}throw`) { let text = event.content.split(' ');//splits every word in your message let query = await lib.googlesheets.query['@0.3.0'].select({ range: `throw!A:A`, bounds: `FIRST_EMPTY_ROW`, where: [{}], limit: { 'count': 0, 'offset': 0 } });//Google Sheet query console.log(query) let random = Math.floor(Math.random() * (query.rows.length - 1));//pulls random row from the query console.log(random) let throw = query.rows[random].fields.Throw;//pulls random word from the Throw column field console.log(throw) await lib.discord.channels['@0.1.1'].messages.create({ channel_id: `${context.params.event.channel_id}`, content: ``, embed: { title: ``, description: `${throw}`, color: 0xd5f2fc, }, }); } }
over 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
Virtual assistant