how to make a discord bot in python

Solutions on MaxInterview for how to make a discord bot in python by the best coders in the world

showing results for - "how to make a discord bot in python"
Emelie
11 Apr 2019
1import discord
2from discord.ext import commands
3
4bot = commands.Bot(command_prefix="!", description="The description")
5
6@bot.event
7async def  on_ready():
8    print("Ready !")
9
10@bot.command()
11async def ping(ctx):
12    await ctx.send('**pong**')
13
14bot.run("enter the token here between the quotes")
David
06 Feb 2016
1# pip install discord
2
3import discord
4
5class MyClient(discord.Client):
6	async def on_connect(self):
7        print('[LOGS] Connecting to discord!')
8
9    async def on_ready(self):
10        print('[LOGS] Bot is ready!')
11        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()))))
12        await self.bot.change_presence(activity=discord.Game(name="Weeke is a god!"))
13	
14    async def on_resumed(self):
15        print("\n[LOGS] Bot has resumed session!")
16
17    async def on_message(self, message):
18        # don't respond to ourselves
19        if message.author == self.user:
20            return
21
22        if message.content == 'ping':
23            await ctx.send(f'Client Latency: {round(self.bot.latency * 1000)}')
24
25client = MyClient()
26client.run('token')
Valerio
01 Oct 2020
1#Anything commented out is optional
2
3import discord
4from discord.ext import commands
5
6bot = commands.Bot(command_prefix='prefix here')
7
8@bot.event
9async def on_ready():
10#   await bot.change_presence(activity=discord.Game(name="Rich Presence Here"))
11    print('Logged in as: ' + bot.user.name)
12    print('Ready!\n')
13    
14@bot.command()
15async def commandname(ctx, *, somevariable)
16#If you don't need a variable, then you only need (ctx)
17#	"""Command description"""
18	Code goes here
19	await ctx.send('Message')
20
21bot.run('yourtoken')
Daniella
04 Feb 2020
1import discord
2
3class MyClient(discord.Client):
4
5    async def on_ready(self):
6        print('Logged on as', self.user)
7
8    async def on_message(self, message):
9        word_list = ['cheat', 'cheats', 'hack', 'hacks', 'internal', 'external', 'ddos', 'denial of service']
10
11        # don't respond to ourselves
12        if message.author == self.user:
13            return
14
15        messageContent = message.content
16        if len(messageContent) > 0:
17            for word in word_list:
18                if word in messageContent:
19                    await message.delete()
20                    await message.channel.send('Do not say that!')
21            
22        messageattachments = message.attachments
23        if len(messageattachments) > 0:
24            for attachment in messageattachments:
25                if attachment.filename.endswith(".dll"):
26                    await message.delete()
27                    await message.channel.send("No DLL's allowed!")
28                elif attachment.filename.endswith('.exe'):
29                    await message.delete()
30                    await message.channel.send("No EXE's allowed!")
31                else:
32                    break
33
34client = MyClient()
35client.run('token here')
Aleah
18 Jun 2017
1#________________________________________________________________________________________#
2#                                                                                        #
3#                               How to make a discord bot                                #
4#________________________________________________________________________________________#
5
6
7# BE AWARE! YOU NEED TO CUSTOMIZE/CONFIGURE THIS CODE OTHERWISE IT WON'T WORK. 
8# THIS CODE IS JUST THE BASICS
9
10
11
12# IMPORT DISCORD.PY. ALLOWS ACCESS TO DISCORD'S API.
13import discord
14
15# IMPORTS EXTENSIONS FOR COMMANDS
16from discord.ext import commands
17
18
19# IMPORT THE OS MODULE.
20import os
21
22# IMPORT LOAD_DOTENV FUNCTION FROM DOTENV MODULE.
23from dotenv import load_dotenv
24
25# IMPORT LOGGING
26
27import logging
28
29
30# LOADS THE .ENV FILE THAT RESIDES ON THE SAME LEVEL AS THE SCRIPT.
31load_dotenv()
32
33# GRAB THE API TOKEN FROM THE .ENV FILE.
34DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
35
36# GETS THE CLIENT OBJECT FROM DISCORD.PY. CLIENT IS SYNONYMOUS WITH BOT.
37bot = discord.Client()
38
39logger = logging.getLogger('discord')
40logger.setLevel(logging.DEBUG)
41handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w')
42handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
43logger.addHandler(handler)
44
45
46bot = commands.Bot(command_prefix='Yourprefix')
47
48# UNDER THIS LINE OF CODE ARE THE COMMANDS FOR THE BOT. YOU CAN ADD/CHANGE THOSE SAFELY WITHOUT DESTORYING THE CODE
49
50@bot.command()
51async def test(ctx, *, arg):
52	await ctx.send(arg, file=discord.File('yourfile.png'))
53
54
55@bot.command()
56async def laugh(ctx):
57	await ctx.send("typeherealink")
58
59
60
61
62@bot.command()
63async def die(ctx):
64	exit()
65
66
67
68# EXECUTES THE BOT WITH THE SPECIFIED TOKEN. DON'T REMOVE THIS LINE OF CODE JUST CHANGE THE "DISCORD_TOKEN" PART TO YOUR DISCORD BOT TOKEN
69bot.run(DISCORD_TOKEN)
70
71#________________________________________________________________________________________#
72
73# If this code helped you please leave a like on it. If you want to see more of this follow me
74# Or just take a look at another answer of my answers
75#
76# THIS CODE HAS BEEN MADE BY : Vast Vicuña
Fox
03 Jul 2017
1import discord
2from discord.ext import commands
3
4client = commands.Bot(command_prefix=".")
5
6@client.event
7async def on_ready():
8    print("Ready!")
9
10bot.run("TOKEN")
queries leading to this page
make yout discord bot online with pythonhow to make a discord bot copy what i say pythondiscord bot pythoinexample discord bot pythonwriting discord bot pythonhow to set up a discord bot pythonhow to create discord bot in pythonhow to make a discord bot in pythonpython discord bot exampleslearn discord pyhow to program discord botpython how to code discordreal python discord botpython run discord botdiscord bot examplediscord bot simple script pythonhow to type on discord with pythondiscord py bot tutorialhow to make discord bot with pythondiscord bot pytohnpython how to write discord botmake a discord bot pythonbasic discotd botdiscord py bot sample codediscord bot framework pythonbasic discord bot code pythonpython discord bot to copy paste messagediscord bot pythn codecan you a discord bot using pythonpython discord chatbotdiscord bots pythonhow to create a discord bot in python vs codehow to make a discord bot in pythobdiscord bot pyhtonhow to create a discord bot pythonmake a discord bot with pythonexample discord py botdiscord bot tutorial pythondiscord bot pythnodiscord python bot ideascreate discord bot in pythonmaking a discord bot pythondiscord bot custom pythondiscord bot pythonmaking a bot for discord in pythondiscord bot commands pythondiscord eventsfor bots pythondiscord bot codepython connect discord botpython how to make a discord botzhow to program discord bot pythonhow to add code to discord bot pythondiscord py bot examplemake a discord botpython discord bot examplehow to program a discord bot in pythonhow to make discord python bot how to create a discord botbasic discord py bothow to code a discord botpython discord bot buttonsdiscord python bot codinghow to make bot auto respond to messages in discord pyhow to make a discord moderation bot pythonhow to create a spam user discord with pythonpython discord bot classdiscord python bot skeleton codemake discord botpython bot discord exemplecreate a discord bot pythondiscord bot coding python basicsdsicord py bot examplepython discord bot writediscord python bot runhow to make discord bot in pythonbasic discord bot pythondiscord bot code pythonpython code for discord bothow to make commands discord bot pythondiscord py botdiscord py command code copy and pastepydroid 3 discordhow to create discord bot using pythondiscord bot python main filediscord py samplehow to make a bot in discord pythondiscord bot python defaultget discord bot name pythondiscord bot setup pythonmaking a discord bot in pythonmusic bot python discordpython nuke bot for discordhow to make a discord bot pyhow to make discord bots with pythondiscord bot example in pythonhow to make a bot for discord in pythondiscord make botbot python discorddiscord bot documentation python how to make a discord py botpythn discord botdiscord bot python tutorialdiscord python bot runhow to make a bot in discord pyhow to use apis using python for discord botdiscord bot statuscode for discord bot pythondiscord bot py how to make a token loggermake a python discord botdiscord client bot pythondiscord botbasic discord bot python commandshow to discord bot pythondiscord bot in pythoncode discord bot pythonhow to connect a discord bot to pythonhow to make a discord bot in python 3 8discord bot discord pydiscord bot for pythonhow to make discord bot pycan you make discord bot in pythondiscord py python server botdiscord bot pytonmaking a simple discord bot with python codediscord bot python set uphow to make a discord botdiscord bot on ready discord pydiscord bot python codehow to code a discord bot in pythondiscord bots in pythondiscord bot creation pythondiscord py simple botdiscod python botpython discord bot basicpython start discord bothow to make a discord bot with pythonmake a discord bot in a clas pythondiscord py how to make a bothow to login bot python discordhow to make a discord bot in discord pydiscord bot commands python examplehow to assign roles in discord bot using pythonhow to use python to read discord messages on your own accounthow to start a python discord bothow to turn a bot discord pythonsimple discord bot pythonspam bot discord pythonget bot discord pysend a bot discord bot pythoncode for discord python botbasic python discord botcreate bot discord pythondiscord python object oriented programmingwhats the python code for adiscord bothow to make a discord bot discord pydiscord python tutoraildiscord py code examplehow to make a bot in discord 2020 using pythonmake a trivia discord bot pythonsimple discord bot listen for messgae pytonhow to program a discord bot python how to make discord bot using pythondiscord bot python simplemake discord bot send a messasge python 2020how to make a bot discord pyhow to make a python discord botdiscord bot in discord pyhow to make discord bot in discord pybot discord python codedownload discord pythonhow to write a python bot to constantly paste and send a message in discord chatpython discord botpyhon discord bot codescreating a discord bot in pythonhow to create a discord bot using pythonpython 3 7 discord bot tutorialmake a disocrd bot pythondiscord bot pypython discord bot codeshow to write a discord bot in pythondiscord bot python aihow to make bot discordsample discord bot codecreate python botmaking discord bot pythondiscord bot source code python easy botsdiscord python bot apihow to use discord bots in pythonhow ot creat discord bot pythonhow to create discord bothow to create a discord bot with pythondiscord create bot pythoncreate discord bot with pythonhow to make discord bot pythondiscord python bothow to make a discord bot using pythonhow to make a discord bot pythonwhen discord bot start discord pydiscord bot with pythondiscord welcome bot script python how to make a discord bot pythinbot discord pythonhow to make a game in discord bot pythonhow to create a discord python projectdiscord bot example code pythonpython discord py hacking toolpython discord bot frameworkhow to make discord bot in pytohnbuild a discord chatbot using pythoncreate discord bot pythondiscord bot in python tutorialpython bot tutorialhow to turn on a discord bot pythonmake a discord bot in pythonsample discord bot pythonbasic discord py botdiscord bot starts with pythondiscord py discord bot discord python bot examplediscord py bot codehow to make discord bot python pycharmpython 3 8 discord boy examplehow to make bot in discord pydiscord bot examplediscord bot python examplehow to start a discord bot in pythondiscord bot fileshow to make a bot for discord python make discord bot pythonhow to get bot pydiscord on chat event pythonlearn discord pydiscord py botdiscord bot example pythonhow to run code on bot start discord pyhow to get py botpython discordbot code samplepython bot discordmaking a discord bot with pythondiscord python bot setupdiscord py 40bothow to make a discord bot in python