#discord-bots

1 messages · Page 628 of 1

slate swan
#

do you mean you want to know how many guilds your bot has joined?

cedar stream
#

Are u in pycharm?

abstract kindle
#

Yes

slate swan
#

len(bot.guilds)

abstract kindle
#

pls dont tell me to change from pycharm

cedar stream
cedar stream
abstract kindle
#

event is not being triggered.. also how do i attach debugger, i was curious about that earlier!

abstract kindle
#

yeah fr. im gonna try this debugger thing first tho

cedar stream
abstract kindle
#

any chance you could send some general code for the wait_for ?

#

I click it and then what.. what is a breakpoint? is that the red circle on the side

cedar stream
abstract kindle
#

That's fine

abstract kindle
#

Yeah i know it's in docs but it's confusing sometimes

slate swan
quick gust
#

pretty starightforward

cedar stream
abstract kindle
#

uh ok i set the breakpoint and now nothin is happening even though im running the command

#

what is lambda?

slate swan
#

a function that doesn't have a name

cedar stream
slate swan
#

basically a temporary function

abstract kindle
#

does check have to be a function?

slate swan
cedar stream
abstract kindle
#

I did?

cedar stream
#

I wanna see where u put it

abstract kindle
#

Lol I feel like such a noob

cedar stream
#

Put it one line under

abstract kindle
#

Will this debug the code from there on?

sullen shoal
#

it wont debug, thats your job

cedar stream
#

No, this will stop the code there for you to manually go through it and debug it

#

U move through it using F8

sullen shoal
#

you may change values of some variables, do stuff like running functions and then press c and hit enter to continue

#

or exit() will stop

abstract kindle
#

Okay cool I used the word debug wrong

tawny arrow
#

i'm scraping urban dictionary

here's my code :

query=input("Enter A Word : ")
data=requests.post(f"https://urbandictionary.com/define.php?term={query}").content
soup=BeautifulSoup(data,"html.parser")
for i in soup.find_all("div",class_="meaning"):
   print(i)
and i'm getting :
<div class="meaning">A person who writes <a class="autolink" href="/define.php?term=funny" onclick="ga('send', 'event', 'Autolink', 'Click', &quot;funny&quot;);">funny</a> and motivational <a class="autolink" href="/define.php?term=posts" onclick="ga('send', 'event', 'Autolink', 'Click', &quot;posts&quot;);">posts</a> on <a class="autolink" href="/define.php?term=Facebook" onclick="ga('send', 'event', 'Autolink', 'Click', &quot;Facebook&quot;);">Facebook</a></div>

how to get inner html of div and anchor tags?

sullen shoal
#

i use a different lib so idk

#

but i have a unfinished project of it, i can give you want

#

oh wait

cedar stream
slate swan
sullen shoal
#

actually mine works fine, that was a different project

tawny arrow
abstract kindle
#

Debugger gets to the async def on_raw_reaction_add(payload) line

cedar stream
#

Press F8

abstract kindle
#

Yeah then it stopped

cedar stream
#

Press F8 again

abstract kindle
#

Like the debugger stopped going and the screen at the bottom lost all the variables in it

#

It completely ended but I can try again

cedar stream
#

Where did that happen

slate swan
#

Guys does anyone know easy way to pass flags in command. i want to do something like this: b!search car --doorcolor black

slate swan
#

read its docs

#

plenty of tutorials out there

abstract kindle
#

At the async def on_raw_reaction_add(payload) line...

cedar stream
slate swan
#

Step 3: if you have a really specific problem that you can't find the solution of anywhere, only then should you ask for help

cedar stream
abstract kindle
#

Could it possibly be the decorator ive got in there?

cedar stream
slate swan
abstract kindle
#

okay fuck this on reaction add shit. lets try wait for

sullen shoal
#

isnt reaction add an event and wait_for waits an event

slate swan
sullen shoal
sullen shoal
#

what does it do

cedar stream
#

And download sources

cedar stream
velvet tinsel
#

morning everyone

cedar stream
#

Gm

sullen shoal
#

morning

abstract kindle
#

So how would I get the (user) parameter if I'm in the DM channel?

velvet tinsel
#

are we doing wait_for()? brilliant.

velvet tinsel
#

elaborate

slate swan
#

lol

abstract kindle
#

Fuck ima go kill myself brb

velvet tinsel
#

and you cant get anything

velvet tinsel
#

through DM channels

abstract kindle
#

FUCK man I AM reading it

velvet tinsel
abstract kindle
#

Lol!

#

YES HE IS!!!!!!!!!!!!!

velvet tinsel
#

Ok chill

slate swan
#

everything is documented

cedar stream
abstract kindle
#

Because this shit like the word coroutine makes little sense to me

velvet tinsel
#

wait_for() <<<<<<<<<<<< READ THE DOCS

abstract kindle
#

Bro do you know how many tabs of the docs I got open???

slate swan
sullen shoal
velvet tinsel
#

🤣

abstract kindle
#

I'm still learning, and sometimes YOU guys can simplify and explain this shit the easiest!!!

cedar stream
velvet tinsel
abstract kindle
#

And then if i don't understand something, I can continue to ask questions and possibly understand it further

#

THEN WHAT is this DISCORD server for?!?!?!?!!?!

velvet tinsel
sullen shoal
#

for the dumb people to help them until they are independent

abstract kindle
#

Man I've learned a LOT from asking questions in here. I've read docs, and when I come across something that confuses me, I ask in here

cedar stream
#

Honestly I just wanna give him the snippet at this point

velvet tinsel
slate swan
abstract kindle
#

Sorry I'm not god at coding rn, I started like a week ago

velvet tinsel
#

then why are you learning dpy

#

😆

abstract kindle
#

Hahaha

slate swan
abstract kindle
#

I'm farther into it than you thinK

velvet tinsel
#

get the basics covered first

velvet tinsel
#

what is async?

slate swan
cedar stream
velvet tinsel
abstract kindle
#

Dictionaries are places to store things with keys

#

like a list but more advanced

velvet tinsel
slate swan
#

💀

abstract kindle
#

fuck man let me go take a class on it rq

velvet tinsel
#

funny

cedar stream
abstract kindle
#

I'm just learning this in my spare time, that's why it's hard to remember what everything is called

sullen shoal
velvet tinsel
#

you need to learn tuples, arrays, variable, asyncio, functions....

slate swan
velvet tinsel
#

Class ofc

#

classes are epic

abstract kindle
#

I would believe a class variable is when you define it and an instance would be the unique variable that is created whenever you create an instance of that class

velvet tinsel
#

I dont use them much *cough *

abstract kindle
#

is that right?

cedar stream
#

Also learn about abstract classes and design patterns

slate swan
abstract kindle
#

fuck man i knew i should have said attribute

cedar stream
#

🤦🏼‍♂️

abstract kindle
#

but if i did and it was wrong i figured you'd have the same reaction

velvet tinsel
#

🤦‍♂️

sullen shoal
velvet tinsel
#

just learn basic python

abstract kindle
#

Ok bye. I wont come back here until I've mastered it. Just means this project that has been a lot of fun for me will have to wait a long time

frozen plaza
#

hello

dark pawn
#

im trying to store a really long multi-nested dictionary into the db in replit but its giving me 'circular reference detected'. anyone know what that is

sullen shoal
#
class Beginner:
  IQ = 0

kazido = Beginner()```
here `kazido` is an instance of `Beginner`
frozen plaza
#

i built a discord both with over 250 commands? is that a big thing?

abstract kindle
#

Why do you guys have to be so mean

abstract kindle
#

I'm just asking questions so i can understand what I don't better

velvet tinsel
sullen shoal
#

im explaining

cedar stream
#

😭

abstract kindle
#

You're being very mean while trying to "help" me

slate swan
abstract kindle
#

???????

slate swan
manic wing
maiden fable
velvet tinsel
manic wing
#

now you need to learn python -_-

frozen plaza
abstract kindle
sullen shoal
maiden fable
velvet tinsel
#

damn

sullen shoal
manic wing
abstract kindle
#

This ain't even all my tabs. I've been reading docs all day bro

maiden fable
slate swan
#

I put __init__ even when I don't need it just because it looks nice

velvet tinsel
#

My book was lying to me all this time

velvet tinsel
maiden fable
#

<@&831776746206265384>

abstract kindle
#

THANK YOU HOLY FUCK!

manic wing
abstract kindle
#

My frustration

slate swan
#

!mute 584662127470575616 Investigating.

unkempt canyonBOT
#

:x: The user doesn't appear to be on the server.

cedar stream
maiden fable
#

Thanks!

velvet tinsel
#

but you need it

slate swan
velvet tinsel
#

I should try that sometimes

cedar stream
abstract kindle
#

Ofc they ignore it tho because they are already engineers

slate swan
sullen shoal
velvet tinsel
abstract kindle
#

No, you ignore what that guy just said

sullen shoal
#

like declaring attributes

manic wing
velvet tinsel
#

I refer to it when I need it

abstract kindle
#

This here

slate swan
sullen shoal
#

oh lol

velvet tinsel
cedar stream
velvet tinsel
manic wing
#

ok i hate to be this guy but

abstract kindle
#

@velvet tinsel You ignore this

manic wing
#

!ot

unkempt canyonBOT
sullen shoal
#

oh yeah i had to reread the conversation

outer violet
#

would this be right embed.add_field(name='Creation Date', value=int(guild.created_at.timestamp(f"%a, %#d %B %Y @ %H:%M:%S %p (<t:1601130860:R>)"))? im just trying to make it show when the bot joined each server cuz its in multiple servers and obviously those would be different dates and not just a year ago and idk how to do that

velvet tinsel
abstract kindle
#

No, you said "I don't ignore the docs"

velvet tinsel
slate swan
#

the docs are the class lol

abstract kindle
#

See? You don't actually care that what he brought up was valid and so you just make a "funny" comment

#

It's very helpful for ME at least to come in here and ask questions when I can't 100% understand what is happening when I look at the docs or watch videos on what I'm trying to do

cedar stream
slate swan
slate swan
#

any one have code for help command bot ?

manic wing
#

please can you go to an off-topic

slate swan
#

Id prefer to help/ignore instead of checking someone's knowledge , just saying

velvet tinsel
sullen shoal
outer violet
velvet tinsel
#

we're not gonna spoonfeed you any code

abstract kindle
#

I'm NOT ASKING YOU TO

cedar stream
slate swan
velvet tinsel
#

trying to be spoonfed but we're not going down there

abstract kindle
#

I'm 18 and college is stressing me out and I just wanna learn some code to have fun

abstract kindle
#

I don't have all the time in the world to learn python aside everything else that is going on. Which is why I come here to ask questions. And half of you act so high and mighty cause you already know everything there is to know

slate swan
#

anyways

abstract kindle
#

God I'm tilted now.

manic wing
#

!ot before kazido lets out everything

unkempt canyonBOT
dark pawn
#

its alright homotrollius has a small pp

abstract kindle
#

Nah, I'm going to a help channel. Shoulda done this a long time ago XD

slate swan
#

💪

abstract kindle
#

My dick is 8 inches hard

dark pawn
#

if u dont have to use lube u aint doing it right

cedar stream
#

Okay yall can chill a bit

slate swan
#

ok we are going in a wrong direction now

blissful lagoon
#

!shh

unkempt canyonBOT
#

✅ silenced current channel for 4 minute(s).

blissful lagoon
#

Some reminders:
Insulting anyone is not ok, especially for being a beginner.
You are free not to answer any questions you don't want to; no one is forcing you to respond.
The topic here is discord bots. Keep your comments on-topic and appropriate.
If you have a problem with another user, contact the moderators. You can always open a @novel apex.

#

!unshh

unkempt canyonBOT
#

✅ unsilenced current channel.

slate swan
#

problem ?

boreal ravine
slate swan
#

you defined the var bot for your Bot object

slate swan
#

tnx

abstract kindle
#

I'm out of here

slate swan
#

how i can create command for my bot

#

kazido , could you mention me in the help channel you occupied , if any

slate swan
unkempt canyonBOT
#

@command(*args, **kwargs)```
A shortcut decorator that invokes [`command()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.command "discord.ext.commands.command") and adds it to the internal command list via [`add_command()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.GroupMixin.add_command "discord.ext.commands.GroupMixin.add_command").
slate swan
#

basically py @bot.command() , with an async function with ctx as its first parameter

cedar stream
sullen shoal
#

where ctx is commands.Context

slate swan
#

yea , was about to say that
thanks

maiden fable
unkempt canyonBOT
#

An aware datetime object that specifies the date and time in UTC that the member joined the guild. If the member left and rejoined the guild, this will be the latest date. In certain cases, this can be None.

sick talon
#

hello, i am trying to show the data which i fetch from an api in the form of pages
pithink could anybody help me out ?

#

i know how to make pages(paginators) manually

manic wing
#

this is a pretty decent paginator if I do say so myself...

#

not amazing, but good at a lowish level

#

looking back on it now, i see a bunch of errors

#

but it works

#

you just have to replace the emojis

#

from core.utils.utils import thecolor from core.utils.emojis import LOCATIONemojis as l
these

velvet tinsel
#

I’m back

#

I think my WiFi sucks

#

Nothings loading

#

Has it just been empty after Caeden sent his paginator?

boreal ravine
#

ur wifi sucks

slate swan
#

?

boreal ravine
#

im not gonna deal with this today

quick gust
#

nvm, why have u indented the function?

#

please go learn python first

#

it literally says what u did wrong in the error

slate swan
#

+that's supposed to be inside a cog file ...

#

...............

spring flax
# slate swan

You would do @commands.command in a cog only, not for your main file

#

In a main file assuming your bot instance is bot, you would use the @bot.command() decorater

#

So remove the class SomeCommands... and remove where you do def setup(bot)....

velvet tinsel
#

I can’t tell the difference between dynou and diabolical

#

The pfp looks similar

spring flax
#

so what would remain is the @bot.event part where you are doing on_ready and change the @commands.command() decorator for your ping command to @bot.command(). And remove self from the arguments for the command since it's not a cog @slate swan

#
@bot.event
async def on_ready():
  #something

@bot.command()
async def ping(ctx):
  await ctx.send(f"Pong! {round(bot.latency) *1000}ms")
quick gust
#

👍🏼

spring flax
# quick gust 👍🏼

yeah and also in case you didn't know, the !resources command has useful documentations for beginners

velvet tinsel
#

Just watching this all happen

#

I don’t even bother about indent errors

quick gust
spring flax
#

uhmm yeah the !resources command has some of the documentations on basic python and it's better to guide a beginner there instead of saying "go learn basic python first" or whatever (i'm just saying, not trying to start anything here)

quick gust
#

yeah that's my bad

slate swan
#

Infernum is noob dev

velvet tinsel
#

Infernum is sad

spring flax
#

there's honestly no need for that

velvet tinsel
slate swan
#

import os

velvet tinsel
#

Don’t be mean to him.

slate swan
#
@bot.group()
async def buy(ctx):
    await ctx.send('Provide A Valid Item Name')

@buy.command()
async def bluticket(ctx):
    conn = sqlite3.connect('test.sql')
    c = conn.cursor()
    amount = 150
    player = ctx.author
    c.execute(f"UPDATE data SET balance = balance-{amount} WHERE ID = {player.id}")
    conn.commit()
    conn.close()
    await ctx.send('Item Purchased Successfully')

when i use !buy bluticket it says "item purchased succesffully" but also "provide a valid item name"

velvet tinsel
slate swan
quick gust
#

lets not do this? i feel like I already said that was my mistake?

velvet tinsel
#

Yes

#

Let’s not do this

cedar stream
#

2 conflicts in 1 day

velvet tinsel
#

Or this will turn into a battleground

tawdry perch
#

You gotta be kidding me, is here still a some sort of fight ;-;

velvet tinsel
#

I forgor

cedar stream
#

LMFAOOO lets talk about fav flowers or something

velvet tinsel
velvet tinsel
tawdry perch
#

good

slate swan
velvet tinsel
#

🤷‍♂️

cedar stream
velvet tinsel
tawdry perch
#

Any ideas to make for me bot?

slate swan
# velvet tinsel What’s a bot.group?

basically @bot.group means like
anythin defined in bot.group is a group command means it can also have args
thats why in the command of bluticket it has @buy.command not @bot or client.command

cedar stream
tawdry perch
#

I think I alrd have that or smth similar

spring flax
slate swan
#

its just its sending the output of bot.group as well as buy command

spring flax
#

Also, don't connect to your database on each command. Keep a connection throughout your bot.

velvet tinsel
cedar stream
slate swan
#

its now sending 1 output when 1 command i used

spring flax
spring flax
slate swan
cedar stream
velvet tinsel
slate swan
#

any education is useful in future

velvet tinsel
#

I’ll do background work

slate swan
#

amogus

cedar stream
velvet tinsel
#

It’s what I do when I don’t know tf what’s happening

slate swan
sage otter
# spring flax https://discord.com/channels/267624335836053506/343944376055103488/7413681041515...

This is true. However there’s a limit, you cannot just come into this server or rather this chat with 0 to No python or programming knowledge at all and expect for everything to go well. Especially the people who come in here with that lack of knowledge and expect spoonfeeding. Us just giving them code will not help them at all but more so hurt them by confusing them if they don’t know what anything does. Even the maintainer of discord.py Danny expects people who use his library to have an intermediate understanding of python and object oriented programming. The limit I mentioned earlier correlated with what I just said. However, if you come in here willing to learn and understand what we tell you then you will be fine and more likely to be helped than people who just want a discord bot and want people to write code for them without them even wanting to understand or learn anything.

spring flax
# slate swan yes

cool do you know how to make a connection throughout your bot to the DB?

slate swan
#

amogus

cedar stream
slate swan
#

amogus

cedar stream
unkempt canyonBOT
#

@slate swan Per Rule 6, your invite link has been removed. If you believe this was a mistake, please let staff know!

Our server rules can be found here: https://pythondiscord.com/pages/rules

tawdry perch
#

lol

slate swan
slate swan
cedar stream
slate swan
#

thanks for help guys

cedar stream
#

Np

spring flax
slate swan
cedar stream
spring flax
#

the second line

cedar stream
spring flax
#

!indents @slate swan reading this would be useful too!

unkempt canyonBOT
#

Indentation

Indentation is leading whitespace (spaces and tabs) at the beginning of a line of code. In the case of Python, they are used to determine the grouping of statements.

Spaces should be preferred over tabs. To be clear, this is in reference to the character itself, not the keys on a keyboard. Your editor/IDE should be configured to insert spaces when the TAB key is pressed. The amount of spaces should be a multiple of 4, except optionally in the case of continuation lines.

Example

def foo():
    bar = 'baz'  # indented one level
    if bar == 'baz':
        print('ham')  # indented two levels
    return bar  # indented one level

The first line is not indented. The next two lines are indented to be inside of the function definition. They will only run when the function is called. The fourth line is indented to be inside the if statement, and will only run if the if statement evaluates to True. The fifth and last line is like the 2nd and 3rd and will always run when the function is called. It effectively closes the if statement above as no more lines can be inside the if statement below that line.

Indentation is used after:
1. Compound statements (eg. if, while, for, try, with, def, class, and their counterparts)
2. Continuation lines

More Info
1. Indentation style guide
2. Tabs or Spaces?
3. Official docs on indentation

spring flax
slate swan
cedar stream
slate swan
#

oh wait its replit

cedar stream
#

lmao

spring flax
cedar stream
slate swan
#

best discord py toturial

spring flax
#

you can use that too, there are more than one ways to do it

slate swan
#

?

cedar stream
cedar stream
slate swan
spring flax
#

!d docs

arctic python
# sage otter This is true. However there’s a limit, you cannot just come into this server or ...

You're correct, but it's also important how you broach the topic of someone not having enough foundational Python knowledge. Just saying "go learn basic Python" is dismissive and doesn't really communicate very well what the person in question is lacking. You can phrase it in a nicer way and provide the resources they need to get up to the level they need. And if someone is not listening despite this, it's important not to lose your patience and become abusive through frustration. You can always step away or message @novel apex and ask staff to step in if the person is being disruptive.

slate swan
#

some from tutorial

spring flax
#

Hey dementati

cedar stream
#

That is docs on how to document ur code 😂

slate swan
#

discord py toturial just

#

:l

#

?

cedar stream
#

Dpy docs are best docs out there

arctic python
spring flax
#

Question dementati: Do you know databases with dpy?

arctic python
#

I know databases and I know dpy, to some extent.

spring flax
#
bot.db = bot.loop.run_until_complete(aiosqlite.connect("the_db_name"))
``` is this a okay way to keep  a connection to a DB?
slate swan
#

i tried doing that , it can often be a recurring

cedar stream
slate swan
#

since you use aiosqlite , you may use the async with connect() method

velvet tinsel
#

Hello

velvet tinsel
#

Someone tried to convert me into Christianity

cedar stream
# spring flax yes ofc

So you will only be limited to sql databases, or even to this specific database, right?

unkempt canyonBOT
velvet tinsel
#

What’s happening here

sullen shoal
#

discussion about discord bots basically

cedar stream
velvet tinsel
spring flax
#

alright thanks

slate swan
unkempt canyonBOT
#

saving_data/sqlite3_usage.py lines 38 to 46

async def create_database():
    async with aiosqlite.connect('animals.db') as connection:
        async with connection.cursor() as cursor:
            await cursor.execute(
                '''
                CREATE TABLE IF NOT EXISTS animals
                ( user TEXT , animal TEXT)
                '''
            )```
slate swan
#

You can try something like this

velvet tinsel
#

I don’t know wtf databases are

#

I’m gonna look at them

cedar stream
velvet tinsel
#

Yes I’m going now

spring flax
#

oh no the one i was using for a connection to a db throughout the bot so i dont need to keep making a connection for each command

cedar stream
spring flax
#

huh

#

how did we come to that?

slate swan
velvet tinsel
#

I love the docs

spring flax
#

yeah they're great

slate swan
#

it would be used everywhere ¯\_(ツ)_/¯

cedar stream
#

So if u ever wanna switch to mongo

#

U gotta fix whole code

slate swan
#

why switch to mongo when postgresql exists

spring flax
#

i have no clue what that's about

cedar stream
slate swan
#

It's easy to migrate from Sqlite to psql

slate swan
cedar stream
#

Also if you have a production app with millions of users and billions of data u wont be using postgres

#

Ud be using nosql

slate swan
#

postgres supports noSQL too , as for production it's highly preferred

sullen shoal
#

fuck all this shit just tell me which one i should go with

slate swan
#

if you are cool with dictionaries , mongodb is a good choice

cedar stream
#

Talking tom company

slate swan
#

Yea

cedar stream
#

They used firebase since postgres wasnt scalable enough

#

Firestore*

slate swan
#

Companies like instagram , Spotify and Netflix use postgres fyi

#

Can we change bot presence to none??

#

What to do to remove bot's activity??

slate swan
cedar stream
spring flax
#

Don't put anything in the first place

slate swan
#

do you mean the status? ( Online/offline)

#

nah

slate swan
spring flax
#

It will have no activity by default

slate swan
#

Just don't set a status as diabolcal said

#

to None so they don't show

spring flax
#

You're giving it one, remove that part

slate swan
#

I mean I am giving it but later if I enter remove status command, it would remove it

spring flax
#

So it's not removing?

slate swan
#

I havent tried ._.

slate swan
slate swan
#

just asking if it can be removed

cedar stream
# slate swan It's faster than mongo too

No its not, nosql can have billions of entries and will work the same as if it had one, sql has certain limit to where it will start working noticeably slower

slate swan
cedar stream
sage otter
#

Did you not just read what he just said.

slate swan
sage otter
#

He said he’s going to initially have one and remove it later with a command.

slate swan
# slate swan Yea

Also 1 thing, if I have set a tasks.loop(minutes=30) Is there a way to call it before 30 minutes??

spring flax
#

Huh

slate swan
#

You can just call the task as a function too

slate swan
spring flax
#

Change minutes=.....

slate swan
#

How do i make a 3 space command such as

!buy golden ticket?
i used bot.group to make 2 space
!buy gticket, but how I make it into 3?

slate swan
# slate swan how??
@ext.tasks.loop(minutes=1)
async def task()
  #code``` If you ju:st do `await task()` IT gets called
spring flax
#

No... don't do that

slate swan
spring flax
#

Just use (ctx,*, argument)

cedar stream
spring flax
slate swan
#

yea

spring flax
#

I mean he wants to write !buy golden ticket

slate swan
spring flax
#

So why command group?

#

Make a normal command

maiden fable
#

Normal command with two args should suffice ngl

cedar stream
spring flax
#

Why two args?

slate swan
maiden fable
spring flax
#

No no read what he said @slate swan

cedar stream
#

3 args

hybrid jay
spring flax
slate swan
#

read their 3rd line

maiden fable
slate swan
#

wait look at dis

@bot.group()
async def hm(ctx):
 await ctx.send('hm')

@hm.command()
async def helo(ctx):
 await ctx.send('yo) 

this makes
!hm helo

spring flax
#

Okay idk what you want to do lol

slate swan
cedar stream
slate swan
#

command

pale turtle
#

I wasn't here for a while nothing changed lol

slate swan
spring flax
#

So you can use consume rest?

cedar stream
slate swan
cedar stream
#

Nested command group

slate swan
cedar stream
#

I dont think aliases attribute lets u put in spaces

slate swan
cedar stream
#

No

slate swan
spring flax
#

Just use this

spring flax
cedar stream
#

Just go w nested command groups

spring flax
#

As the arguments

slate swan
#

so the bot will match the arg provided by the author?

cedar stream
cedar stream
#

Like

#

He wants to make a command called buy_golden_ticket

orchid inlet
#

guys. what coding excercises can I do to get better

spring flax
#

From where are you getting this?

cedar stream
orchid inlet
#

I cant make a single code without searching it up

spring flax
cedar stream
cedar stream
orchid inlet
orchid inlet
#

fx

cedar stream
#

Like u will always have to look something up

orchid inlet
# cedar stream Wym?

like @commands.command() async def join(self,ctx): if ctx.author.voice is None: await ctx.send("Du skal sjovt nok være i en voice channel") voice_channel = ctx.author.voice.channel if ctx.voice_client is None: await voice_channel.connect()

#

like this

cedar stream
#

Not this necessary, but no one can code w/o looking stuff up

#

It’ s part of the process

orchid inlet
#

I know, but making a discord queue is too hard for me. I dont understand

#

So what can I do just to get better at making code lines

cedar stream
slate swan
#

on what type of bot, is the bot using files or using youtube api to play

cedar stream
slate swan
#

if its a file then its pretty simple if its using a command which search youtube to play then its hard

orchid inlet
slate swan
orchid inlet
cedar stream
cedar stream
cedar stream
#

Like literally anything

#

Just code a lot and ull gain experience

slate swan
orchid inlet
#

Can you show me what a bot dashboard looks like? @cedar stream

cedar stream
#

The site it will take u on is a dashboard

#

But that one is complex and has a whole team working on it

slate swan
orchid inlet
cedar stream
#

U can make a mobile app

orchid inlet
#

so you make a website with python?

cedar stream
#

Or game

orchid inlet
#

I thought you only could make websites with html

cedar stream
cedar stream
#

There is more to web applications than html

sullen shoal
#

you can do anything with python, it will be a little slow tho

velvet tinsel
surreal dust
#

so hello

#

hecker here

#

how do i master making discord bots and proudly displace the supreme carl bot

tawdry perch
#

this seems to be incorrect way to get a role, why? ```py
role = await ctx.guild.get_role(self.default)

tawdry perch
#

oh

surreal dust
#

hello so i needed some help i wanted my bot to create the highest role in the server (as he is the administrator) and then give it to himself is it possible by any means?

slate swan
#

Why make a role and give it to himself

#

he is in the same position as the role

orchid inlet
#

it was just a refrence

slate swan
#

@slate swan How can I make a command so the user input b!image <text> -u <user>

text is a string and user is a discord member

slate swan
#

text is not of 1 letter

#

text is like a full sentence

#

what's the part tho

slate swan
#

*-U part

#

-u is like a flag

#

it will tell the bot that a user:discord.Member is entered

#

why dont you reverse the command order , like mention the user first and text later?

#

but I want to make it so that if the user is none, then the user is ctx.author

slate swan
#

??

boreal ravine
#

!e

a = None
b = a or "a is none"
print(b)
unkempt canyonBOT
#

@boreal ravine :white_check_mark: Your eval job has completed with return code 0.

a is none
slate swan
#

I am not refering to that

boreal ravine
#

What are you referring to then

boreal ravine
#

bruh

slate swan
#

you mean py user:discord.Member=None?

#
async def command(ctx , user: typing.Union[str . discord.Member] , text):```
#

and then you can check if user variable is a discord.Member or not

slate swan
#

!d typing.Union

unkempt canyonBOT
#

typing.Union```
Union type; `Union[X, Y]` is equivalent to `X | Y` and means either X or Y.

To define a union, use e.g. `Union[int, str]` or the shorthand `int | str`. Details...
boreal ravine
#

just use | if your using 3.10

slate swan
#

Oh and what if the user have to enter:py b!help 1 -u whois abcd

I want to put 1 and abcd in variable A and whois in variable B

#

A is a list

orchid inlet
#

@cedar stream Is there other small bot projects I can start on instead of a dashboard?

leaden jasper
#

how to see number of animated emojis in a server?

boreal ravine
#

!d discord.Guild.emojis

unkempt canyonBOT
visual island
#

!d discord.Emoji.animated

unkempt canyonBOT
boreal ravine
#

^^

#

also why does the documentation get deleted after a couple of seconds

#

I didn't click the reaction

leaden jasper
#

the limit for the server

boreal ravine
#

oh

visual island
boreal ravine
#

o

#

!d discord.Guild.emoji_limit

unkempt canyonBOT
boreal ravine
#

hm idk by default it's 50

#

you could check for the guilds boosts and add them though

leaden jasper
orchid inlet
#

hey guys, How do I make a about respond to 2 different thing in one command block

#
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith['Hello', 'hello']:
        await message.channel.send('Hello')```
#

I made a string, but it doenst work

orchid inlet
#

tuple?

visual island
#

if message.content.startswith(('Hello', 'hello')):

visual island
#

!d tuple

orchid inlet
#

oh, why does [] not work?

unkempt canyonBOT
#

class tuple([iterable])```
Tuples may be constructed in a number of ways:

• Using a pair of parentheses to denote the empty tuple: `()`

• Using a trailing comma for a singleton tuple: `a,` or `(a,)`

• Separating items with commas: `a, b, c` or `(a, b, c)`

• Using the [`tuple()`](https://docs.python.org/3/library/stdtypes.html#tuple "tuple") built-in: `tuple()` or `tuple(iterable)`...
visual island
#

not calling the startswith

orchid inlet
#

because you still need () to close it and not only []

#

right?

visual island
#

!e
print("hi".startswith(["1", "2"]))

unkempt canyonBOT
#

@visual island :x: Your eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "<string>", line 1, in <module>
003 | TypeError: startswith first arg must be str or a tuple of str, not list
visual island
#

see

#

the main reason is mutability

velvet tinsel
visual island
velvet tinsel
#

👌

#

You have pycharm professional?

#

Lucky

cedar stream
leaden jasper
#

what is the ratelimit for adding emojis

visual island
velvet tinsel
brave flint
#

why it trow an error :
An error occurred: Command raised an exception: UnboundLocalError: local variable 'qr' referenced before assignment

boreal ravine
#

qr was defined somewhere else

brave flint
#

nope

boreal ravine
#
qr = ...

def func():
  qr = ...
``` something like this happened
boreal ravine
#

the error doesn't lie

brave flint
#

okie

orchid inlet
slate swan
#

help py @Blank.command(aliases=["phc"]) async def phcomment(ctx, user: typing.Union[str, discord.Member], *, text=None): await ctx.message.delete() if text is None: text="I like it very much" if type(user)==str: text=f"{user} {text}" user=ctx.message.author name=user.display_name image=str(user.avatar_url) url=phcomment_gen(name, image, text) try: file=io.BytesIO(requests.get(url).content) await ctx.channel.send(file=discord.File(file, 'ph.png')) except Exception: await ctx.channel.send(url)

Even if I mention a user, it still think its a string

visual island
orchid inlet
#

doenst work

orchid inlet
#

okay so no []?

boreal ravine
orchid inlet
#

okay ty

boreal ravine
#

icy gave an example already smh

orchid inlet
visual island
boreal ravine
#

just do ```py
async def phcomment(ctx, member: discord.Member, *, text)

visual island
#

idk

slate swan
visual island
#
async def phcomment(ctx, member: discord.Member = None, *, text = None):
  member = member or ctx.author
  # stuff you did earlier
boreal ravine
#

hm

slate swan
boreal ravine
#

so confused

visual island
#

or yeah Optional works too

slate swan
#

trypinf

boreal ravine
# slate swan optional\🤔

well, if you wanted to do !phcomment hello and !phcomment @kayle#6872 hello it'd both work if you used Optional ig

slate swan
#

btw

slate swan
snow anchor
#

!import os

boreal ravine
#

pog

#

#bot-commands pls 🙏

slate swan
#

!e py def foo(a=None , b): pass

visual island
#

I forgot to change it lol

slate swan
#

ah

glass rock
#

is there an async time module?

snow anchor
#

hi

glass rock
#

hi

boreal ravine
visual island
boreal ravine
#

asyncio has sleep attribute which is async

visual island
#

do you mean for the time.sleep?

orchid inlet
#

@visual island it still dont work

glass rock
visual island
#

show code

boreal ravine
snow anchor
#

I'm HAPPY 😀 😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀

visual island
glass rock
boreal ravine
#

wut icy said

glass rock
orchid inlet
#
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith(('inshallah', 'Inshallah')):
        await message.channel.send('SIIIIIUUUUUUUU')```
#

@visual island

slate swan
unkempt canyonBOT
minor panther
#

Hi

snow anchor
orchid inlet
snow anchor
#

👍

boreal ravine
minor panther
#

Guys, i have one unusual problem

orchid inlet
#

its from a meme btw lmao

slate swan
visual island
#

you can

minor panther
#

I use cogs

orchid inlet
slate swan
#

oh?

orchid inlet
visual island
#

search up str.startswith on google

visual island
orchid inlet
slate swan
visual island
orchid inlet
#

if that is what you mean

boreal ravine
#

yes

visual island
#

yes

orchid inlet
#

wait wait wait. Cant you have more command blocks where to bot responds

#

like I have two identical bots, the difference between is just what I say in the chat and what it responds with.

#

so in the first its "Inshallah" respond: "SIIIIIIIIUUUUUUUUUUU"

#

and in the second block its "okay lets go" respond: "youtube link"

#

or I could just send the block

#
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('inshallah'):
        await message.channel.send('SIIIIIUUUUUUUU')

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('okay lets go'):
        await message.channel.send('https://www.youtube.com/watch?v=AWM5ZNdWlqw')```
#

@visual island

minor panther
#

Ok the problem is in cogs. I want to get the guild on the initialization step:
Like this:

1.   def __init__(self, bot):
2.         self.bot = bot
3.         self.guild = self.bot.get_guild()

But there is one problem, when i use get method to get the guild (line 3) method returns me None, not guild I want to find.
The only solution was to use:

await self.bot.fetch_guild()

Okey, i right its the only way to correctly get it, if you know how to do it another way, tell me, it will initially change root of the problem.
But my solution is async method,
i cant use await in __init__().
I also tried to use asyncio
I worked with loops, my code looked like this:

1.    def __init__(self, bot):
2.         self.bot = bot
3.         loop =asyncio.get_event_loop()
4.         self.guild=loop.run_until_complete(
              asyncio.create_task(
                     self.bot.fetch_guild()
              )
)

But i’ve caught an exception with request lib, i find it is in some special methods in library, i think that my tryings to use asyncio don’t correspond with these methods.
I need in a solution. I dont wanna add attributes to cog by using on_ready event

orchid inlet
#

well its only one of the blocks that work

#

and there is no error. Should I send the whole code?

visual island
#

no, you can only have 1 same event, just use if-elif

orchid inlet
#

So I cant do it?

#

But I already use if

visual island
visual island
orchid inlet
#

where in the code

visual island
#

below your first if statement

minor panther
#

My goal is to get tge guild in init

visual island
minor panther
#

Any way

minor panther
orchid inlet
#
@client.event
if async def on_message(message):
    if message.author == client.user:
        return

    if message.content.startswith('okay lets go'):
        await message.channel.send('https://www.youtube.com/watch?v=AWM5ZNdWlqw')```
visual island
orchid inlet
#

like this

valid perch
minor panther
#

I load all extentions then i run the bot

visual island
minor panther
#

Ok

orchid inlet
visual island
#
if statement1:
   ... 
elif statement2:
   ... 
orchid inlet
#

ahhhh

visual island
minor panther
visual island
#

also what you mean by request lib is aiohttp probably?

boreal ravine
slate swan
#
random_status_status=True

@Blank.command(aliases=["rs"])
async def random_status(ctx):
    await ctx.message.delete()
    if random_status_status==False:
        random_status_status=True
        await ctx.channel.send("Random statuses are now turned on", delete_after=2.0)
        await change_activity()
    if random_status_status==True:
        random_status_status=False
        await Blank.change_presence(activity=None)
        await ctx.channel.send("Random statuses are now turned off and the status have been reset", delete_after=2.0)```

When I print it, it shows true but when this command is ran, then it shows random_status_status referenced before assignment \😢
glass rock
#

my bot was running and it suddenly stopped

#

help

slate swan
glass rock
slate swan
glass rock
#

no

slate swan
#

What did you type when it stopped?

glass rock
#

nothing

#

but i did add something on_ready

slate swan
#

what?

#

change presence?

glass rock
#
  while True:
    if time.strftime("%H:%M:%S")=="12:30:00":
      await channel.send("Time ees 123000")```
#

would this crash my bot?/

slate swan
#

I don't think so but IDK if we can use infinite loop in on ready

glass rock
#

it ran for a bit then crashed for no reason

slate swan
#

idk bro then, try asking professional

visual island
#

while True is blocking, but with async function inside it, it will be asynchronous. But in your case there, youre putting the async function inside an if statement where it should be in the outest indentation

glass rock
visual island
#

you can put await asyncio.sleep(0.001)

#

that doesn't change anything

glass rock
visual island
#

yes

glass rock
#

what difference wuld 0.01 make

magic ore
visual island
magic ore
#

Because they're already yielding to the event loop in the while loop

visual island
#

yielding to the event loop?

velvet tinsel
visual island
magic ore
#

Well first of all they should post the error they get when their bot crashes instead of us guessing what the problem is

visual island
#

probably heart beat block?

#

idk

velvet tinsel
#

My heart beats once every hour

#

👍

velvet tinsel
visual island
visual island
#

!botvar use this instead

unkempt canyonBOT
#

Python allows you to set custom attributes to most objects, like your bot! By storing things as attributes of the bot object, you can access them anywhere you access your bot. In the discord.py library, these custom attributes are commonly known as "bot variables" and can be a lifesaver if your bot is divided into many different files. An example on how to use custom attributes on your bot is shown below:

bot = commands.Bot(command_prefix="!")
# Set an attribute on our bot
bot.test = "I am accessible everywhere!"

@bot.command()
async def get(ctx: commands.Context):
    """A command to get the current value of `test`."""
    # Send what the test attribute is currently set to
    await ctx.send(ctx.bot.test)

@bot.command()
async def setval(ctx: commands.Context, *, new_text: str):
    """A command to set a new value of `test`."""
    # Here we change the attribute to what was specified in new_text
    bot.test = new_text

This all applies to cogs as well! You can set attributes to self as you wish.

Be sure not to overwrite attributes discord.py uses, like cogs or users. Name your attributes carefully!

slate swan
orchid inlet
# minor panther elif equals ```py else: if ```

Well, is this wrong then? ```@client.event
async def on_message(message):
if message.author == client.user:
return

elif message.content.startswith('inshallah'):
    await message.channel.send('SIIIIIUUUUUUUU')

@client.event
async def on_message(message):
if message.author == client.user:
return

elif message.content.startswith('okay lets go'):
    await message.channel.send('https://www.youtube.com/watch?v=AWM5ZNdWlqw')```
#

@minor panther

slate swan
#

2 on messages cannot be in the program

rain ridge
#

how do u reset the nick

slate swan
orchid inlet
rain ridge
#

ty

sullen shoal
rain ridge
slate swan
glass rock
orchid inlet
slate swan
#

You can do if else

visual island
# slate swan I still dont understand

!e

a = 1
def b():
    print(a) # global variable defined line 1 get to be a local variable in function b
    a = 2 # trying to set local variable but local variable exists already which is what we defined above
b()
unkempt canyonBOT
#

@visual island :x: Your eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "<string>", line 5, in <module>
003 |   File "<string>", line 3, in b
004 | UnboundLocalError: local variable 'a' referenced before assignment
orchid inlet
slate swan
sullen shoal
#

why is it a tuple

orchid inlet
sullen shoal
#

it should

slate swan
sullen shoal
slate swan
sullen shoal
slate swan
slate swan
#

oh understood a bit

slate swan
sullen shoal
slate swan
#

But still idk whats the error

#

can you explain me with a easy fix

sullen shoal
#

what is the error

sullen shoal
#

okay i will try to explain

slate swan
#

Wait wait its said

Local variable random_status_status referenced before asignment

#

Why didn't it took the global variable??

sullen shoal
#
random_status_status=True

@Blank.command(aliases=["rs"])
async def random_status(ctx):
    await ctx.message.delete()
    if random_status_status==False:
        random_status_status=True```
here before defining the command you declared the variable, and now, 
```py
    if random_status_status==False:
        random_status_status=True```
You're trying to make it a local variable,  in the second line, and just before that you're also trying to get its value
cedar stream
sullen shoal
#

!e

print(v)
v = 1```
unkempt canyonBOT
#

@sullen shoal :x: Your eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "<string>", line 1, in <module>
003 | NameError: name 'v' is not defined
sullen shoal
#

this is somewhat like that

#

but because its already defined, it wont show this error

slate swan
#

So what should I do to set its value to True if it is false

#

the value of global one

maiden fable
#

What happened

sullen shoal
#

you may either declare it a global or go with the good method which is using the bot or cog class

slate swan
#

ok so let me declare it global

sullen shoal
#

stay away from global variables

#

dont do that shit

#

its ugly and bad

maiden fable
unkempt canyonBOT
#

Python allows you to set custom attributes to most objects, like your bot! By storing things as attributes of the bot object, you can access them anywhere you access your bot. In the discord.py library, these custom attributes are commonly known as "bot variables" and can be a lifesaver if your bot is divided into many different files. An example on how to use custom attributes on your bot is shown below:

bot = commands.Bot(command_prefix="!")
# Set an attribute on our bot
bot.test = "I am accessible everywhere!"

@bot.command()
async def get(ctx: commands.Context):
    """A command to get the current value of `test`."""
    # Send what the test attribute is currently set to
    await ctx.send(ctx.bot.test)

@bot.command()
async def setval(ctx: commands.Context, *, new_text: str):
    """A command to set a new value of `test`."""
    # Here we change the attribute to what was specified in new_text
    bot.test = new_text

This all applies to cogs as well! You can set attributes to self as you wish.

Be sure not to overwrite attributes discord.py uses, like cogs or users. Name your attributes carefully!

cedar stream
maiden fable
#

Breh

cedar stream
#

Inside the function

sullen shoal
#

really bad ugly dumb choice

cedar stream
#

It’ s his decision 🤷🏼‍♂️

maiden fable
#

bruh, there's a reason I used the bot var tag

cedar stream
slate swan
cedar stream
#

Np

#

🤷🏼‍♂️

maiden fable
#

;-;

slate swan
sullen shoal
#

chat looking cool

cedar stream
#

How is it looking?

sullen shoal
#

i aint showing, its too good

maiden fable
cedar stream
#

Okay

maiden fable
#

!globals also

unkempt canyonBOT
#

When adding functions or classes to a program, it can be tempting to reference inaccessible variables by declaring them as global. Doing this can result in code that is harder to read, debug and test. Instead of using globals, pass variables or objects as parameters and receive return values.

Instead of writing

def update_score():
    global score, roll
    score = score + roll
update_score()

do this instead

def update_score(score, roll):
    return score + roll
score = update_score(score, roll)

For in-depth explanations on why global variables are bad news in a variety of situations, see this Stack Overflow answer.

slate swan
#

Also this is not working: py await Blank.change_presence(activity=None)

maiden fable
#

That should remove the activity, no?

hasty loom
#

is there a more professional way to run discord bots than just ssh'ing into your vps, git cloning the repo, putting ur token in the config file with vim, and then doing python3 bot.py in a tmux session

#

cus thats why i do lol and idk if thats a bad thing

maiden fable
#

A systemd file?

hasty loom
#

i use time4vps which is in germany

slate swan
cedar stream
hasty loom
#

uh dont think its got docs lol

#

its just a regular ubuntu server

cedar stream
tawdry perch
#

what moderation commands I should add to my bot? I have basics done

cedar stream
#

Ik gcp has some stuff that makes it easier but I never looked into it

cedar stream
#

Add automod

tawdry perch
#

this is what I have now

#

automod = ?

cedar stream
#

Just copy em of dyno and mee6

tawdry perch
#

I don't know what commands they even have

slate swan
tawdry perch
#

alrd existing, as well: anti spam, filtters for invites, words and few other things

cedar stream
sullen shoal
#

wont that be great

cedar stream
#

LMFAOOO

tawdry perch
#

I have as well implemented that once

cedar stream
#

No, it should default to ur bot

tawdry perch
#

nah

cedar stream
#

Do you log all mod actions?

tawdry perch
#

pretty much

#

it's still a bit under developmment because it's a lot of work for me

cedar stream
slate swan
#

Guys can we remove the activity status of bot??