#๐Ÿ”’ Discord Bot Help

119 messages ยท Page 1 of 1 (latest)

wooden scroll
#

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.

trail moonBOT
#

@wooden scroll

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.

rain widget
wooden scroll
#

djfsogfn

#

heres the text

#

oh you righjt

wooden scroll
#

would i jus do ,class Client(gacha_card):

lament steeple
#

why are you declaring the intents twice?

wooden scroll
#

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

lament steeple
#

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

wooden scroll
#

ooo okok should i change the bot to client

#

do they work interchangeably?

lament steeple
lament steeple
#

as the post suggests just use bot

wooden scroll
#

okay cool

lament steeple
#

you don't have to set the intents twice, use it only once andd use it for the bot subclass

wooden scroll
#

so put it in the bot subclass, not above it?

lament steeple
#

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

wooden scroll
#

ooooo okok thank you!

#

i will check it out

lament steeple
#

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

wooden scroll
#

okok so @bot.event is neede i was getting mixed signals from peopel LOL

lament steeple
#

You don't necessarly need it

wooden scroll
#

okok will it work the same if i do bot.event vs the subclass?

lament steeple
#

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

wooden scroll
#

okok so separate on ready?

#

sorry i was looking at the example

lament steeple
#

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")

wooden scroll
#

this would be before i add any commands and after the imports?

lament steeple
#

yes

#

you need to create your bot instance first before everything

wooden scroll
#

okokok and before the intents as well

lament steeple
lament steeple
#

then you can call your_bot.run(discord_token_here

wooden scroll
#

okok i have it at the bottom i just didnt put it in the ss

lament steeple
#

Are you hardcoding your token?

#

Is it literally the token string?

wooden scroll
#

possibly...., i know there is a way to do it but i couldn't figure it out at the time

lament steeple
#

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

lament steeple
wooden scroll
#

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

lament steeple
#

I see

#

Its pretty straight forward, you should manage to get it working really easy

wooden scroll
#

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

lament steeple
#

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

wooden scroll
#

okok the thing i was looking at had me start w .env and my terminal was freaking out LOL

#

okok

wooden scroll
lament steeple
#

show the output

wooden scroll
#

`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")`

lament steeple
#

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

wooden scroll
#

OHHH yes yes

#

i forgot to delete it

lament steeple
#

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

wooden scroll
#

and after adding this into it i can now remove the
`intents = discord.Intents.default()

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

lament steeple
#

yes, you move the intents part to a function

#

and use it inside of the bot subclass

wooden scroll
#

also the bot is reported saying that it is undefined

lament steeple
#

How are you importing bot?

#

from discord.ext.commands import Bot

#

should look like this

wooden scroll
#

this part?

#

hmm okok

#

i see now

wooden scroll
#

okay

#

now the commands dont work

lament steeple
#

It should stop giving the warn

#

Did you run the bot?

wooden scroll
#

yes doing so now

lament steeple
#

It probably won't work until you do the necessary mods

#

i pointed out its recommended to use Cogs to use the commands

wooden scroll
#

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

lament steeple
#

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

wooden scroll
#

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

lament steeple
#

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

wooden scroll
#

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

lament steeple
#

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

wooden scroll
#

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

lament steeple
#

Alright

#

Follow the lib examples

wooden scroll
#

thank you so much!!! i appreciate the help

#

!close

trail moonBOT
#
Python help channel closed with !close

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.