Python从谷歌驱动器获取txt

时间:2020-11-11 18:51:06

标签: python python-3.x discord discord.py

所以我正在制作一个从txt获取问题和答案的discord机器人,但是我希望我的朋友也可以远程访问该txt,所以我认为google drive是一个好主意,但我似乎无法找到一种方法。

如您所见,脚本以txt每行的第一个单词作为问题,第二个作为答案。

如果无法使用Google驱动器,还有其他方法吗?现在我考虑了一下……也许我可以为该机器人发出命令以将其自己添加到txt中,如果没有更简单的方法,我将这样做,因为那将很繁琐...

import os
import random
import discord
client = discord.Client()
symbols = ('?',',','!','/','(',')','=','|','@','#','"',"'","¿","¡","-","_",".","·","~","$","·","ª","º","+","*",";",":")
TOKEN = 'XXXXXXXXXXXXXXXXX'
directory = 'C:/Users/XXXX/Desktop/Folders/Python/DiscBot/paquest.txt'
file = open(directory, 'r')
qlines = []
linecount = 0
for line in file:
    line_list = line.split()
    qlines.append(line_list)
file.close()
print(qlines)

@client.event
async def on_ready():
    print(f'{client.user} has connected to Discord!')
    channel = client.get_channel(XXXXXXXXXXXXXXXXXX)
    await channel.send("**online**")

@client.event
async def on_message(message):
    channel = client.get_channel(XXXXXXXXXXXXXXXXXX)
    m = ''
    m = message.content.lower()
    m = m.replace(' ', '')
    for i in range(0,len(symbols)):
        m = m.replace(symbols[i],'')
    print(m)
    if message.author == client.user:
        return
    
    for i in range(0, len(qlines)):
        print(qlines[i][0])
        if m == qlines[i][0]:
            await message.channel.send(qlines[i][1])
        elif m == 'pa':
            rn = random.randint(0,1)
            if rn == 1:
                await message.channel.send('what')
            elif rn == 0:
                await message.channel.send('what do you need')
    print(message)
client.run(TOKEN)

0 个答案:

没有答案