crate a discord bot python api code example

Example 1: how to make a discord bot python

# pip install discord

import 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 ourselves
        if message.author == self.user:
            return

        if message.content == 'ping':
            await ctx.send(f'Client Latency: {round(self.bot.latency * 1000)}')

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

Example 2: 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 itself
      if message.author == client.user:
      		return
      
      #now let's start with the message content check
      if 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