Answer the question
In order to leave comments, you need to log in
How to remove a role from a user using id in discord.py?
I want to remove roles from all recorded users in the
JSON database:
[{"author": 606893698198011913, "exp": 5, "hero": 0}], [{"author": 400230840417779712, "exp": 0, "hero": 0}] # и т.д.
def load_stats_data():
with open("stats.json", "r") as read_file:
data = json.load(read_file)
return data
users_data = list(load_stats_data()) # Получаем json
with open("stats.json", "w") as f:
for user in users_data:
role_1 = user['author'].guild.get_role(834011803486257174) # Снятие ролей
await user['author'].remove_roles(role_1)
json.dump(users_data, f)
@bot.command() # Регистрация
async def reg(ctx):
author = ctx.author
users_data = list(json_checker.load_stats_data()) # получаем данные со stats.json
with open("stats.json", "w") as f:
users_data.append({'author': ctx.author, 'exp': 0, 'hero': 0})
json.dump(users_data, f)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question