Professional Documents
Culture Documents
MaraDrinksMilk - Discord - Py
MaraDrinksMilk - Discord - Py
tv/MaraDrinksMilk
discord.py
how to make a discord bot with python and host it 24/7 for free
twitch.tv/MaraDrinksMilk
SET 2
UP 4
twitch.tv/MaraDrinksMilk
Create a Developer Account
https://discord.com/developers/applications
UP
a. Admin is a strong permission to give a bot, but allows you
to do a lot and bypass a lot of private channels. A lot of
Discord bots will ask for Admin, but if you want, you can
limit permissions in your future bots!
4. Copy the link generated
5. Go to the link and add the bot to your new test server!
twitch.tv/MaraDrinksMilk
Shhh...
Create a secret variable
for your bot token
twitch.tv/MaraDrinksMilk
main.py
import discord
import os
bot = discord.Client()
@bot.event
async def on_ready():
print('We have logged in as {0.user}'.format(bot))
@bot.event
async def on_message(message):
if message.author == bot.user:
return
if message.content.startswith('$hello'):
await message.channel.send('Hello!')
bot.run(os.environ['TOKEN'])
twitch.tv/MaraDrinksMilk
main.py
...
@bot.event
async def on_message(message):
...
if message.content.startswith('$echo'):
await message.channel.send(message.content[5:])
...
twitch.tv/MaraDrinksMilk
main.py
...
@bot.event
async def on_message(message):
...
if message.content.startswith('$hi'):
if len(message.mentions) != 0:
await message.channel.send("Hey, <@" + message.author.id +
"> !")
else:
for mention in message.mentions:
await message.channel.send("Hey, <@" + mention.id + "> !")
...
twitch.tv/MaraDrinksMilk
main.py
...
@bot.event
async def on_message(message):
...
if message.content.startswith('$channel'):
channel_name = message.content[8:]
await message.channel.category.create_text_channel(channel_name)
...
twitch.tv/MaraDrinksMilk
stay_awake.py
@app.route('/')
def home():
return "Hey, I'm awake!"
def run():
app.run(host='0.0.0.0', port=8080)
def stay_awake():
t = Thread(target=run)
t.start()
twitch.tv/MaraDrinksMilk
main.py
import discord
import os
from stay_awake import stay_awake
stay_awake()
bot = discord.Client()
@bot.event
async def on_ready():
print('We have logged in as {0.user}'.format(bot))
...
twitch.tv/MaraDrinksMilk
twitch.tv/MaraDrinksMilk
Thanks for
tuning in! discord.gg/ebMsPKpkBu
biweekly challenges + community
linkedin.com/in/maralihart
MaraDrinksMilk