python discordbot code example
Example 1: how to import discord in python
py -3 -m pip install -U discord.py
Example 2: How to setup discord.py bot
import discord
from discord.ext import commands
import asyncio
client = commands.Bot(command_prefix='!')
token = 'YOUR TOKEN HERE'
@client.command()
async def hello(ctx):
await ctx.send('Hello I am a Test Bot!')
@client.event
async def on_ready():
print('Hello, I am now running')
client.run(token)
Example 3: discord python bot
from discord.ext import commands
bot = commands.Bot(command_prefix="^^")
async def on_ready():
print("Logged in as - {} | {}".format(bot.user, bot.user.id))
print("Invite link | https://discord.com/oauth2/authorize?client_id={}&scope=bot&permissions=8".format(
bot.user.id))
bot.run("__TOKEN__")