'Discord bot won't go online

I've just started learn python and my discord bot won't go online. it just said " Process exit with exit code 0". And there's no error with the code.

here's my code. enter image description here



Solution 1:[1]

Add await client.process_commands(ctx) and @client.event don't need parentheses(). Use the code given below:

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

  await client.process_commands(ctx)

Use this entire code if it still not working:

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix="!")


@bot.event
async def on_ready():
  print('We are logged in!')

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

   await bot.process_commands(message)

@bot.command()
async def ping(message) :
   await message.channel.send("Pong!!")

bot.run("TOKEN")

Solution 2:[2]

You should try this instead

import os
import discord
from discord.ext import commands

discord_token = "Your Token"

client = discord.Client()

bot = commands.Bot(cloient_prefix="!")

@client.command()
async def on_ready():
  print("running")

other codes here...

bot.run(discord_token)

Solution 3:[3]

You should try this instead

import os
    import discord
    from discord.ext import commands
    
    discord_token = "Your Token"
    
    client = discord.Client()
    
    bot = commands.Bot(command_prefix="s!")

@bot.event
async def on_ready():
  print("running")

bot.run(discord_token)

@bot.command()
async def on_ready():
  print("running")

bot.run(discord_token)


and the output should be running

Solution 4:[4]

The code you gave is wrong, this is correct:

import os 
import discord
from discord.ext import commands

bot = commands.Bot(command_prefix="!") # you don't need an extra discord.client Bot is enough
token = os.getenv("TOKEN")
#you should not run the program here you should run it at last

@bot.event #no need for brackets
async def on_ready():
  print("running")

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

@bot.command(name="span",description="YOUR DESCRIPTION HERE") # it is command and not commands
async def span_(ctx,amount:int,*,message):
  for i in range(amount):
    await ctx.send(message)

bot.run(token) #you should run the bot now only and this will work perfectly!

You can find the the documentation for discord.py here.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 ME immortal
Solution 3 Hunter Eyes
Solution 4 Nick stands with Ukraine