【发布时间】:2019-11-16 10:07:19
【问题描述】:
我正在设置我的第一个 discord 机器人,它将能够从 Google 电子表格、官方 API 中获取数据,并将其作为嵌入消息引入 discord。问题出在 .addField() 级别,我无法输入单元格的值。我该怎么做?
const { Client, RichEmbed } = require('discord.js');
const client= new Client();
const GoogleSpreadsheet = require('google-spreadsheet');
const {promisify} = require('util');
const creds = require('./client_secret.json');
client.on('message', message => {
if (message.content === '!bot'){
async function accessSpreadsheet() {
const doc = new GoogleSpreadsheet('1qA11t460-ceILmwu6RtfiPGb_n9MUD_7z6Ld7I_Z6yc');
await promisify(doc.useServiceAccountAuth)(creds);
const info = await promisify(doc.getInfo)();
var sheet = info.worksheets[0];
var cells = await promisify(sheet.getCells)({
'min-row': 2,
'max-row': 5,
'min-col': 3,
'max-col': 3,
'return-empty': true,
})
for (var cell of cells) {
message.author.send(cell.value)
}
}
accessSpreadsheet();
const embede = new RichEmbed()
.setColor('#0099ff')
.setTitle("My Title")
.addBlankField()
.setDescription('Some description')
.addBlankField()
.addField('Name', '•'+ cell[1].value , true)
.setTimestamp();
message.author.send(embede) }
})
client.login('xxx')
我希望输出“Terrassycup 3”,但实际输出是 console.log 中的“ReferenceError: cell is not defined”
【问题讨论】:
标签: javascript node.js google-sheets-api discord.js