I have attempted numerous approaches without success. Below is our current implementation (personal information excluded for privacy).
@bot.command(aliases=['terminate', 'exit', 'stop'])
async def shutdown(ctx):
if ctx.guild.id != targetServerId:
return
trusted_role = discord.utils.get(ctx.guild.roles, name="Trusted Members")
if trusted_role in ctx.author.roles:
await ctx.send("Shutting down the bot...")
await bot.close()
else:
return
Any assistance would be greatly valued.
Try using bot owner check. Include @commands.is_owner() before your shutdown function. Just make sure your trusted user is the owner or assign permissions carefully. It adds extra security for bot control. Also, keep an eye on error logs in case any unnoticed issues arise! gl 
To ensure only specific members can execute the shutdown command, you can utilize a dedicated channel for trusted interactions or use a configuration file to list user IDs allowed to use the command. Compare the ctx.author.id with this list. Adding these mechanisms helps in maintaining control over the shutdown process. Lastly, ensure your bot doesn’t have elevated permissions to prevent any security issues in case of misuse.
You could also consider using decorators to restrict command execution. For instance, you could create a custom decorator to check if ctx.author.id matches IDs in a trusted list before the shutdown is triggered. It’s a neat way to keep the code clean and maintain security easily. 