Answers for "discor python boppt"

10

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')
Posted by: Guest on April-06-2020
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

Python Answers by Framework

Browse Popular Code Answers by Language