Answer the question
In order to leave comments, you need to log in
Gives an error message. What to do?
Hello, I'm trying to make custom roles on the server, but when using the change command, I get an error:
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))
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