Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python How to make a basic discord bot [PYTHON]

James

Active Coder
Hello again! It has been a while since I have made one of these and I see questions a lot about discord bots so I thought why not make a tutorial!

To get started you're gonna need python, to install python go to https://www.python.org/downloads/

I am using 3.7.0 at the time of writing this but any 3.7 version should work the same.

Now you need to install the discord module.
To do this you need to open your command prompt and type "pip install discord.py"
Wait for it all to download.

Now go to https://discordapp.com/developers/applications/

Click on new application and give your bot a name!

Now go to "Bot"

Click "Add Bot"

img.png

Now you've added the bot keep your bots token for later (DO NOT SHOW ANYONE)


Now, you need to import the discord module

import discord

Great!

Now you should actually load up the bot

Python:
import discord

token = '' # Your bots special token (look above at where we create the bot app)

client = discord.Client()

client.run(token)

Great! Your bot is online, but what next? You can't run any commands?

Well, this is where the main part comes in.

Python:
import discord
token = ''
client = discord.Client()

@client.event
async def on_message(message):
    author = message.author
    channel = message.channel
    guild = channel.guild
    if message.type != discord.MessageType.default: # Checks to make sure it is send by a user
        return None
    if author == client.user: # Checks to make sure whoever is sending the message isn't the actual bot itsself
        return None
    await channel.send('Hello, '+author.name+' you said, '+message.content+', in, '+channel.name+' on the server, '+guild.name+'.')

client.run(token)

And there is a bot. No commands but it works and gives you some info when you type.

If this gets some views and replies I will make another tutorial showing you how to add commands and embeds, until then, goodbye!
 

Buy us a coffee!

Back
Top Bottom