Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Guild command can only be used once #116

Open
johann-lau opened this issue Feb 10, 2022 · 7 comments
Open

Guild command can only be used once #116

johann-lau opened this issue Feb 10, 2022 · 7 comments

Comments

@johann-lau
Copy link

(Please point out any mistakes, if I get too confused.)
I created a guild-only slash command, as follows:

bs = Slash(bot)
...
@bs.command(name= "test",
            description= "Foo bar", guild_ids= [880686520678371369],
            default_permission= False,
            guild_permissions= {880686520678371369: ui.SlashPermission(allowed= {ui.SlashPermission.USER: [687474789342117900]})}
)
async def tester(ctx):
    await ctx.respond("Test")
# 687474789342117900 is my user ID

I invoked this slash command. Immediately after that, the command gets removed from the list of other commands. All other commands continued to work, so I believe it is not a fatal bug. I tried looking into the module's code but I cannot find anything - I think it might be the bot wrongly deleting the command?

@kvsxxx
Copy link
Member

kvsxxx commented Feb 14, 2022

sorry for the late response, can you try to install the git version instead?

pip install git+https://github.com/discord-py-ui/discord-ui

@johann-lau
Copy link
Author

Unfortunately, I think it is not working either. This time it gives the following error:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nextcord/client.py", line 415, in _run_event
    await coro(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/discord_ui/client.py", line 174, in on_ready
    await self.commands.sync()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/discord_ui/slash/types.py", line 1548, in sync
    for i, c in enumerate(data):
TypeError: 'NoneType' object is not iterable

And also

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nextcord/client.py", line 414, in _run_event
    await coro(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nextcord/client.py", line 1864, in on_connect
    await self.rollout_application_commands()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nextcord/client.py", line 1894, in rollout_application_commands
    await self.deploy_application_commands(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nextcord/client.py", line 1808, in deploy_application_commands
    await self._connection.deploy_application_commands(data=data, guild_id=None, associate_known=associate_known,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nextcord/state.py", line 619, in deploy_application_commands
    await self.http.delete_global_command(self.application_id, raw_response["id"])
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nextcord/http.py", line 331, in request
    raise NotFound(response, data)
nextcord.errors.NotFound: 404 Not Found (error code: 10063): Unknown application command

@kvsxxx
Copy link
Member

kvsxxx commented Feb 18, 2022

sorry for the late response again I had a lot of stuff to do.
seems like an issue in the lib, I'll fix that rq

@kvsxxx
Copy link
Member

kvsxxx commented Feb 19, 2022

alright the issue should be fixed can you try to reinstall discord-ui again?

@johann-lau
Copy link
Author

This time, it seems like that the command is not registered. However, all other commands are working fine.

@kvsxxx
Copy link
Member

kvsxxx commented Feb 21, 2022

can you try to nuke all commands and then restart the bot

to nuke your commands (delete them all) add this snippet of code

@bot.listen()
async def on_ready():
    await bs.commands.nuke()

let the code run for one time and then remove that piece of code again

@johann-lau
Copy link
Author

This time:

Ignoring exception in on_ready
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nextcord/client.py", line 415, in _run_event
    await coro(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/discord_ui/client.py", line 174, in on_ready
    await self.commands.sync()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/discord_ui/slash/types.py", line 1552, in sync
    command._id = _command['id']
UnboundLocalError: local variable '_command' referenced before assignment

I tried changing discord_ui/slash/types.py line 1547~1553 to the following:

        for command in commands:
            for i, c in enumerate(data):
                if c['name'] == command.name and c['type'] == command.command_type.value:
                    _command = data.pop(i)
                    command._id = _command['id']
            command._state = self._state
            self._raw_cache[command._id] = command

It didn't raise any errors. However, global commands are not registered and I am not allowed to use that guild command.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants