Discord Bot Python missing positional argument token

Question:

I’m a beginner python programmer trying to get my bot online, but I can’t solve one error I keep getting. In tutorials, people usually run something like

client.run('TOKEN') 

in the end, whereas TOKEN is the discord bot token. Pycharm doesn’t recognize the token and gives the following error:

TypeError: Client.run() missing 1 required positional argument: ‘token’

I tried typing

client.run(token='TOKEN')

but I’m afraid this is not the solution because then Pycharm tells me that the positional argument ‘self’ is missing.
I’m very new to this, so any help would be appreciated.

Here’s the full code:

import discord

class MyClient(discord.Client):
    async def on_ready(self):
        print("print Befehl test")

client = MyClient
client.run(token='TOKEN')
Asked By: Sakurairo Fuyu

||

Answers:

The issue is that you’re not instantiating MyClass. client is just a reference to the class MyClass itself. So, when you do client.run(), it is trying to run the function as a static method.

To fix this, just add parentheses after MyClient. Try this instead:

import discord

class MyClient(discord.Client):
    async def on_ready(self):
        print("print Befehl test")

client = MyClient()
client.run(token='TOKEN')
Answered By: Michael M.

client should be MyClient(), you have to actually instantiate it. Just add the parentheses.

import discord

class MyClient(discord.Client):
    async def on_ready(self):
        print("print Befehl test")

client = MyClient()
client.run(token='TOKEN')

instead of just MyClient.

Answered By: BVB44

This solved my problem:

import discord
    
    class MyClient(discord.Client):
        async def on_ready(self):
            print("print Befehl test")
    
    client = MyClient(intents=discord.Intents.all())
    client.run(token='TOKEN')
Answered By: Sakurairo Fuyu