管理コマンドにアクセスできる役割を変更できる「システム」を作ろうとしていますが、どうすればよいかわからないというエラーが表示されます。
コード:
def get_prefix(client, message):
with open("prefixes.json", 'r') as f:
prefixes = json.load(f)
return prefixes[str(message.guild.id)]
@bot.command(name="changeadminrole", help="Choose the role that can execute admin commands")
async def changeadmin(ctx, role: Role):
with open("admins.json", 'r') as f:
admins = json.load(f)
admins[str(ctx.guild.id)] = role.name
with open("admins.json", 'w') as f:
json.dump(admins, f, indent=4)
await ctx.send(f"Admin role changed to {role.mention}")
次に、人々が必要な役割を持っているかどうかを確認するために、私はこれを行います:
@bot.command(name="kick", help="Kicks a member from the server")
@commands.has_role(get_adminrole)
私にはこのエラーが発生する役割があります。
discord.ext.commands.errors.MissingRole: Role <function get_adminrole at 0x03977220> is required to run this command.
Idkなぜ<function get_adminrole at 0x03977220>
、admins.json
ファイルに存在するロール名の代わりにその()を取得するのですか?
{
"506201000374435850": "Absolute Admin"
}
助けていただければ幸いです。
これが私がそれをするために使用したコード全体です。
ここで、残りのコードを続行できる役割を取得しました。
@bot.command()
async def changeadmin(ctx, *, role: discord.Role):
# Code here
await ctx.send(f"Admin role changed to {role.mention}")
名前の代わりにロールIDを保存して、スキップrole = ....
してただ実行できるようにするとよいでしょう。return admins[str(message.guild.id)]
def get_adminrole(message):
with open("admins.json", 'r') as f:
admins = json.load(f)
role = discord.utils.get(message.guild.roles, name=admins[str(message.guild.id)])
return role.id
キックコマンドの使用方法の回避策は次のとおりです
@bot.command()
async def kick(ctx):
admin_role_id = get_adminrole(ctx)
if ctx.author not in ctx.guild.get_role(admin_role_id).members:
await ctx.send("You are not an Admin")
return
# code here
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加