#๐Ÿ”’ error while making discord bot

53 messages ยท Page 1 of 1 (latest)

twilit lintel
#

So i was making a discord bot and got this error idk how to fix it pls help

class client(discord.client): async def on_ready(self): print('Logged on as', self.user) TypeError: module() takes at most 2 arguments (3 given)

unkempt joltBOT
#

@twilit lintel

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

devout torrent
#

you're probably looking to inherit from discord.Client (note the capital letter)

twilit lintel
#

IT SOMEHOW WORKED

#

now im gettin random errors

#

wow

#

Traceback (most recent call last):
File "c:\Users\Naman\Desktop\dc bot\main.py", line 12, in <module>
client.run('token')
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Naman\AppData\Local\Programs\Python\Python313\Lib\site-packages\discord\client.py", line 906, in run
asyncio.run(runner())
~~~~~~~~~~~^^^^^^^^^^
File "C:\Users\Naman\AppData\Local\Programs\Python\Python313\Lib\asyncio\runners.py", line 195, in run
return runner.run(main)
~~~~~~~~~~^^^^^^
File "C:\Users\Naman\AppData\Local\Programs\Python\Python313\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "C:\Users\Naman\AppData\Local\Programs\Python\Python313\Lib\asyncio\base_events.py", line 725, in run_until_complete
return future.result()
~~~~~~~~~~~~~^^
File "C:\Users\Naman\AppData\Local\Programs\Python\Python313\Lib\site-packages\discord\client.py", line 895, in runner
await self.start(token, reconnect=reconnect)
File "C:\Users\Naman\AppData\Local\Programs\Python\Python313\Lib\site-packages\discord\client.py", line 824, in start
await self.connect(reconnect=reconnect)
File "C:\Users\Naman\AppData\Local\Programs\Python\Python313\Lib\site-packages\discord\client.py", line 748, in connect
raise PrivilegedIntentsRequired(exc.shard_id) from None
discord.errors.PrivilegedIntentsRequired: Shard ID None is requesting privileged intents that have not been explicitly enabled in the developer portal. It is recommended to go to https://discord.com/developers/applications/ and explicitly enable the privileged intents within your application's page. If this is not possible, then consider disabling the privileged intents instead.

#

im gettin this now

unkempt joltBOT
#
Using intents in discord.py

Intents are a feature of Discord that tells the gateway exactly which events to send your bot. Various features of discord.py rely on having particular intents enabled, further detailed in its documentation. Since discord.py v2.0.0, it has become mandatory for developers to explicitly define the values of these intents in their code.

There are standard and privileged intents. To use privileged intents like Presences, Server Members, and Message Content, you have to first enable them in the Discord Developer Portal. In there, go to the Bot page of your application, scroll down to the Privileged Gateway Intents section, and enable the privileged intents that you need. Standard intents can be used without any changes in the developer portal.

Afterwards in your code, you need to set the intents you want to connect with in the bot's constructor using the intents keyword argument, like this:

from discord import Intents
from discord.ext import commands

# Enable all standard intents and message content
# (prefix commands generally require message content)
intents = Intents.default()
intents.message_content = True

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

For more info about using intents, see discord.py's related guide, and for general information about them, see the Discord developer documentation on intents.

twilit lintel
upbeat kettle
#

did you even read that

twilit lintel
upbeat kettle
#

๐Ÿ’€

twilit lintel
#

ohkk

#

so i have to enable it form

#

the dev portal

upbeat kettle
#

yeah

twilit lintel
#

can you help me tho

#

yt tutorials are outdated

upbeat kettle
twilit lintel
#

i jus wanaa make a bot that counts specific words

upbeat kettle
twilit lintel
#

and then tells how many of that said word has a specific user said

upbeat kettle
#

thats why you should read documentation

twilit lintel
upbeat kettle
#

you aint getting no where in programming if you dont like reading

twilit lintel
#

uuuf

#

okay

#

so

#

where do i start

upbeat kettle
twilit lintel
#

also where do i learn all this

#

i dont jus wana copy paste code uk

upbeat kettle
# twilit lintel yes

youll have to make use of the on_message event of the bot and use a database to store the data, if you wanna use a local DB you can look at aiosqlite async wrapper of sqlite, you'll have to learn some basic SQL commands too.

You can look at discord.py documentation for reference: https://discordpy.readthedocs.io/en/stable/
Additionally theres an updated guide with examples and explaination on pretty much every aspect of the dpy lib: https://fallendeity.github.io/discord.py-masterclass/

A hands-on guide to Discord.py

twilit lintel
upbeat kettle
#

oracle servers?

#

yeah you can

twilit lintel
#

ohkk

#

tysmm

upbeat kettle
#

i dont think the guide has examples on events, so ill show you

You can use listeners to watch for specific events, one of them is on_message which gets executed when a message is sent in any server where the bot is present in.

If you're not using cogs-

from discord import Message

word = "hello"

@bot.listen("on_message")
async def message_listener(message: Message) -> None:
  if message.author.bot:
    # Check if the message is sent by a bot & ignore it
    return
  
  if word in message.content.lower().replace(" ", ""):
    # Do database handling stuff
twilit lintel
upbeat kettle
#

and cogs are a way of organizing your code into different parts over multiple files (optional but recommended)

twilit lintel
#

ohk

#

i wont do cogs for now

#

like

#

for this bot

unkempt joltBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.