Как сделать whitelist систему для discord бота с помощью txt документа?
Код на данный момент:
wl = [652953834360143876,804342605034553345, 729715610774274180,758091017520939058]
@client.command()
@commands.cooldown(1, 60, commands.BucketType.user)
async def whitelist(ctx):
author = ctx.message.author
if ctx.author.id in wl:
await ctx.send("You in whitelist")
else:
await ctx.send("You not in whitelist")
Я хотел бы сделать так, чтобы можно было добавлять людей командой с помощью текстового документа, а также удалять людей из whitelist.
Ответы (1 шт):
Автор решения: Kers
→ Ссылка
для примера json:
import json
wl = [652953834360143876,804342605034553345, 729715610774274180,758091017520939058]
# Сохранить в файл
with open("data_file.json", "w") as write_file:
json.dump(wl, write_file)
# Загрузить из файла
with open("data_file.json", "r") as read_file:
data2 = json.load(read_file)
print(data2)
А дальше уже логика как Вы хотите добавлять или удалять. Например добавить новых людей из файла в wl:
for i in data2:
if i in wl:
print("Есть в списке")
elif i not in wl:
wl.append(i)
print(wl)