Answers for "discord py bot"

14

bot discord python

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix="!", description="The description")

@bot.event
async def  on_ready():
    print("Ready !")

@bot.command()
async def ping(ctx):
    await ctx.send('**pong**')

bot.run("enter the token here between the quotes")
Posted by: Guest on January-02-2021
1

Discord.py bot example

#Anything commented out is optional

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix='prefix here')

@bot.event
async def on_ready():
#   await bot.change_presence(activity=discord.Game(name="Rich Presence Here"))
    print('Logged in as: ' + bot.user.name)
    print('Ready!n')
    
@bot.command()
async def commandname(ctx, *, somevariable)
#If you don't need a variable, then you only need (ctx)
#	"""Command description"""
	Code goes here
	await ctx.send('Message')

bot.run('yourtoken')
Posted by: Guest on January-09-2021
13

discord.py

# Discord.py is a API wrapper for python. 
Docs = "https://discordpy.readthedocs.io/en/latest/"
PyPI = "pip install -U discord.py"

# --- A simple bot ---

import discord
from discord.ext import commands 

client = commands.Bot(comand_prefix='bot prefix here') # You can choose your own prefix here

@client.event()
async def on_ready(): # When the bot starts
    print(f"Bot online and logged in as {client.user}")

# A simple command
@client.command(aliases=["ms", "aliases!"]) # You make make the command respond to other commands too
async def ping(ctx, a_variable): # a_variable is a parameter you use in the command
    await ctx.send(f"Pong! {round(client.latency * 1000)}ms. Your input was {a_variable}")

client.run('your token here') # Running the bot
Posted by: Guest on September-29-2020
1

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)
Posted by: Guest on November-27-2020
2

discord python bot

import discord
from discord.ext import commands 

client = commands.Bot(comand_prefix='bot prefix here') # You can choose your own prefix here

@client.event()
async def on_ready(): # When the bot starts
    print(f"Bot online and logged in as {client.user}")

# A simple command
@client.command(aliases=["ms", "aliases!"]) # You make make the command respond to other commands too
async def ping(ctx, a_variable): # a_variable is a argument you use in the command
    await ctx.send(f"Pong! {round(client.latency * 1000)}ms. Your input was {a_variable}")

client.run('your token here') # Running the bot
Posted by: Guest on April-07-2021
9

discord.py

import discord

client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('$hello'):
        await message.channel.send('Hello!')

client.run('your token here')
Posted by: Guest on March-27-2020

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language