#๐ error while making discord bot
53 messages ยท Page 1 of 1 (latest)
@twilit lintel
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.
you're probably looking to inherit from discord.Client (note the capital letter)
OMG UR A LIFE SAVOR
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
!intents
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.
so i jus import intents and commands??
did you even read that
ok let me read
๐
yeah
in what
i jus wanaa make a bot that counts specific words
yeah yt tutorials become outdated very quickly
and then tells how many of that said word has a specific user said
thats why you should read documentation
i hate reading
you aint getting no where in programming if you dont like reading
so you want the bot to count how many times any user has said a specific word?
yes
also where do i learn all this
i dont jus wana copy paste code uk
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
okhka i will read this but but but i can keep this runnin on oracle right?
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
whats cogs also where do i learn sql now ๐ญ
you can learn sql from anywhere, or you can search basics of sqlite or smt and learn from there
and cogs are a way of organizing your code into different parts over multiple files (optional but recommended)
A hands-on guide to Discord.py
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.