Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

360
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda