Skip to content

Add functions to removes all commands. #41

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

Merged
merged 4 commits into from
Dec 29, 2020

Conversation

4surix
Copy link
Contributor

@4surix 4surix commented Dec 28, 2020

Hello !

I made two functions to delete all commands everywhere or just in one area (global or guild).

Why ?

I did this because I wanted to delete all the commands from a server and then put back only the ones I wanted, so that I could remove the ones that no longer exist and add the new ones.

Exemple :

import discord
import discord_slash


bot = discord.Client()
slash = discord_slash.SlashCommand(bot)

@bot.event
async def on_ready(self):

    await slash.remove_all_commands()

    # Useless, because `remove_all_commands` already removes the global commands,
    #  just for the exemple.
    await slash.remove_all_commands_in('global')

    # As explained I then call up the existing `register_all_commands` function 
    #  to add the commands I want.
    await slash.register_all_commands()

bot.run(token)

Thank you for reading, have a nice day !

@4surix 4surix mentioned this pull request Dec 29, 2020
2 tasks
@eunwoo1104
Copy link
Contributor

This is good function, but there are some questions.

  1. This doesn't affect the SlashCommand itself. This should be in the .utils.manage_commands.
  2. Why did you use for x in self.commands.keys():? This isn't necessary, and it is wasting some times.

@4surix
Copy link
Contributor Author

4surix commented Dec 29, 2020

Actually as register_all_commands was in SlashCommand, I thought it was the right place because remove_all_commands does the opposite of register_all_commands.

Yes, for x in self.commands.keys(): is absolutely useless here.
I think I should go to sleep one day.

@eunwoo1104
Copy link
Contributor

Actually as register_all_commands was in SlashCommand, I thought it was the right place because remove_all_commands does the opposite of register_all_commands.

Well... register_all_commands reads commands registered in SlashCommand. However, yours read commands list from discord API. That's why I said this should be in the .utils.manage_commands.

@4surix
Copy link
Contributor Author

4surix commented Dec 29, 2020

Okay I see, you are right,

So I moved into .utils.manage_commands and this is what it looks like :

import discord
import discord_slash
from discord_slash.utils import manage_commands


bot = discord.Client()
slash = discord_slash.SlashCommand(bot)

@bot.event
async def on_ready(self):
    await manage_commands.remove_all_commands(slash)
    await manage_commands.remove_all_commands_in(slash, 'global')
    await slash.register_all_commands()

bot.run(token)

It is good ? If yes, i commit this.

@eunwoo1104
Copy link
Contributor

eunwoo1104 commented Dec 29, 2020

Looks good!

@eunwoo1104
Copy link
Contributor

eunwoo1104 commented Dec 29, 2020

Merging this pull request. Thank you for contributing!
+ I'll trim some code to fit the code style.

@eunwoo1104 eunwoo1104 merged commit abdf0a8 into interactions-py:master Dec 29, 2020
eunwoo1104 added a commit that referenced this pull request Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants