Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
483 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()
See Question&Answers more detail:os

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

1 Reply

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):

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...