title: Discord bot unable to get access to the Google Sheets getting error The request is missing a valid API key
body: <p>I am having problem with my Discord bot trying to access the Google Sheets API v4.0. I want it to read, write, and update data in the sheet. My code work fine for Node.js application but when I put my code in a Discord bot, it gives me this error:</p>
  <p><code>UnhandledPromiseRejectionWarning: Error: The request is missing a valid API key</code></p>
  <p>I don't understand why I am getting this error. I even made a service account for my Discord bot.</p>
  <p>Here is the Discord bot's code.</p>
  <pre><code>require('dotenv').config();
  
  const sheet = require('./sheet');
  const { Client } = require('discord.js');
  const { sheets } = require('googleapis/build/src/apis/sheets');
  const client = new Client();
  </code></pre>
  <p>Sheet file code:</p>
  <pre><code>const {google} = require('googleapis');
  const keys = require('./keys.json');
  
  const client  = new google.auth.JWT(
      keys.client_email,
      keys.private_key_id,
      keys.private_key,
      ['https://www.googleapis.com/auth/spreadsheets']
  );
  
  client.authorize(function(err,tokens){
  
      if(err){
          console.log(err);
          return;
      }
      // else{
      //     console.log('Connected');
      //     gsrun(client);
      // }
  });
  
  const getdata = async function gsrun(cl){
  
      const gsapi = google.sheets({version:'v4',auth:cl});
  
      const opt = {
          spreadsheetId:'1LzdhD4rb2FdElTyQCAkgb5oyeGeu0d9rT2abS4n_4i8',
          range: 'A2:B5'
      };
  
      let data =  await gsapi.spreadsheets.values.get(opt);
  
      console.log(data.data.values);
  }
  exports.getdata = getdata;
  </code></pre>
  <p>I have given access to bot email id to sheet which is discordbotapi@nodejs-api-testing-discordbot.iam.gserviceaccount.com. I have also enabled the Google Sheets API. Where am I making error?</p>