r/learnpython • u/dragonlord9631 • 1d ago
How to get discord messages into python?
Im not attempting to make a bot per say, i just want to see if i can get a discord message, and then do something with it.
So far, python hasnt recognized "discord" as a valid package to import.
Then again, i am coding on a phone, maybe thats the problem.
But first, i want to see about receiving a discord message into python, so i can write it to a file, and then i can do stuff with it.
Any help would be appreciated!
3
2
3
u/dev-razorblade23 1d ago
Discord is not really a package in python. And to interact with Discord, you kinda need the to use their API which is intended for bots.
I would take a look at discord.py library (installation depends on the platform you are coding on)
https://discordpy.readthedocs.io/en/stable/
2
u/PureWasian 1d ago
Option 1) discord.py: https://discordpy.readthedocs.io/en/stable/intro.html but that's a convenience wrapper for setting up a bot as a listener to whatever server channel you are listening for messages in. You'd install the library following the steps in above link and also look at the Working with Discord links from their home page: https://discordpy.readthedocs.io/en/stable/index.html
Option 2) Use the Discord API directly. Ideally you read through that and also understand basic Rest APIs, OAuth2, and read through the GET Channel Messages section of their documentation at a bare minimum to get the idea and know what data shape you're working with.
1
u/dragonlord9631 1d ago
Thank you for the links, i will check it out
1
u/PureWasian 1d ago
Both options are a bitch and a half in terms of setup complexity if you're new to Python/APIs/Discord Bots and programming more generally, best of luck.
Don't expect it to be a quick adventure to get working your first time around messing with it.
1
u/dragonlord9631 1d ago
Hmmm. Ill probably just return to the project every once in a while, hopefully i can get it working before i forget completely😅
0
u/kyle2143 1d ago
Easiest way is to install whatever the most popular library is for discord. There's probably a million people who have wanted to do this, so someone has definitely made a simple wrapper library for it.
-1
u/dragonlord9631 1d ago
Ill look into that, thank you
0
u/BrilliantEmotion4461 1d ago
why not use forbidden tech? AI can teach you how. I have the entire process and script right here.
1
u/dragonlord9631 1d ago
No. I prefer to code myself, and i trust the redditors suggestions much more than AI
0
u/BrilliantEmotion4461 1d ago
I have it teach me. And lol. Trauting redditors more than Fable. Cute.
6
u/socal_nerdtastic 1d ago
Python does not come with a
discordpackage. You have to install one first. How to install modules will depend on what coding platform you are using on your phone.