repl.com discord bot not working

so i got this code in repl (look picture):

import discord
import os
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 bitch') 

   client.run(os.getenv('TOKEN'))

and if i run it nothing is happening. The code just shuts down immediatly. i try to make a discord bot.

Welcome there,

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

indentation is part of python syntax, you have made so that this is not called

which is what creates the connection with the discord bot, as you put it inside an if statement that execute only in response to an event in the server, so it will never be called

Oh yeah i see thank you both

you have to get your bots token then it will be fine to do it go on the webpage of it the dev page it should be in bot settings

For some reason, I was getting a 429 error when trying out this code a couple days ago. But now it seems to be working just fine!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.