如何获得Discord机器人从特定范围的Google表格中读取数据?

JVKX

有没有办法让不和谐的机器人从Google表格中查找数据?

示例情况:如果Discord机器人出现命令“!points Bob”,则该机器人将在Google工作表中查找“ Bob”并返回鲍勃拥有的点数。

我假设我会使用模块google-spreadsheet,但是我是新手。有没有人可以帮忙?

莱纳斯·G

您可以尝试类似的方法,我尚未对此进行测试!googleapis为此使用了npm-package。

/*
Assuming your table is something like this:
 |------------------|
 | Player  | Points |
 |------------------|
 | Player1 | 0      |
 | Player2 | 100    |
 |------------------|
*/
function checkPoints(auth,name) {
    return new Promise((resolve, reject) => {
        const sheets = google.sheets({ version: 'v4', auth });

        sheets.spreadsheets.values.get({
            spreadsheetId: '<your spreadsheetid>',
            range: '<Your Points sheetname>!A2:B', // A2 because i assume you got a title like "Name/Username" etc.
        }, (err, res) => {
            if (err) return console.log("The API returned an error: " + err);
            let list = [];
            for(let i = 0; i < res[0].length; i++){ //Loop throw all Players
                if(res[0][i] == name){
                    resolve(res[1][i]); //Returns the Points of the Player
                }
            }
        }
        );
    });
}

要使用此功能,您必须通过api传递auth(请查看googleapisPackage的文档)和名称。该函数返回一个Promise,然后您就可以执行了,就像我说过的,我还没有在不和谐的bot中测试过它。

checkPoints(auth,name).then(points =>{
    console.log("Points  of player " + name + ": " + points);
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使Python Discord机器人等待测验的特定答案?

在Discord中编程机器人-如何使机器人从subreddit发送随机图像?

如何使用Discord机器人从列表中删除条目

如何让 Discord 机器人返回消息中的字数

用Python编程Discord机器人-如何使该机器人将命令限制在特定服务器上?

如何让Discord机器人创建频道

如何使用Discord机器人踢人?

如何批量删除 Discord 机器人

如何获得我的机器人的RobotState?

您如何发送Discord机器人读取的DM?(discord.py)

如何使用 Discord.js 从特定消息和来自特定用户/机器人的消息中删除嵌入

如何从机器人框架中的 API 获取 JSON 数据

如何检查机器人框架中的数据类型?

Discord.py机器人未读取其他机器人的消息

如何获得我的discord机器人所具有的所有角色的列表?

Discord.js:如何通过服务器上的机器人读取用户状态?

如何让 Discord.js 机器人读取和使用聊天中发送的图片网址

如何在discord.js中合并图像以创建Discord机器人?

您如何让Discord机器人删除用户对discord.py中消息的反应?

Discord.py:如何在我的 Discord 机器人的丰富存在中添加图像?

(discord.py)如何让我的机器人读取发送给它的DM并打印它们或将它们发送到特定频道

如何在Discord机器人上设置服务器特定的变量?

如何从特定版本的Google表格中读取数据?

ROBLOX Discord 机器人

将图像附加到Telegram机器人通过Google表格发送的文本中

用Python编程Discord机器人-如何使该机器人重复图像?

用Python编程Discord机器人-如何使该机器人运行更快?

如何让我的机器人私信成为被机器人踢的用户?(Discord.js)

如何阻止 Discord 机器人响应其他机器人?