adding permission error

This commit is contained in:
2022-06-30 19:41:51 +03:00
parent d9b4e1e87b
commit 6ca1e372fc

21
test.py
View File

@@ -6,6 +6,7 @@ import threading
from os import walk, path, makedirs, remove, rename, listdir from os import walk, path, makedirs, remove, rename, listdir
import discord import discord
import dislash
from discord.ext import commands from discord.ext import commands
from dislash import InteractionClient, Option, OptionType, OptionChoice from dislash import InteractionClient, Option, OptionType, OptionChoice
@@ -131,7 +132,7 @@ class Commands:
@staticmethod @staticmethod
async def set_prefix(ctx, prefix: str): async def set_prefix(ctx, prefix: str):
await Commands.write_json(ctx.guild.id, "prefix", prefix) await Commands.write_json(ctx.guild.id, "prefix", prefix)
await ctx.send(f"Prefix set to: `{prefix}`") await ctx.send(f"Prefix set to: `{prefix}`", ephemeral=True)
@staticmethod @staticmethod
def list_files(fold: str): def list_files(fold: str):
@@ -150,12 +151,12 @@ class Commands:
parameter = None parameter = None
try: try:
with open('prefix.json', 'r', encoding='utf-8') as fp: # Open the JSON with open('prefix.json', 'r', encoding='utf-8') as fp: # Open the JSON
jsonObject = json.load(fp) # Load the custom prefixes _json = json.load(fp) # Load the custom prefixes
except TypeError: except TypeError:
jsonObject = {} _json = {}
if guild: # If the guild exists if guild: # If the guild exists
try: try:
guild_conf = jsonObject[f"{guild}"] guild_conf = _json[f"{guild}"]
try: try:
parameter = guild_conf[f"{param}"] parameter = guild_conf[f"{param}"]
except TypeError: except TypeError:
@@ -306,11 +307,17 @@ async def command_set_prefix(ctx, prefix: str):
Option("prefix", "Specify prefix", OptionType.STRING, required=True), Option("prefix", "Specify prefix", OptionType.STRING, required=True),
] ]
) )
@commands.has_permissions(administrator=True) @dislash.has_permissions(administrator=True)
async def slash_set_prefix(ctx, prefix: str): async def slash_set_prefix(ctx, prefix: str):
await Commands.set_prefix(ctx, prefix) await Commands.set_prefix(ctx, prefix)
@slash_set_prefix.error
@command_set_prefix.error
async def set_prefix_error(ctx):
await ctx.reply('You don`t have permissions')
@inter_client.slash_command( @inter_client.slash_command(
name="info", name="info",
description="Read list of tracks for user", description="Read list of tracks for user",
@@ -346,7 +353,7 @@ async def info(ctx, user=None):
emb.add_field(name="Roles list", value=f"{roles}", inline=True) emb.add_field(name="Roles list", value=f"{roles}", inline=True)
emb.set_footer(text="Information requested by: {}".format(ctx.author.display_name)) emb.set_footer(text="Information requested by: {}".format(ctx.author.display_name))
await ctx.reply(embed=emb) await ctx.reply(embed=emb, ephemeral=True)
@inter_client.slash_command( @inter_client.slash_command(
@@ -376,7 +383,7 @@ async def set_bot_role(ctx, role):
@inter_client.slash_command( @inter_client.slash_command(
name="cogs", name="cog",
description="Work with cogs", description="Work with cogs",
options=[ options=[
Option("what do", Option("what do",