How to create a discord bot!

I have found it hard to make a discord bot without Botghost or anything like that,
then I tried Replit and after some time it worked
!I just want to show you the code I used!
This is in Python

Code:

# This example requires the 'message_content' intent.
 
import discord

intents = discord.Intents.default()
intents.message_content = True

client = discord.Client(intents=intents)

@client.event
async def on_ready():
    print(f'We have logged in as {client.user}')

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('hello'):
        await message.channel.send('Hello!')

    if message.author == client.user:
        return

    if message.content.startswith('hi'):
        await message.channel.send('Hi! I am a robot!')

client.run('Discord_bot_token')

If you copy and paste it and then change the value up there (to the bots token)
Then run the script and if you did it correct you will get a working bot!!!
Try “Hi” and “Hello”!
Hope this works!
:smiley:

do not put the

This example requires the ‘message_content’ intent.

in the code

Instead of .startswith() I find it easier to just use string indexing since it’s much more concise.

if message.content[:5] == 'hello':
  await message.channel.send('Hello!')'
1 Like

Oh, okay, thank you for telling me that,
I will try that