Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
52 views
in Technique[技术] by (71.8m points)

python - How does is_owner works?

So i am trying to add dev only commands me and my devs get confused on doing this as we need the is_owner but i do not know how to implement it any help here?

So currently i have a shutdown bot command for devs when it is needed:

@commands.command(pass_context=True)
@checks.isOwner()
async def shutdown(self, ctx):
    """Shuts the bot down"""
    fmt = 'Shutting down, I will miss you {0.author.name}'
    await self.bot.say(fmt.format(ctx.message))
    await self.bot.logout()
    await self.bot.close()
question from:https://stackoverflow.com/questions/65844706/how-does-is-owner-works

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you want to check if that the person using a command is an owner or developer of the bot, first you will need to set their ID as owner_id when you instance the bot:

bot = commands.Bot(command_prefix = '!', owner_id = 123345219197488900, intents = intents)

In case you are a group of developers and want to set more than one as owner_ids:

owners = [123345219197488900, 173545269197488974, 253345719197888931]
bot = commands.Bot(command_prefix = '!', owner_ids = set(owners), intents = intents)

Then you can use a command check to ensure that the user using this command is an owner.

@commands.command(pass_context=True)
@commands.is_owner()
async def shutdown(self, ctx):

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...