discord.py simple bot code example
Example 1: discord.py simple bot
import discord
from discord.ext import commands
client = commands.Bot(comand_prefix='bot prefix here')
@client.event()
async def on_ready():
print(f"Bot online and logged in as {self.client.user}")
@client.command(aliases=["ms", "aliases!"])
async def ping(ctx, a_variable):
await ctx.send(f"Pong! {round(client.latency * 1000)}ms. Your input was {a_variable}")
client.run('your token here')
Example 2: Discord.py bot example
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='prefix here')
@bot.event
async def on_ready():
print('Logged in as: ' + bot.user.name)
print('Ready!\n')
@bot.command()
async def commandname(ctx, *, somevariable)
Code goes here
await ctx.send('Message')
bot.run('yourtoken')
Example 3: discord bot python message that's being replied to
message.reference.resolved