Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with commands.is_owner() #5741

Closed
3 tasks done
cvscade opened this issue Aug 19, 2020 · 11 comments
Closed
3 tasks done

Issue with commands.is_owner() #5741

cvscade opened this issue Aug 19, 2020 · 11 comments
Labels
no repro Cannot be reproduced.

Comments

@cvscade
Copy link

cvscade commented Aug 19, 2020

Summary

@commands.is_owner() behaving incorrectly.

Reproduction Steps

  1. Create a command
  2. Add the @commands.is_owner() decorator.
  3. Make sure you’ve set the owner_id whilst creating the client/bot etc. object.

Expected Results

It should work by only allowing the owner to run it.

Actual Results

It works, but it fails on some of the attempts. I made an eval command and I put the decorator onto it (in a cog yes), the command worked 2/5 times and the other 3 attempts in the console I got an error stating that you are not the owner of the bot.

Traceback-

Traceback (most recent call last):
  File "/app/.local/lib/python3.7/site-packages/discord/ext/commands/bot.py", line 903, in invoke
    await ctx.command.invoke(ctx)
  File "/app/.local/lib/python3.7/site-packages/discord/ext/commands/core.py", line 847, in invoke
    await self.prepare(ctx)
  File "/app/.local/lib/python3.7/site-packages/discord/ext/commands/core.py", line 776, in prepare
    if not await self.can_run(ctx):
  File "/app/.local/lib/python3.7/site-packages/discord/ext/commands/core.py", line 1069, in can_run
    return await discord.utils.async_all(predicate(ctx) for predicate in predicates)
  File "/app/.local/lib/python3.7/site-packages/discord/utils.py", line 340, in async_all
    elem = await elem
  File "/app/.local/lib/python3.7/site-packages/discord/ext/commands/core.py", line 1876, in predicate
    raise NotOwner('You do not own this bot.')

discord.ext.commands.errors.NotOwner: You do not own this bot.

x3

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

System Information

  • Python v3.7.9-final
  • discord.py v1.4.0-final
  • aiohttp v3.6.2
  • system info: Linux 4.4.0-1107-aws fix logic #118-Ubuntu SMP Sun May 3 TIMECENSORED(Trying to update) UTC 2020
@helish88
Copy link

helish88 commented Aug 19, 2020

add owner_id

bot = commands.Bot(command_prefix='>', owner_id = 177494227918389249)

@Rapptz
Copy link
Owner

Rapptz commented Aug 19, 2020

You don't have to set the owner_id, it gets fetched automatically on first use.

I definitely cannot repro this nor I imagine this is an issue with the library since it would be a huge security risk that would affect thousands of users. I suspect there's something going on in your configuration so this will need more information.

@Rapptz Rapptz added the no repro Cannot be reproduced. label Aug 19, 2020
@AEnterprise
Copy link

could it be the bot is owned by a team instead of an individual user?

@lgaan
Copy link
Contributor

lgaan commented Aug 19, 2020

@AEnterprise In recent discord.py versions, teams are included in the is_owner() decorator

@Phxntxm
Copy link
Contributor

Phxntxm commented Aug 19, 2020

@AEnterprise In recent discord.py versions, teams are included in the is_owner() decorator

Pretty sure his point is that he is setting owner_id directly. If that's set, then teams is not going to be handled:

if self.owner_id:
return user.id == self.owner_id
elif self.owner_ids:
return user.id in self.owner_ids
else:
app = await self.application_info()
if app.team:
self.owner_ids = ids = {m.id for m in app.team.members}
return user.id in ids
else:
self.owner_id = owner_id = app.owner.id
return user.id == owner_id

@lgaan
Copy link
Contributor

lgaan commented Aug 19, 2020

@Phxntxm Ah, I forgot about that

@cvscade
Copy link
Author

cvscade commented Aug 20, 2020

You don't have to set the owner_id, it gets fetched automatically on first use.

I definitely cannot repro this nor I imagine this is an issue with the library since it would be a huge security risk that would affect thousands of users. I suspect there's something going on in your configuration so this will need more information.

I did directly set the owner_id, and I am sure the ID is valid. As Helish88 told me to do so, my client object already looks like that. Even if I am explicitly setting the owner_id it should work. What more information can I provide?

@Rapptz
Copy link
Owner

Rapptz commented Aug 20, 2020

  1. Code has yet to be shown.
  2. Teams or not being mentioned (like the above) hasn't been disclosed.
  3. Mentioning which members are invoking and what was expected vs not.

Currently this issue is mainly saying that sometimes an exception happens and sometimes it doesn't. It's unclear what this really means. For all we know the 3 attempts that failed could have been your server members trying to run it.

@cvscade
Copy link
Author

cvscade commented Aug 20, 2020

  1. Here’s my code:
client = commands.Bot(command_prefix="$", help_command=None, owner_id=335469153869889547)

Above is my client object.

@commands.command()
@commands.is_owner()
async def test(self, ctx):
      await ctx.send(“Do something”)

Above is my command. Originally I was doing it with an eval command and then I changed over to test to see if it was something with the command it self.

  1. No it’s not a team being used, it’s just me.

  2. It was only me invoking it, and the server I am using it only has me and the bot as it’s members.

I’ve tested it several times, it works for the first 1-2 tries and then throws the you do not own this bot error.

@cvscade
Copy link
Author

cvscade commented Aug 20, 2020

And yes I have tried removing the owner_id field, that’s how it initially started. But then I thought you have to explicitly state the owner_id which I did.

@cvscade
Copy link
Author

cvscade commented Aug 20, 2020

Ok so it works now. And I’m an idiot.
Sorry for wasting time, it’s kinda weird that the same code works on Repl.it but not Glitch.
Anyway I would like to close this issue, I’m off to figuring out how to fix it on Glitch myself!

@cvscade cvscade closed this as completed Aug 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no repro Cannot be reproduced.
Projects
None yet
Development

No branches or pull requests

6 participants