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

352
Views
How to get a discord bot to pull a random cell from a Google Sheet every time a command is used?

I'm using Autocode so I have the Google API linked to my discord bot. I have figured out how to get the bot to retrieve a distinct cell, but i want it to pull a random one each time the command is used.

For example one user wants to throw something (a list of words in a google sheet) at another user. User1 would type "/throw @User2" and it would return a message in discord that says "User1 threw frogs at @User2" or something similar.

Below is my current code, but I know it is not correct (especially the line with description)

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

0

After a lot of trial and error and help from Autocode support, here is the solution I came up with

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,
          },
        });
  }
}
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!