Hello!! I wrote a code for a simple drop and pull command and for some reason no matter how i change it it wont communicate to the server, the other two events work, the call and response and the message reaction, but none of the other commands work within the server.
#๐ Discord Bot Help
119 messages ยท Page 1 of 1 (latest)
@wooden scroll
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.
Closes after a period of inactivity, or when you send !close.
i dont know anything about discord bots nowadays but why not make a GachaCard class ? 
oooo okok
would i jus do ,class Client(gacha_card):
why are you declaring the intents twice?
one of my comp sci friends said that i needed it
im not entirely sure i was wondering why it was needed too
but it doesnt work without it either
intents lets discord knows which data your bot should receive, you will need to enable them in the developer portal too
also don't use client and bot at the same time
use only one
okok real yeah
as the post suggests just use bot
okay cool
you don't have to set the intents twice, use it only once andd use it for the bot subclass
so put it in the bot subclass, not above it?
yeah, something like:
class YourBot(Bot)
define a function inside your bot that sets the intent and invoke it inside the constructor
or you can pass the intents object as a parameter too, both are great
dpy has examples in their docs on how to build a basic bot, you should check it out
Note: it is recommended to subclass the Bot and split your commands into Cogs
and not put them in a simple file, but this overall examples shows you the basics of dpy
okok so @bot.event is neede i was getting mixed signals from peopel LOL
You don't necessarly need it
okok will it work the same if i do bot.event vs the subclass?
Yes, also dont setup anything on ready
as its called multiple times in dpy
when you subclass bot
you can override setup_hook
which is made specifically for that
The general implemention would look something like this
class YourBot(Bot):
def __init__(self) -> None:
intents = self._define_intents() # This will return an intent object, or you can just pass it on the constructor
super().__init__(prefix="!", intents=intents)
async def setup_hook(self):
print("connected")
this would be before i add any commands and after the imports?
okokok and before the intents as well
take a look at Cogs on how to make your commands organized too:
https://discordpy.readthedocs.io/en/stable/ext/commands/cogs.html
The intents will be created when you instanciate your bot object in the code i provided above
then you can call your_bot.run(discord_token_here
YES yes i was looking at that on the dpy website
okok i have it at the bottom i just didnt put it in the ss
possibly...., i know there is a way to do it but i couldn't figure it out at the time
Its generally not recommended to do that for security reasons, but if you are not going to post it anywhere (e.g github) it doesn't matter
env to hide application secrets fits here
i know i know and just having it out and working on it isnt. agood idea, i planned to do the env thing
YEAH i tried it early on while getting started and i couldnt get it to work
I see
Its pretty straight forward, you should manage to get it working really easy
is it within my terminal or inside the file
i tried in both but that was also super early on before i got the bot even working
yeah, you can create the file within the terminal
but you can also create the file by hand in your workspace
just create a file ending in .env
and install python-dotenv to acess the contents of the file
okok the thing i was looking at had me start w .env and my terminal was freaking out LOL
okok
okok so i did this part and a bunch of errors cam eup
show the output
`class YourBot(Bot):
def init(self) -> None:
intents = self._define_intents() # This will return an intent object, or you can just pass it on the constructor
super().__init__(prefix="!", intents=intents)
async def setup_hook(self):
print("connected")`
The_define_intents function is something i recommended you doing, but you need to set it up yourself to return an Intent object
its not implemented
i dont think the setup_hook is idented also
Also the Bot type in the parenthesis has a warn in there, you should investigate why
probably related to import issues
and after adding this into it i can now remove the
`intents = discord.Intents.default()
bot = commands.bot(command_prefix="!", intents=intents)`
yes, you move the intents part to a function
and use it inside of the bot subclass
also the bot is reported saying that it is undefined
How are you importing bot?
from discord.ext.commands import Bot
should look like this
add that again
okay
now the commands dont work
yes doing so now
It probably won't work until you do the necessary mods
i pointed out its recommended to use Cogs to use the commands
file "/Users/kanekrajecki/python/fling.py", line 20, in <module> bot = commands.bot(command_prefix="!", intents=intents) TypeError: 'module' object is not callable
okok
yes sorry im doing so now
i was focused on the subclass
You're trying to call a module as a method
If you have little to no experience with python itself, discord bots are too advanced for a beginners to tackle
ahh, yeah, I can see that. I think I can get a handle on it over time, though; if I just do my research, I should be fine. I want to try to get these simple events down and go from there. I am aware they aren't simple for a beginner but besides a few parts I understand generally what they all do
I see, okay then, you should have a good understanding of OOP as dpy messes around with it a lot
Knowing that will make it 10x easier
this is true imma gonna do a deeper dive into dpy bcz this is the only coding project i plan to do
also learning through errors and just figuring it out is fun to me LMAO
Try deep diving into OOP first, trust me it will be way easier to undertand dpy when you know classes and objects
Just a suggestion, you can do as you want
okok got it and yeah basic understanding of python before like huge events
but first imma look up how to AT LEAST get these codes to work, imma close this for rn im too deep in to give up now
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.