if not interaction.user.guild_permissions.manage_channels:
await interaction.response.send_message("You dont have permission for this command", ephemeral=True)
I don't know what to set this only for admins / owners. Members can lock / unlock channels...
when i try to /lock /unlock as a member he send me message ""You dont have permission for this command" and lock channel
@bot.slash_command()
async def lock( interaction, channel : nextcord.TextChannel= None):
if not interaction.user.guild_permissions.manage_channels:
await interaction.response.send_message("Vi niste u mogucnosti da koristite ovu komandu!", ephemeral=True)
if channel is None:
channel = interaction.response.message.channel
await channel.set_permissions(interaction.guild.default_role, send_messages= False)
await interaction.response.send_message('Channel is locked.')
@bot.slash_command()
async def unlock( interaction, channel : nextcord.TextChannel= None):
if not interaction.user.guild_permissions.manage_channels:
await interaction.response.send_message("Vi niste u mogucnosti da koristite ovu komandu!", ephemeral=True)
if channel is None:
channel = interaction.response.message.channel
await channel.set_permissions(interaction.guild.default_role, send_messages= None)
await interaction.response.send_message('Channel is unlocked')
here is full code
You can use has_permissions() to check for special permissions.
In your case, you can implement it like this:
@bot.command()
@commands.has_permissions(administrator=True)
If you want only the owner of the bot to be able to execute a command, use:
@commands.is_owner()