Skip to content

Instantly share code, notes, and snippets.

@Nixinova
Created March 31, 2022 00:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nixinova/a11c696cd4926aad58f473dbde11b3ae to your computer and use it in GitHub Desktop.
Save Nixinova/a11c696cd4926aad58f473dbde11b3ae to your computer and use it in GitHub Desktop.
Discord Python bot template

Discord Bot template

Create a Discord API account then run python bot.py.

More info

import os
import random
import discord
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
client = discord.Client()
@client.event
async def on_ready():
print(f'{client.user} has connected to Discord!')
@client.event
async def on_message(message):
content = message.content.lower()
if message.author == client.user:
return
elif 'bad bot' in content:
replies = [
"Don't be mean :(",
"Bad human",
]
reply = random.choice(replies)
await message.channel.send(reply)
client.run(TOKEN)
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
"discord.py" = "*"
python-dotenv = "*"
[dev-packages]
[requires]
python_version = "3.9"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment