Saltar al contenido

ejemplo simple de código de bot de discordia de Python

Ejemplo 1: bot simple discord.py

importdiscordfrom discord.extimport 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 self.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

Ejemplo 2: como importar discordia en Python

py -3-m pip install -U discord.py

Ejemplo 3: ejemplo de bot de Discord.py

#Anything commented out is optional

importdiscordfrom discord.extimport commands

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

@bot.eventasync 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')

Ejemplo 4: Cómo configurar el bot discord.py

#Import essentials
importdiscordfrom discord.extimport 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.eventasync def on_ready():print('Hello, I am now running')
    
    
    
client.run(token)

Ejemplo 5: discord Python bot

from discord.extimport 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__")

¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *