I have searched all through Stackoverflow and I can't find a fix, Granted a lot of other people have the same error they didn't really help when I looked them up. The error is:
CommandInvokeError: Command raised an exception: UnpicklingError: invalid load key, 'H'
Here is the code I have at the moment:
@bot.command(pass_context=True)
async def joke(ctx):
with open("joke_file1.pk1", "rb") as f:
joke_list = pickle.load(f)
await bot.say(random.choice(joke_list))
@bot.command(pass_context=True)
async def addjoke(ctx, *args):
if not os.path.isfile("joke_file1.pk1"):
joke_list = []
else:
with open("joke_file1.pk1", "rb") as f:
joke_list = pickle.load(f)
joke_list.append(" ".join(args))
with open("joke_file1.pk1", "wb") as f:
pickle.dump(joke_list, f)
That is in my main file and I also have another file for letting it read from the .txt file I have and heres the code for that one
import pickle
with open("joke_file1.pk1", "rb") as f:
jokes = pickle.load(f)
with open("joke_title1.txt", "r") as f:
data = f.readlines()
for joke in data:
jokes.append(joke.replace("\n", ""))
with open("joke_file1.pk1", "wb") as f:
pickle.dump(jokes, f)
I get the same error on that second file as the top one. If someone can help me fix this I thank you!
This image is what all the files look like. Cow.py is the code that reads the .txt file
I fixed everything. All I needed to do is remove the preset files and run the bot again. Once ran everything worked again. T