Skip to content

Instantly share code, notes, and snippets.

@Rajdave69
Last active January 8, 2023 14:10
Show Gist options
  • Save Rajdave69/db6f78dec0e46e7b5e6841b5c79ad825 to your computer and use it in GitHub Desktop.
Save Rajdave69/db6f78dec0e46e7b5e6841b5c79ad825 to your computer and use it in GitHub Desktop.
Single file Python Discord Bot template
import discord
from discord.ext import commands
# This is defining the actual bot
client = commands.Bot(intents=discord.Intents.all(), command_prefix='!')
# Event listeners are defined with the @client.event decorator
@client.event
async def on_ready():
print("Connected to Discord!")
# Normal (prefixed) commands are defined with the @client.command decorator
# Using normal commands is not recommended, as they are not slash commands
@client.command()
async def ping(ctx):
# Use ctx.send to send a message
await ctx.send("Pong!")
# Slash commands are defined with the @client.slash_command decorator
@client.slash_command()
async def ping(ctx):
# Use ctx.respond to "respond" to the slash command
await ctx.respond("Pong!")
client.run("token")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment