import discord
from discord.ext import commands
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from pprint import pprint
scope = ["""https://spreadsheets.google.com/feeds",'https://www.googleapis.com/auth/sprea...,"https://www.googleapis.com/auth/drive...","https://www.googleapis.com/auth/drive"""]
creds = ServiceAccountCredentials.from_json_keyfile_name("creds.json", scope)
client = gspread.authorize(creds)
sheet = client.open("NYRP Clock Ins").sheet1 # Open the spreadhseet
data = sheet.get_all_records() # Get a list of all records
row = sheet.row_values(3) # Get a specific row
col = sheet.col_values(3) # Get a specific column
cell = sheet.cell(1,2).value # Get the value of a specific cell
insertRow = ["hello", 5, "red", "blue"]
sheet.add_rows(insertRow, 4) # Insert the list as a row at index 4
sheet.update_cell(2,2, "CHANGED") # Update one cell
numRows = sheet.row_count # Get the number of rows in the sheet
class MyClient(discord.Client):
async def on_ready(self):
print('Logged in as')
print(self.user.name)
print(self.user.id)
print('------')
async def on_message(self, message):
# we do not want the bot to reply to itself
if message.author.id == self.user.id:
return
if message.content.startswith('.clock in'):
embed = discord.Embed(title='BCSO', description='Succesfully Clocked In', color=0x5ed623)
embed.add_field(name='.clock out', value='Clocks out')
await message.channel.send(content=None, embed=embed,)
insertRow = ["hello", 5, "red", "blue"]
sheet.add_rows(insertRow, 4) # Insert the list as a row at index 4
if message.content.startswith('.clock out'):
embed = discord.Embed(title='BCSO', description='Succesfully Clocked Out', color=0xef210a)
embed.add_field(name='.clock in', value='Clocks In')
await message.channel.send(content=None, embed=embed,)
invalid_scope:https://spreadsheets.google.com/feeds",'https://www.googleapis.com/auth/sprea...,"https://www.googleapis.com/auth/drive...","https://www.googleapis.com/auth / drive不是有效的受众群体字符串。
当我尝试运行bot并找不到修复程序时,出现上述错误消息
答案 0 :(得分:0)
您使用的范围未正确定义。
您可以尝试以下方法:
scope = ["https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/drive.appfolder",
"https://spreadsheets.google.com/feeds"]
有关范围的更多信息,您可以尝试阅读以下文档。
[1] https://developers.google.com/drive/api/v2/about-auth
[2] https://developers.google.com/sheets/api/guides/authorizing