1import discord
2
3client = discord.Client()
4
5@client.event
6async def on_ready():
7 print('Logged in as {0.user}'.format(client))
8
9@client.event
10async def on_message(message):
11 if message.author == client.user:
12 return
13
14 if message.content.startswith('$hello'):
15 await message.channel.send('Hello!')
16
17client.run('your token here')
1# Discord.py is a API wrapper for python.
2Docs = "https://discordpy.readthedocs.io/en/latest/"
3PyPI = "pip install -U discord.py"
4
5# --- A simple bot ---
6
7import discord
8from discord.ext import commands
9
10client = commands.Bot(comand_prefix='bot prefix here') # You can choose your own prefix here
11
12@client.event()
13async def on_ready(): # When the bot starts
14 print(f"Bot online and logged in as {client.user}")
15
16# A simple command
17@client.command(aliases=["ms", "aliases!"]) # You make make the command respond to other commands too
18async def ping(ctx, a_variable): # a_variable is a parameter you use in the command
19 await ctx.send(f"Pong! {round(client.latency * 1000)}ms. Your input was {a_variable}")
20
21client.run('your token here') # Running the bot
1
2#Import essentials
3import discord
4from discord.ext import commands
5import asyncio
6#Some things that makes your life easier! (aliases to make code shorter)
7client = commands.Bot(command_prefix='!') #change it if you want
8token = 'YOUR TOKEN HERE' #Put your token here
9#Making a first text command! (Respond's when a user triggers it on Discord)
10@client.command()
11async def hello(ctx):
12 await ctx.send('Hello I am a Test Bot!')
13#Tell's us if the bot is running / Runs the bot on Discord
14@client.event
15async def on_ready():
16 print('Hello, I am now running')
17
18
19
20client.run(token)
1import discord
2
3client = discord.Client()
4
5@client.event
6async def on_ready():
7 print('We have logged in as {0.user}'.format(client))
8
9@client.event
10async def on_message(message):
11 if message.author == client.user:
12 return
13
14 if message.content.startswith('$hello'):
15 await message.channel.send('Hello!')
16
17client.run('your token here')
1import discord
2
3class MyClient(discord.Client):
4 async def on_ready(self):
5 print('Logged on as', self.user)
6
7 async def on_message(self, message):
8 # don't respond to ourselves
9 if message.author == self.user:
10 return
11
12 if message.content == 'ping':
13 await message.channel.send('pong')
14
15client = MyClient()
16client.run('token')
17