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 function readBlacklist() {
const spreadsheetId = "myspreadsheetID";
const sheetName = "BOTDATA";
const cells = ["H1"];
const valueInputOption = 'USER_ENTERED';
const ranges = cells.map((c) => `'${sheetName}'!${c}`);
const sheets = google.sheets({ version: "v4", auth });
try {
const response = await sheets.spreadsheets.values.update({ spreadsheetId, ranges, valueInputOption });
const rows = response.data.valueRanges.reduce((o, { values = [[""]] }, i) => ((o[cells[i]] = values[0][0]), o), {});
return rows;
} catch (error) {
console.log(`There was an error: ${error}`)
}
}
(async()=>{
const write = await readBlacklist(['test']);
console.log(write);
if (interaction.commandName === 'checkbl') {
const userInput = interaction.options.get('steamid').value;
const bl = new EmbedBuilder()
.setTitle('Blacklist Checker')
.setDescription(`${userInput}`)
.setColor('Red')
.setThumbnail('https://i.imgur.com/9GKhYQf.png')
.setFooter({text: 'DroneOS', iconURL: 'https://i.imgur.com/9GKhYQf.png'})
.setTimestamp()
interaction.reply({ embeds: [bl]});
}
})()