An example bot of user install slash command + cog. Using Pycord 2.6.1
- Use slash command in public server, private server and DM. You don't need to have bot installed in the server to use the command, you can use command everywhere!
- Using your bot command by App Launcher.

-
Download or
git clonethis repository. -
Run
pip install -r requirements.txtto install required Python library. -
Run
python main.pyto start the bot.
-
To run this bot, first you need to create a bot at Discord Developer Portal. I assume you are already very familiar with this step. If you don't know how to do this, go watch some tutorial videos on YouTube.
-
Since we are making a bot that supports user install commands, we need to make enable
User Installoption and some other configuration at dev portal, as below image shown.
-
Now, invite your bot to your test server. Mention the bot, open its profile and click
Add App.
After you authorized the bot, you will see a nice little pop up at bottom right corner tells you App Added!

We can now open App Launcher and check our bot. Of course, you won't see any commands because you haven't run the code. You can see the /ping command in the image because I ran the code earlier.

- Here comes the coding part. I assume you are familiar with these steps too, so I'll keep it simple.
- Download or
git clonethis repository. - Run
pip install -r requirements.txtto install required Python library. - Create a .env file and enter
DISCORD_BOT_TOKEN = 'THE_BOT_TOKEN_YOU_GET_FROM_DISCORD_DEV_PORTAL' - Run
python main.pyto start the bot.
- You can see that
/pingcommand works without any problem in servers with/wthout bot installed and in DM :)
- Copy
ping.pyincogsfolder and rename it to the name you like. -
- Rename every 'ping' in
ping.pyto the name you like.
- Rename every 'ping' in
- Open
main.py, you can see:
extensions = [
'cogs.ping',
]now add 'cogs.another_command_name', under 'cogs.ping',
4. Restart main.py
ping.py
class ping(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.slash_command(
name='ping',
description='Check bot latency',
integration_types=[
IntegrationType.user_install, # This line shows that the command is a user install command
IntegrationType.guild_install,
],
contexts=[
InteractionContextType.guild,
InteractionContextType.bot_dm, # This line shows that the command can be used in DM
InteractionContextType.private_channel, # This line shows that the command can be used in private channel
],
)
