Saltar al contenido

hacer un ejemplo de código de Python de bot de discordia

Nuestro grupo especializado despúes de ciertos días de investigación y de recopilar de información, obtuvimos la solución, queremos que te resulte útil para tu proyecto.

Ejemplo 1: 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")

Ejemplo 2: como importar discordia en Python

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

Ejemplo 3: cómo hacer un pitón de bot de discordia

# pip install discordimport discord

class MyClient(discord.Client):
	async def on_connect(self):
        print('[LOGS] Connecting to discord!')

    async def on_ready(self):
        print('[LOGS] Bot is ready!')
        print("""[LOGS] Logged in: n[LOGS] ID: n[LOGS] Number of users: """.format(self.bot.user.name, self.bot.user.id, len(set(self.bot.get_all_members()))))
        await self.bot.change_presence(activity=discord.Game(name="Weeke is a god!"))
	
    async def on_resumed(self):
        print("n[LOGS] Bot has resumed session!")

    async def on_message(self, message):
        # don't respond to ourselvesif message.author == self.user:
            returnif message.content =='ping':
            await ctx.send(f'Client Latency: round(self.bot.latency * 1000)')

client = MyClient()
client.run('token')

Ejemplo 4: 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 itselfif message.author == client.user:
      		return#now let's start with the message content checkif 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

Ejemplo 5: chat moderado del bot de discordia de Python

import discord

class MyClient(discord.Client):

    async def on_ready(self):
        print('Logged on as', self.user)

    async def on_message(self, message):
        word_list =['cheat', 'cheats', 'hack', 'hacks', 'internal', 'external', 'ddos', 'denial of service']# don't respond to ourselvesif message.author == self.user:
            return

        messageContent = message.content
        if len(messageContent)>0:
            forwordin word_list:
                if word in messageContent:
                    await message.delete()
                    await message.channel.send('Do not say that!')
            
        messageattachments = message.attachments
        if len(messageattachments)>0:
            forattachmentin messageattachments:
                if attachment.filename.endswith(".dll"):
                    await message.delete()
                    await message.channel.send("No DLL's allowed!")elif attachment.filename.endswith('.exe'):
                    await message.delete()
                    await message.channel.send("No EXE's allowed!")
                else:
                    break

client = MyClient()
client.run('token here')

Ejemplo 6: ejemplo de bot de Discord.py

#Anything commented out is optionalimport 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')

Aquí puedes ver las comentarios y valoraciones de los lectores

Ten en cuenta dar visibilidad a esta reseña si te valió la pena.

¡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 *