I need to make a bot that stores the user’s UserID in a txt file, and then deletes that UserID when the user does a command.
This code looks at the text file with all the users’ UserID’s. Then it finds the UserID of the user who did the command – and then is supposed to delete that user’s UserID from the file. However, this command doesn’t work – as it deletes the ENTIRETY of the text file’s content – when it’s only supposed to delete one line. I have browsed for an hour in forums to solve this: but nothing has worked.
@client.command()
async def unreserve(ctx):
author = (ctx.author.id)
with open('ReservedUsers.txt', 'r') as f:
lines = f.readlines()
with open('ReservedUsers.txt', 'w') as f:
for line in lines:
if line == author:
f.write(line)
And this is an example of the ‘ReservedUsers.txt’ file:
000000000000000001
000000000000000002
000000000000000003