Я долго пытаюсь сделать так, чтобы каждый сервер мог настроить себе авто-роль, но у меня не получается, роль просто не выдается. Пожалуйста помогите. Вот мой код для авто ролей:
def AutoRole(bot, role: discord.Role):
with open("AR.json", "r") as f:
AR = json.load(f)
return AR[str(role.guild.id)]
@bot.event
async def on_guild_join(guild):
with open("prefix.json", "r") as f:
prefix = json.load(f)
prefix[str(guild.id)] = "/"
with open("prefix.json", "w") as f:
json.dump(prefix, f, indent=4)
with open("AR.json", "r") as f:
AR = json.load(f)
AR[str(guild.id)] = ""
with open("AR.json", "w") as f:
json.dump(AR, f, indent=4)
@Bot.event
async def on_member_join(member):
role = get(member.guild.roles, name=AutoRole)
await member.add_roles(role)
@Bot.event
async def on_guild_remove(guild):
with open("AR.json", "r") as f:
AR = json.load(f)
AR.pop(str(guild.id))
with open("AR.json", "w") as f:
json.dump(AR, f, indent=4)
@Bot.command()
async def AutoRole(ctx, new: str):
with open("AR.json", "r") as f:
AR = json.load(f)
AR[str(ctx.guild.id)] = new
with open("AR.json", "w") as f:
json.dump(AR, f, indent=4)