EOFError:超出输入范围:键入命令时

时间:2018-08-18 23:58:50

标签: python discord.py eoferror

我正在尝试创建.quote和.addquote命令,并让thme读取文件。当您键入.addquote时,它将把该引号放入文件中。然后,当您输入.quote时,它将向您发送发送到文件中的随机报价。

import discord
from discord.ext.commands import Bot
from discord.ext import commands
from random import randint
import random
import asyncio
import pickle
import os
import json
from itertools import cycle
import time

Client = discord.Client()
status = ['Just', 'Being', 'Updated']
bot = commands.Bot(command_prefix='.') #This will be the prefix for your bot
bot.remove_command("help")


@bot.event
async def on_message(message):

    if message.content.startswith('.quote'):
        with open("quote_file.pk1", "rb") as quote_file:
                quote_list = pickle.load(quote_file) #This is where i get the error 
        await bot.send_message(message.channel, random.choice(quote_list)) 

    if message.content.startswith('.addquote'):
        if not os.path.isfile("quote_file.pk1"):
            quote_list = []
        else:
            with open("quote_file.pk1", "rb") as quote_file:
                quote_list = pickle.load(quote_file)
        quote_list.append(message.content[9:])
        with open("quote_file.pk1", "wb") as quote_file:
            pickle.dump(quote_list, quote_file)

出现错误

      File "C:\Users\MYNAME\Desktop\MyBot\McVPS Bot.py", line 39, in on_message
    quote_list = pickle.load(quote_file)
EOFError: Ran out of input

我不知道我要去哪里错了,因为我认为这一切看起来都是正确的。我希望外面有人知道我要去哪里错了。

0 个答案:

没有答案
相关问题