0

我正在尝试创建一个 .quote 和 .addquote 命令并读取文件。当您键入 .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

我不知道我哪里出错了,因为在我看来这一切看起来都是正确的。我希望有人知道我哪里出错了。

4

0 回答 0