I am creating a discord bot and would like to write to a specific cell in Google sheets. With this code i am able to post the userInput into the embed when the command is executed on discord.
However the code is returning an error : Missing range, and is not writing in google sheets.
Essentially i want the user to use the command "/checkbl steamidhere". "steamidhere" would be whatever the userInput is. Write that user input into the Google sheets cell H1.
This is my code I am currently using:
async sample() {
const sheets = google.sheets({ version: "v4", auth });
const spreadsheetId = "sheetid";
const sheetName = "BOTDATA";
const cells = ["H1"];
const valueInputOption = "USER_ENTERED";
const userInput = "sample value";
const result = await sheets.spreadsheets.values.update({
spreadsheetId,
range: `'${sheetName}'!${cells[0]}`,
resource: { values: [[userInput]] },
valueInputOption,
});
console.log(result.data);
}
sample();
I believe your goal is as follows.
userInput
of const userInput = interaction.options.get('steamid').value;
into the cell "H1" of "BOTDATA" sheet.In this case, how about the following modification? In this modification, the function readBlacklist()
is not used. Only the value userInput
is put into the cell "H1" of "BOTDATA" sheet.
const userInput = interaction.options.get('steamid').value;
const bl = new EmbedBuilder()
const userInput = interaction.options.get('steamid').value;
// --- I added the below script.
const spreadsheetId = "myspreadsheetID";
const sheetName = "BOTDATA";
const cells = ["H1"];
const valueInputOption = "USER_ENTERED";
// const userInput = "sample value"; // This is a sample value. In your situation, "const userInput = interaction.options.get('steamid').value;" is used.
const result = await sheets.spreadsheets.values.update({
spreadsheetId,
range: `'${sheetName}'!${cells[0]}`,
resource: { values: [[userInput]] },
valueInputOption,
});
// console.log(result.data); // If you want to confirn the returned value, please use this.
// ---
const bl = new EmbedBuilder()
userInput
is put into the cell "H1" of "BOTDATA" sheet.sheets
can be used for putting the values to the Spreadsheet using Sheets API. Please be careful about this.From your following reply,
I've updated my original question with the modification, and the error i am receiving.
and, the following your new error,
Unfortunately i am getting TypeError: (intermediate value)(...) is not a function
Unfortunately, I cannot replicate your new error. I'm worried whether your new error is related to my script. So, in order to check it, please test the following script. In the additional script, only my script is used. If the same error occurs, please tell me.
async function sample() { // <--- Modified
const sheets = // Please use your client
const spreadsheetId = "###"; // Please set your spreadsheet ID.
const sheetName = "BOTDATA";
const cells = ["H1"];
const valueInputOption = "USER_ENTERED";
const userInput = "sample value";
// const sheets = google.sheets({ version: "v4", auth }); // Please remove this line.
const result = await sheets.spreadsheets.values.update({
spreadsheetId,
range: `'${sheetName}'!${cells[0]}`,
resource: { values: [[userInput]] },
valueInputOption,
});
console.log(result.data);
}
sample();