##defines get_repeat role and reads the json and whatever
def get_repeatrole(client, message):
with open('repeatrole.json', 'r') as c:
prefixes = json.load(c)
return roles[str(message.guild.id)]
##repeat - trying to custom role per server##
###REPEAT ROLE CHANGE###
@client.command(pass_context=True, aliases=['crr', 'repeatchange', 'changerr'])
@has_permissions(administrator=True)
async def changerepeatrole(ctx, role):
with open('repeatrole.json', 'r') as c:
roles = json.load(c)
roles[str(ctx.guild.id)] = roled
with open('repeatrole.json', 'w') as c:
json.dump(roled, f, indent=4)
ctx.send(f'{role} can now use the repeat command')
###REPEAT ROLE CHANGE###
###repeat command
@client.command()
@commands.has_role({get_repeatrole})
async def repeat(ctx, times: int, content='repeating...'):
for i in range(times):
await ctx.send(content)
@repeat.error
async def repeat_error(ctx, error):
if isinstance(error, discord.ext.commands.errors.NotOwner):
await ctx.send("You do not own this bot lol")
我似乎无法记录所记录的角色。我的目的是弄清楚如何通过命令将角色分配给特定命令。我没有收到任何错误消息,但是没有用。请帮助,在此先感谢:>
答案 0 :(得分:0)
更好地将角色ID保存在JSON中
下面是修改后的代码:
##defines get_repeat role and reads the json and whatever
def get_repeatrole(client, message):
with open('repeatrole.json', 'r') as c:
roles = json.load(c)
return roles[str(message.guild.id)]
##repeat - trying to custom role per server##
###REPEAT ROLE CHANGE###
@client.command(pass_context=True, aliases=['crr', 'repeatchange', 'changerr'])
@has_permissions(administrator=True)
async def changerepeatrole(ctx, role: discord.Role):
with open('repeatrole.json', 'r') as c:
roles = json.load(c)
roles[str(ctx.guild.id)] = role.id
with open('repeatrole.json', 'w') as c:
json.dump(roles, f, indent=4)
await ctx.send(f'{role.mention} can now use the repeat command')
###REPEAT ROLE CHANGE###
###repeat command
@client.command()
async def repeat(ctx, times: int, content='repeating...'):
if get_repeatrole(client, ctx) not in [i.id for i in ctx.author.roles]: return await ctx.send("You do not own this bot lol")
for i in range(times):
await ctx.send(content)