'Python Discord Bot Not Going Online (Code Is Correct!)

I'm working on creating a Discord Quiz Bot with Python using Visual Studio Code and following a youtube tutorial (https://www.youtube.com/watch?v=jq6IoD7EyWY).

I followed the tutorial exactly and I have no errors in my code. But when I do 'py bot.py' my bot doesn't go online like in the tutorial video. I'm not sure what is going on. I'm not getting an error in Visual Studio Code. So why is my bot not connecting? Thanks in advance!

import discord

client = discord.Client()

@client.event

async def on_message(message):

  if message.author == client.user:

     return

  if message.content.startswith('hello'):
     await message.channel.send('hello, I am a bot')

client.run('token')


Solution 1:[1]

Do you get any error in any way or do you get no output? Maybe using some print statements in your code, help you to find the issue. Something i thought of is this:

print("1") 
do_something():
   pass
print("2")

You should try to print something directly before your client.run() and see, if this is being printed. If it is, then there is a issue with client.run() maybe wrong token etc. if it's not, then the issue is somewhere above the print statement.

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 Toastlover