how to setup python for make a discord bot code example
Example 1: discord bot python
# To make a simple discord bot that when the message content is '.hello'
# first you need to create a bot on discord.com/developers/
#there are many tutorials on how to create a bot
# then use py -3 -m pip install -U discord.py[voice] in terminal
# or if you're on mac/linux python3 -m pip install -U discord.py[voice]
import discord.py
client = discord.Client()
@client.event
async def on_ready():
print("Logged in as {0.user}".format(client)
@client.event
async def on_message(message):
#this will prevent the bot from responding to itself
if message.author == client.user:
return
#now let's start with the message content check
if message.content == '.hello':
print("Hello there!!")
#now run the bot
client.run('here put your token')
#and now when you run the program the bot will be online and working
Example 2: How to setup discord.py bot
#Import essentials
import discord
from discord.ext import commands
import asyncio
#Some things that makes your life easier! (aliases to make code shorter)
client = commands.Bot(command_prefix='!') #change it if you want
token = 'YOUR TOKEN HERE' #Put your token here
#Making a first text command! (Respond's when a user triggers it on Discord)
@client.command()
async def hello(ctx):
await ctx.send('Hello I am a Test Bot!')
#Tell's us if the bot is running / Runs the bot on Discord
@client.event
async def on_ready():
print('Hello, I am now running')
client.run(token)