Здравствуйте, пытаюсь сделать кастомные роли на сервере, но при использовании команды изменения выдаёт ошибку:
Command raised an exception: AttributeError: 'str' object has no attribute 'value'
Код, который я использую:
import discord
from discord.ext import commands
import random
import json
from discord.utils import get
class Custom(commands.Cog):
def __init__ (self, client):
self.client = client
@commands.command()
async def role (self, ctx):
await open_acc(ctx.author)
users = await get_roles_data()
user = ctx.author
role = await ctx.guild.create_role(name="Роль")
await ctx.author.add_roles(role)
id = role.id
users[str(user.id)]["role"] = id
with open("roles.json", "w") as f:
json.dump(users, f, indent=4)
@commands.command()
async def роль (self, ctx, color, *, name):
await open_acc(ctx.author)
users = await get_roles_data()
user = ctx.author
rid = users[str(user.id)]["role"]
role = get(ctx.guild.roles, id=rid)
await role.edit(name=name, color=color)
await ctx.send("Роль успешно изменена.")
async def open_acc(user):
users = await get_roles_data()
if str(user.id) in users:
return False
else:
users[str(user.id)] = {}
users[str(user.id)]["role"] = None
with open("roles.json", "w") as f:
json.dump(users, f, indent=4)
return True
async def get_roles_data():
with open("roles.json", "r") as f:
users = json.load(f)
return users
def setup(client):
client.add_cog(Custom(client))