#discord-bots

1 messages ¡ Page 707 of 1

sour lodge
#

ohhhh

slate swan
#

It should be inside the init function

sour lodge
#

makes sense

slate swan
#

They are fields

shadow wraith
#

don't tell me someone codefeeded you for that avatar command

slate swan
#

!d discord.Embed.add_field

unkempt canyonBOT
#

add_field(*, name, value, inline=True)```
Adds a field to the embed object.

This function returns the class instance to allow for fluent-style chaining.
shadow wraith
#

🚶 i understand i need examples but i need a basic concept of implementation

fluid spindle
#

Is there some listener that listens for replies to a certain message?

shadow wraith
fluid spindle
slate swan
#

also , you should not edit your discord client with apps like better discord / bandaged discord
It's against discord TOS

shadow wraith
#

wait i misread it

slate swan
#

!d discord.Message.reference

unkempt canyonBOT
#

The message that this message references. This is only applicable to messages of type MessageType.pins_add, crossposted messages created by a followed channel integration, or message replies.

New in version 1.5.

slate swan
#

It's none if it's not a replied message or channel integration

#

You may use it in normal on_message events

shadow wraith
#

something i learned today: bot events are just complicated things easened for you

#

not applicable to all events tho

slate swan
#

Yeah , if you would be doing it thru the raw data you get from the discord Gateway connection , it would be very hard
That's what a wrapper is meant for

shadow wraith
#

so it wrapped my present for christmas?

sour lodge
#

how can I do client.latency in a cog cause there is no client

sage otter
#

What do you have bot defined as in your cog?

slate swan
#

ctx.bot.latency

sage otter
#

You could do that AMshrug

sour lodge
#

alr thanks

fluid spindle
slate swan
#

another way to do that is defining the .bot for your cog class inside the `init function

slate swan
#

If the condition satisfies , move on to next step
Else you can return

proven osprey
#

guys how to do like bot waiting for user's answer an than use it?

slate swan
#

Inside a command right?

#

!d discord.ext.commands.Bot.wait_for , use "message" as the event position arg

unkempt canyonBOT
#

wait_for(event, *, check=None, timeout=None)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Waits for a WebSocket event to be dispatched.

This could be used to wait for a user to reply to a message, or to react to a message, or to edit a message in a self-contained way.

The `timeout` parameter is passed onto [`asyncio.wait_for()`](https://docs.python.org/3/library/asyncio-task.html#asyncio.wait_for "(in Python v3.9)"). By default, it does not timeout. Note that this does propagate the [`asyncio.TimeoutError`](https://docs.python.org/3/library/asyncio-exceptions.html#asyncio.TimeoutError "(in Python v3.9)") for you in case of timeout and is provided for ease of use.

In case the event returns multiple arguments, a [`tuple`](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.9)") containing those arguments is returned instead. Please check the [documentation](https://discordpy.readthedocs.io/en/master/api.html#discord-api-events) for a list of events and their parameters.

This function returns the **first event that meets the requirements**...
proven osprey
#

@slate swan

#

correct?

slate swan
#

Nope

#

"message" should be a string

proven osprey
#

i cant understand)

#

@slate swansorry for mentions

velvet tinsel
#

What’s wrong

#

Also what is that

#

It’s missing kwargs

#

It’s missing a lot of stuff

fluid spindle
#

Is there a way to add a listener to a command group?

upbeat otter
proven osprey
#

check @upbeat otter

#

what i should write instead of ctx if im writing this inside on_voice_state_update

#

and it doesn't accept ctx

sour lodge
#

what does the word “kwargs” suppose to mean

upbeat otter
#

Annd theres no kwarg as user_limit

proven osprey
#

when im passing ctx into on_voice_state_update it writes me an error

proven osprey
fluid spindle
slate swan
#

!d disnake.Member.timeout

unkempt canyonBOT
#

await timeout(*, duration=..., until=..., reason=None)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Times out the member from the guild; until then, the member will not be able to interact with the guild.

Exactly one of `duration` or `until` must be provided. To remove a timeout, set one of the parameters to `None`.

You must have the [`Permissions.moderate_members`](https://docs.disnake.dev/en/latest/api.html#disnake.Permissions.moderate_members "disnake.Permissions.moderate_members") permission to do this.

New in version 2.3.
slate swan
velvet tinsel
#

Hi Okimii

#

I’m playing a Sherlock board game lol

#

By myself

#

😭

proven osprey
#

help me please i want to get input from user but i dont know how because its not possible to pass ctx inside on_voice_state_update

slate swan
proven osprey
#

can i use something different instead of ctx.author and ctx.channel?

velvet tinsel
#

Bro

#

Why don’t you Google some stuff

proven osprey
#

i tried

velvet tinsel
#

And?

proven osprey
#

and nothing

velvet tinsel
#

And nothing.

proven ore
proven osprey
#

yes i have before and after

velvet tinsel
#

Put ctx in and see what it does

proven osprey
#

on_voice_state_update does not accept ctx

#

that what it writes me when i put ctx inside

slate swan
#

the event doesnt take ctx

tawdry perch
#

how would you check against ctx.author when that means like command author

tawdry perch
slate swan
#

ctx = Context

tawdry perch
slate swan
#
@bot.command()
async def command(ctx: commands.Context):
    await ctx.send("message")

makes sense

#

dont know if its type hinted well tho

tawdry perch
#

I think that's the way, usually the Context is imported to avoid commands.

slate swan
proven osprey
tawdry perch
#

before and after are member objects

slate swan
#
@bot.command()
async def command(smt: commands.Context) -> None:
    await smt.send("message") 

in this case ctx is smt since its a positional arg it doesnt matter its arg naming but yes its bad practice

tawdry perch
slate swan
#

isnt weird how dpy converts something to a obj with a typehint

proven osprey
#

maybe i did something wrong i dont know, i got this code from the internet

tawdry perch
proven osprey
#

but my idea was to get input from user and then use it to set a voice limit

slate swan
tawdry perch
#

imo that is quite useful

slate swan
#

yeah weird how it converts it to an obj

#

pretty cool at the same time

#

!e

def foo(name: str) -> None:
    print(f"hello {name}")

foo(1)
unkempt canyonBOT
#

@slate swan :white_check_mark: Your eval job has completed with return code 0.

hello 1
slate swan
#

i type hinted it to a str but gave a int

tawdry perch
#

Would dpy raise error?

#

Oh wait, it would

slate swan
tawdry perch
#

Dang that is very useful, I mean I have used it as like that but never thought about it

slate swan
#
(nonetype: discord.Member)

this would make it a member obj which is kinda unpythonic but very cool

velvet tinsel
#

@proven osprey

#

I found something

tawdry perch
#

Everything is making sense now

slate swan
proven osprey
velvet tinsel
#

If you want it to send something

tawdry perch
#

Yep

velvet tinsel
#

And you can’t use ctx

tawdry perch
#

Now I can use that feature even more effectively

velvet tinsel
#

member.guild.system_channel.send() use this

velvet tinsel
#

Okimii being smort brainmon

proven ore
tawdry perch
#

Maybe I could make a custom object for discord.member or discord.user

proven osprey
#

what i need to write instead of this? @velvet tinsel

slate swan
proven ore
tawdry perch
#

Thx for telling me about that!

slate swan
slate swan
proven ore
#

*arg also takes unlimited arguments

slate swan
#

better to use a kwarg tho

velvet tinsel
#

Improve your Googling skills pithink

proven ore
#

like

def test(*args):
 print(args)
test("arg1", "arg2", "arg3")
# Result will be (arg1, arg2, arg3)
#

i gtg rn cya guys

velvet tinsel
#

Cool

proven ore
velvet tinsel
#

!e

def test(*args):
 print(args)
test("arg1", "arg2", "arg3")
# Result will be (arg1, arg2, arg3)
unkempt canyonBOT
#

@velvet tinsel :white_check_mark: Your eval job has completed with return code 0.

('arg1', 'arg2', 'arg3')
velvet tinsel
#

Yep 👍

velvet tinsel
slate swan
slate swan
proven osprey
#

am i stupid but i don't understand the place where i should write this @velvet tinsel

velvet tinsel
#

Use listen()

#

@slate swan

#

I also posted it

#

Be sure to mark my answer as correct

#

😳

slate swan
#
  1. your using client and importing commands?wut
    2.put your on ready event on top
    3.its message.reply
velvet tinsel
#

Mark my answer as correct as well

proven ore
slate swan
velvet tinsel
#

Yeah and message.reply

proven ore
unkempt canyonBOT
#

@proven ore :white_check_mark: Your eval job has completed with return code 0.

{'arg1': 'arg1', 'arg2': 'arg2', 'arg3': 'arg3'}
velvet tinsel
#

💀

proven osprey
proven ore
#

a dict

velvet tinsel
#

Ah returns a dict

proven ore
slate swan
velvet tinsel
#

He’s trying to get my attention

proven ore
slate swan
proven osprey
#

this is true...)

velvet tinsel
proven ore
velvet tinsel
#

The id

proven ore
#

u cant just send a picture ;-;

velvet tinsel
#

He can’t pass ctx

velvet tinsel
proven ore
#

could u show full code pls @proven osprey

#

@client.listen()

velvet tinsel
#

And client.listen()

velvet tinsel
#

STOP TAKING THE WORDS OUT OF MY HEAD

slate swan
proven ore
velvet tinsel
#

NOT FUNNY

#

ILL FIND WHERE YOU LIVE

proven ore
#

:KEKW:

#

sh

proven ore
velvet tinsel
#

:kek:

slate swan
#

!d discord.ext.commands.Bot

unkempt canyonBOT
#

class discord.ext.commands.Bot(command_prefix, help_command=<default-help-command>, description=None, **options)```
Represents a discord bot.

This class is a subclass of [`discord.Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") and as a result anything that you can do with a [`discord.Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") you can do with this bot.

This class also subclasses [`GroupMixin`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.GroupMixin "discord.ext.commands.GroupMixin") to provide the functionality to manage commands.
velvet tinsel
#

If you’re super beginner why you doing discord py

proven osprey
slate swan
velvet tinsel
#

Bro

#

You didn’t even know the bot can reply to itself

#

🕴️

#

Be prepared to encounter lots of errors

#

If you don’t know simple python

slate swan
velvet tinsel
#

bro

#

Finding excuses 🤔

slate swan
velvet tinsel
#

Me too

#

Can you come to my house

slate swan
#

im at your housepithink

#

already

velvet tinsel
#

Where are you

#

I want some company

slate swan
#

dpy uses asynchronous programming and oop

slate swan
unkempt canyonBOT
slate swan
velvet tinsel
#

You started it

#

Yeah

clear flax
#

As someone who just learned to code in python a few weeks ago, I've been looking for projects that i could do. I've narrowed down my choices to making a webpage and or discord bot. What route would be the best?

slate swan
#

if you want to i would recommend to learn pythons syntax yes,but if you want to learn dpy go for it,it will be hard but do whatever your heart desires pithink

velvet tinsel
#

Did you finish all the fundamentals

#

Like lists, dictionaries, functions, async, OOP, and classes?

slate swan
velvet tinsel
#

I made a career out of discord bots

slate swan
velvet tinsel
#

I earned $0 because yes

#

It’s how the code is structured

slate swan
#

the way its written in

velvet tinsel
#

Okimii

clear flax
slate swan
velvet tinsel
#

HTML, CSS is probably what you want

#

Python is mainly for backend

#

So is JavaScript

velvet tinsel
slate swan
slate swan
clear flax
#

alright

velvet tinsel
#

Cool

slate swan
#

14pithink

velvet tinsel
#

Bro I thought you were in high school

slate swan
#

good luck thopithink

slate swan
#

im a freshman 🚶

velvet tinsel
#

Maybe England has different ways of teaching

slate swan
#

about to be 15 in a month

velvet tinsel
#

🤔

velvet tinsel
slate swan
velvet tinsel
#

I’m gonna send you a gift 😳

slate swan
velvet tinsel
#

Where do you live

slate swan
#

ikrpithink

slate swan
velvet tinsel
#

I’m gonna buy you that big pink fluffy unicorn toy

proven ore
#

U do not need ctx if you have after and before parameters

velvet tinsel
velvet tinsel
#

All the cameras in my house are armed

#

You can’t run

slate swan
#

!ot yert

unkempt canyonBOT
daring valley
#
@bot.command()
async def say(ctx, *,message):
    await ctx.send(message)
    await ctx.message.delete()

why it doesn't delete the message?

velvet tinsel
#

message.delete()

slate swan
slate swan
velvet tinsel
#

And also what’s the- oh you said it

velvet tinsel
#

He did that

slate swan
#

your wrong lol

velvet tinsel
daring valley
slate swan
#

message.delete is for an event

velvet tinsel
#

Huh?

slate swan
velvet tinsel
#

I corrected myself message is a var that contains the message ID

slate swan
velvet tinsel
velvet tinsel
#

ok

#

but message is a var

slate swan
#

an kwarg

velvet tinsel
#

the var contains the message ID

daring valley
velvet tinsel
slate swan
#

might be given an error

daring valley
#

ohhh

velvet tinsel
slate swan
#

ctx.message.delete

velvet tinsel
#

You can do that lol

#

And also remove that message arg

slate swan
velvet tinsel
#

What’s that even doing there

velvet tinsel
#

Yeah maybe message=None is causing the error

slate swan
#
await ctx.message.send()

the coro deletes the command

velvet tinsel
#

Cute little snek

daring valley
velvet tinsel
#

What’s *,

#

Can’t you do *msg?

slate swan
velvet tinsel
#

That doesn’t make sense

#

can not you do

#

That is grammatically incorrect

slate swan
velvet tinsel
#

However “cant” does make sense

#

can’t you do makes sense

slate swan
#

*, this makes every following arg a kwarg

velvet tinsel
#

However if you write it formally it does not

#

🤔

slate swan
#

know your stuff mrpithink

velvet tinsel
#

How very interesting

velvet tinsel
slate swan
velvet tinsel
#

I was just…uhhh…sleepy 😳

#

😳

slate swan
daring valley
#
@bot.command()
async def say(ctx, *,msg):
    await ctx.message.delete()
    await ctx.send(msg)

now it doesn't send message and the message doesn't get deleted

velvet tinsel
#

Can I sleep

velvet tinsel
#

You sent it then immediately deleted it

#

Of course nothings gonna happen lol

#

Use asyncio.sleep()

#

!d asyncio.sleep

unkempt canyonBOT
#

coroutine asyncio.sleep(delay, result=None)```
Block for *delay* seconds.

If *result* is provided, it is returned to the caller when the coroutine completes.

`sleep()` always suspends the current task, allowing other tasks to run.

Setting the delay to 0 provides an optimized path to allow other tasks to run. This can be used by long-running functions to avoid blocking the event loop for the full duration of the function call.

Deprecated since version 3.8, removed in version 3.10: The `loop` parameter. This function has been implicitly getting the current running loop since 3.7. See [What’s New in 3.10’s Removed section](https://docs.python.org/3/whatsnew/3.10.html#whatsnew310-removed) for more information.

Example of coroutine displaying the current date every second for 5 seconds:
velvet tinsel
#

Ah tylerr

daring valley
velvet tinsel
#

Hello

slate swan
sage otter
#

Did you just do
[p]say or did you actually put a message behind it

velvet tinsel
slate swan
velvet tinsel
#

He wanted to say it first lol

slate swan
velvet tinsel
#

There’s a reason why it’s called “say”

velvet tinsel
daring valley
sage otter
#

Betting he did what I said. It probably rose a commands.MissingArguments or something

velvet tinsel
#

Sorry 😭

slate swan
sage otter
proven ore
#

A

velvet tinsel
#

wdym deletes the command

sage otter
#

How did you use the command.

velvet tinsel
sage otter
proven ore
proven ore
#

Question*

velvet tinsel
#

Show us

slate swan
daring valley
#
?say a
proven ore
velvet tinsel
#

And?

sage otter
#

And that didn’t work.

velvet tinsel
daring valley
proven ore
velvet tinsel
#

Because you sent it and deleted it

sage otter
proven ore
sage otter
#

I don’t need your help.

velvet tinsel
#

At the same time don’t you see

velvet tinsel
slate swan
#

you guys need to scroll up ngl

daring valley
#
@bot.command()
async def say(ctx,*,rep=None):
    await ctx.message.delete() #doesn't do anything
    await ctx.send(rep) #works but not when it's 2nd like now
proven ore
#

This works properly

velvet tinsel
#

Why did you delete the message first

proven ore
#

Funny how I still dk who’s asking lol

velvet tinsel
#

It’s Korn

proven ore
#

Oh

velvet tinsel
#

Who did you think was asking

proven ore
#

Trying doing ctx: commands.Context

velvet tinsel
#

naw

daring valley
#
@bot.command()
async def say(ctx,*,rep=None):
    await ctx.send(rep)
    await ctx.message.delete()
slate swan
sage otter
#

Type hinting doesn’t effect run time in this case

proven ore
velvet tinsel
#

WHAT

proven ore
velvet tinsel
#

SERIOUSLY

proven ore
#

Ik no need but what if

slate swan
#

its a positional arg ffs

proven ore
daring valley
proven ore
#

Just try

sage otter
#

I’m leaving. I already put in my 2 cents.

velvet tinsel
sage otter
#

🚶

velvet tinsel
#

🕴️

proven ore
slate swan
velvet tinsel
#

Yeah

#

Don’t you find it funny

slate swan
velvet tinsel
#

No

proven ore
velvet tinsel
#

🤔

slate swan
#

you guys should learn basic oop

proven ore
daring valley
#

imma head out

proven ore
#

How the hell is this related to oop Lol

velvet tinsel
#

No

slate swan
#

he wants to delete the message that invoked the command

slate swan
velvet tinsel
#

Try bot.delete_message(ctx.message)

proven ore
proven ore
#

delete() is a coro not a class

slate swan
velvet tinsel
proven ore
#

Coros*

velvet tinsel
#

And use bot.say()

slate swan
velvet tinsel
proven ore
velvet tinsel
#

Why not use it

slate swan
velvet tinsel
#

Or use purge()

proven ore
velvet tinsel
#

But that’s too risky

proven ore
velvet tinsel
#

Naw it’s too risky

#

It depends on the bots response

proven ore
#

Ye

pliant gulch
velvet tinsel
#

Sometimes the bot is slower

vocal shoal
#

is there a function that returns the last command/event ran?

velvet tinsel
#

It can delete the message

slate swan
velvet tinsel
proven ore
velvet tinsel
#

But there is a way

pliant gulch
vocal shoal
proven ore
#

Bruh

pliant gulch
#

You are quite literally using the class by using the methods of the class

velvet tinsel
slate swan
pliant gulch
#

You do str.split not split(str)

velvet tinsel
pliant gulch
#

Unless split is defined otherwise

slate swan
pliant gulch
#

That would be functional programming

proven ore
vocal shoal
proven ore
#

Ok guys let’s go back to the topic lmao

velvet tinsel
#

For example, @bot.command(): async def foo: … list.append(foo)

proven ore
#

We’re supposed to help him

#

LOL

velvet tinsel
#

I take offence on behalf of Okimii

slate swan
#

🤪

velvet tinsel
#

Ok

#

Let’s stop now

proven ore
pliant gulch
#

🤔

proven ore
#

ANYWAYS

velvet tinsel
#

||cause you are nah jk ||

#

ANYWAYS

velvet tinsel
#

🚶‍♂️

#

“What discord py is this”

proven ore
#

🧑‍🦯

velvet tinsel
#

“Idk, discord py”

slate swan
proven ore
#

🧑‍🦯🧑‍🦯🧑‍🦯

velvet tinsel
#

“Oh cool”

#

“Yeah I know”

proven ore
#

🏃

velvet tinsel
#

“It’s discord py”

#

“Then why did you ask which discord py it is”

#

“…well”

proven ore
slate swan
velvet tinsel
#

Then ask what version

proven ore
slate swan
proven ore
slate swan
proven ore
#

Okay…

velvet tinsel
#

Okay…

proven ore
#

🧎

slate swan
proven ore
proven ore
proven ore
velvet tinsel
slate swan
proven ore
velvet tinsel
proven ore
velvet tinsel
#

Bye 👋

proven ore
velvet tinsel
#

Too bad

#

I went there

#

It was terrible

proven ore
#

Anyone has a cool template for web dashboard of a discord bot? (I wanna use it with flask)

proven ore
proven ore
#

Âż?

proven ore
#

Sus

velvet tinsel
#

Your pfp with a tag that says ayo look it’s my bot

proven ore
#

Looks like something to me ;)

velvet tinsel
#

Take a screenshot of your pfp

#

And then put a text that says “ayo it’s my bot”

#

And use it as banner

proven ore
#

No fr dyk any templates breh

velvet tinsel
#

I have no idea

#

actually, I do. I’m just not bothered

slate swan
#

hi anynone has a cool avatar and nickname for a but cuz i think of channging pfp of my bot and nickaname

slate swan
#

i dont know i just need cool pfp and nickname for my but i losing ideas

hushed field
#

whats your bot about

slate swan
#

but fisrtly i dont thing of this to be releate to the bot

velvet tinsel
velvet tinsel
#

no

slate swan
#

its the easiest thing

velvet tinsel
#

how?

#

exactly

#

no response~

slate swan
#

cuz fristyly u need to find good pfp or make

velvet tinsel
#

no

#

you're getting it wrong

#

it's hard to change the pfp

slate swan
velvet tinsel
#

it wont work through dev portal

slate swan
#

right there

#

yes it would

velvet tinsel
#

naw

#

have you even tried

slate swan
#

just run the bot after you update its name and boom donepithink

slate swan
velvet tinsel
#

it doesnt work like that

velvet tinsel
slate swan
slate swan
velvet tinsel
slate swan
#

some sort of my opinion

#

more preference than opinion

velvet tinsel
#

yeah ig

slate swan
#

my bot gots this nickname and pfp but i dont have any ideas to change nickname and pfp

slate swan
slate swan
slate swan
slate swan
slate swan
slate swan
#

i only have 148 lines for my bot rn but idk what commands to add i have basic ones and kick ban unban mute etc

#

well nothing to be exact everyone starts as a beginner

velvet tinsel
slate swan
#

i just do have one question how do i hid my token? so client.run(TOKEN)
is hidden

velvet tinsel
#

see

slate swan
#

I tried making a music one where it plays and i made it so it can leave/join using !join but i couldnt figure out how to do it

#

i think since youtube is taking down usic bots its not possible

slate swan
#

ive only been using tutorials but no copy pasting so far 😄

#

i like to type it it gives me a real experience

#

well i recommend to use docs and no tutorials that are probably outdated

#

kekw

slate swan
#

heh

#

how to make command that counts messagas has user send

#

when samone types +user it shows stats of usaers messages

#

if i can do this in python

#

pls

dapper cobalt
#

Store in a database each user's messages count, and increment +1 each time a user sends a message.

slate swan
#

but i dont know how to make that how to start even make it

mellow gulch
#

Can someone help

#

The argument missing is player2id

slate swan
#

this

dapper cobalt
unkempt canyonBOT
#

discord.on_message(message)```
Called when a [`Message`](https://discordpy.readthedocs.io/en/master/api.html#discord.Message "discord.Message") is created and sent.

This requires [`Intents.messages`](https://discordpy.readthedocs.io/en/master/api.html#discord.Intents.messages "discord.Intents.messages") to be enabled.

Warning

Your bot’s own messages and private messages are sent through this event. This can lead cases of ‘recursion’ depending on how your bot was programmed. If you want the bot to not reply to itself, consider checking the user IDs. Note that [`Bot`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Bot "discord.ext.commands.Bot") does not have this problem.
mellow gulch
slate swan
#

!code

unkempt canyonBOT
#

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

slate swan
#

its an event i know

dapper cobalt
slate swan
#

ok

bitter perch
#

!d collections.Counter

unkempt canyonBOT
#

class collections.Counter([iterable-or-mapping])```
A [`Counter`](https://docs.python.org/3/library/collections.html#collections.Counter "collections.Counter") is a [`dict`](https://docs.python.org/3/library/stdtypes.html#dict "dict") subclass for counting hashable objects. It is a collection where elements are stored as dictionary keys and their counts are stored as dictionary values. Counts are allowed to be any integer value including zero or negative counts. The [`Counter`](https://docs.python.org/3/library/collections.html#collections.Counter "collections.Counter") class is similar to bags or multisets in other languages.

Elements are counted from an *iterable* or initialized from another *mapping* (or counter):

```py
>>> c = Counter()                           # a new, empty counter
>>> c = Counter('gallahad')                 # a new counter from an iterable
>>> c = Counter({'red': 4, 'blue': 2})      # a new counter from a mapping
>>> c = Counter(cats=4, dogs=8)             # a new counter from keyword args
bitter perch
#

I present

cedar stream
#

!d dict

unkempt canyonBOT
#

class dict(**kwargs)``````py

class dict(mapping, **kwargs)``````py

class dict(iterable, **kwargs)```
Return a new dictionary initialized from an optional positional argument and a possibly empty set of keyword arguments.

Dictionaries can be created by several means:

• Use a comma-separated list of `key: value` pairs within braces: `{'jack': 4098, 'sjoerd': 4127}` or `{4098: 'jack', 4127: 'sjoerd'}`

• Use a dict comprehension: `{}`, `{x: x ** 2 for x in range(10)}`

• Use the type constructor: `dict()`, `dict([('foo', 100), ('bar', 200)])`, `dict(foo=100, bar=200)`
slate swan
slate swan
#

so rn i need to make command +user thats shows users sent messages in the discord server

mellow gulch
#

Anyone know how to fix this it is prolly smth i am missing but idk

cedar stream
slate swan
cedar stream
cedar stream
slate swan
#

i got an event

#

only

cedar stream
#

Hb the command

slate swan
#

but the command i dont know how to make

cedar stream
#

Just read data from the db and display it

cedar stream
cedar stream
desert heart
#

Keep in mind that if if is used, then the code is checking every time versus only raising an exception if it doesn't exist

cedar stream
#

Especially when he doesn’t have any users stored

#

Idk, for this use case it just seems nicer to use if/else

#

Tho I get what u mean

mellow gulch
#

Im assuming that im not supposed to do that

cedar stream
mellow gulch
#

Wdym

cedar stream
#

innit

#

Just ConnectFour(player…)

#

This creates new instance

mellow gulch
#

But i cannot pass through the variables through that class

#

It doesnt let me and gibs me an error

slate swan
# cedar stream Where do you store data

i need to make some sort of file for that coomand or something (i usin hosting and in this hosting i making command and files for commands thats needs files)

cedar stream
mellow gulch
#

And i was told to pass them through the innit function

cedar stream
#

And the error

slate swan
#

what is db

cedar stream
#

It’ s where u store data

slate swan
#

ok

#

i need to make other file for this or what

cedar stream
slate swan
#

ok

#

i can make data bases on my hosting

#

yes

cedar stream
#

Google mongo, It’ s simplest and u can have a free cluster in cloud

mellow gulch
# cedar stream Send code
import nextcord, datetime, os
from datetime import datetime
from nextcord.ext import commands


def setup(bot):
    print("Connect Four has loaded.")

class ConnectFour():
    def __init__(self, bot, msg, game_num, player1name, player1id, player2name, player2id):

        class ready_up_button(nextcord.ui.View):
            def __init__(self):
                super().__init__()
                self.value = None

            @nextcord.ui.button(label='Ready', style=nextcord.ButtonStyle.primary)
            async def connect_four_button(self, button: nextcord.ui.Button, interaction: nextcord.Interaction):
                self.value = 1
                self.stop()
``` and so on
cedar stream
mellow gulch
slate swan
#

but how i dont even know oabout mongo atlas

cedar stream
cedar stream
#

Find a guide

mellow gulch
#

But args are in innit function

cedar stream
#

You cant run innit if you dont have an instance

slate swan
#

wait but how the data base must looks like for that command

mellow gulch
cloud dawn
#

Why did you put the whole class in the init?

cedar stream
# mellow gulch

Yes, ok, that is a constructor, now create a new instance of this class

cedar stream
cedar stream
mellow gulch
#

I pit everything in that

cedar stream
#

That is not how It’ s done

mellow gulch
#

Ik ik

#

Gimme a sec

cedar stream
#

Innit is basically a function that gets called when u create new instance

#

So u kinda need an instance to run it

#

And if you try to define class methods in there it wont work

mellow gulch
#

do i do this to turn them into variables without the self. part

#

@cedar stream

cedar stream
#

self.bot = bot

#

Basically, self is an instance of this class

#

Read this

mellow gulch
#

but i dont wanna type out self.bot

cedar stream
mellow gulch
#

can i do

#
self.bot = bot
bot = self.bot```
cedar stream
#

No

#

Dont

mellow gulch
#

y it not work

#

ooo what about

cedar stream
#

Cus bot will only be accessible inside innit

#

Self.bot is instance variable

mellow gulch
#

m vicuh q4jnkae.fmdzxck oiq eul;ar.jkdfcm,va0pa9w;iloukj.,dermgscv v9pui;khj.WSRDFXC;HJK.WSDFCGYHPBKSD NZXC

cedar stream
#

Bot isnt

mellow gulch
#

oki then

cedar stream
#

You gotta do self.bot

#

If you want to make it an instance variable

mellow gulch
#

wait y it not working

cedar stream
unkempt canyonBOT
#

Hey @mellow gulch!

Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:

• If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)

• If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:

https://paste.pythondiscord.com

mellow gulch
#
class ConnectFour():
    def __init__(self, bot, msg, game_num, player1name, player1id, player2name, player2id):
        self.bot = bot
        self.msg = msg
        self.game_num = game_num
        self.player1name = player1name
        self.player1id = player1id
        self.player2name = player2name
        self.player2id = player2id

    view = ready_up_button()
    if self.game_num == 1:
        channel1 = self.bot.multi11channel```
#

I shortened it

cloud dawn
mellow gulch
#

So when it is activated

#

The class

#

That code will startup

cloud dawn
#

You don't have access to self like that.

mellow gulch
#

Right?

jade jolt
#

that would be in __init__ wouldn't it

#

that gets "ran" when you call the class

mellow gulch
#

Ohhhhhhhhhhh

#

So that means in that case

cloud dawn
mellow gulch
#

K ill watch

#

May be usefull to watch all of those

cedar stream
mellow gulch
#

All i know about coding is basically just one class of highschool

#

Lmao

jade jolt
#

!e

class abc:
    def __init__(self, x):
        if x == 3:
            print(x)
abc(3)
``` like this @mellow gulch
unkempt canyonBOT
#

@jade jolt :white_check_mark: Your eval job has completed with return code 0.

3
jade jolt
#

a hastily put together exame

#

example

mellow gulch
#

Ok thx

cloud dawn
#

I mean

#

!e ```py
class abc:
def new(self, x):
if x == 3:
print(x)
abc(3)

unkempt canyonBOT
#

@cloud dawn :white_check_mark: Your eval job has completed with return code 0.

3
jade jolt
#

that too

#

whats the difference

cloud dawn
#

Well they are kinda different.

cloud dawn
jade jolt
#

ah

#

interesting

manic wing
#

i like __call__

jade jolt
#

and that does..?

manic wing
#

means you can call a class

jade jolt
#

show a quick example in #bot-commands ?

cedar stream
cloud dawn
jade jolt
#

o

cedar stream
#

If you do instance(), it will execute whats inside __call__

cloud dawn
jade jolt
#

doesnt seem like it has a practical use to me^

jade jolt
#

tyvm

cloud dawn
#

!e ```py
class abc:
def init(self, x):
self.x = 3

def __call__(self):
    print(self.x)

obj = abc(3)

obj()

unkempt canyonBOT
#

@cloud dawn :white_check_mark: Your eval job has completed with return code 0.

3
slate swan
#

is there a way to get your bot to play music ive tried so many times but cant find out?

cloud dawn
slate swan
#

oh okay

cloud dawn
jade jolt
slate swan
jade jolt
#

!ytdl

unkempt canyonBOT
#

Per Python Discord's Rule 5, we are unable to assist with questions related to youtube-dl, pytube, or other YouTube video downloaders, as their usage violates YouTube's Terms of Service.

For reference, this usage is covered by the following clauses in YouTube's TOS, as of 2021-03-17:

The following restrictions apply to your use of the Service. You are not allowed to:

1. access, reproduce, download, distribute, transmit, broadcast, display, sell, license, alter, modify or otherwise use any part of the Service or any Content except: (a) as specifically permitted by the Service;  (b) with prior written permission from YouTube and, if applicable, the respective rights holders; or (c) as permitted by applicable law;

3. access the Service using any automated means (such as robots, botnets or scrapers) except: (a) in the case of public search engines, in accordance with YouTube’s robots.txt file; (b) with YouTube’s prior written permission; or (c) as permitted by applicable law;

9. use the Service to view or listen to Content other than for personal, non-commercial use (for example, you may not publicly screen videos or stream music from the Service)
slate swan
#

how come mee6

#

has it

cloud dawn
cedar stream
cloud dawn
sage otter
#

I mean if you have the music locally

jade jolt
#

^ if its non copyright iirc

cedar stream
sage otter
#

It isn’t

slate swan
#

how do i hide my token i tried doing it using .env but didnt work

sage otter
#

Music bots aren’t against discord tos. It’s the means of how the music bots get their music.

cloud dawn
jade jolt
#

true

cedar stream
jade jolt
#

if you download from non copyright sounds themselves its fine

sage otter
#

Fortunately YouTube has nothing today with local audio files AMshrug

cloud dawn
#

Find a website that does allow it :)
||I know some||

#

SECRETS

cedar stream
slate swan
#

like import load_dotenv

cloud dawn
cedar stream
cloud dawn
slate swan
#

now do i wanna put that in .env or should i put it in my main bot folder with all the other import

cedar stream
#

And u do load_dotenv(path)

cedar stream
cedar stream
slate swan
#

yea i realized LOL

cedar stream
#

Python imports usually go into python files

#

In .env u only put TOKEN=gigegc77(5(74hjtdjydtt try h se

#

Or whatever u want

cedar stream
cloud dawn
#

I do recommend putting it in a string though.

cedar stream
#

?

cloud dawn
#

Yeah

#

@cedar stream you have been pretty active past days. Enjoying Christmas?

patent surge
#

@commands.command(alias="restrict") Why alias doesn't works ?

cloud dawn
#

aliases

#

It's a list

#

Or tuple.

velvet tinsel
#

It’s a list

#

And it’s aliases

cloud dawn
#

That is exactly what i told him.

slate swan
#

Wrong. It's an iterable object of string objects bigbrain

cloud dawn
#

It's the object discord.ext.commands.Command.aliases that is called aliases it's a list of aliases the command can be invoked under. The type of the kwarg being a union of list and a tuple containing strings.

visual island
slate swan
#

Smh statically typed code be like

unkempt canyonBOT
#

discord/ext/commands/core.py line 329

if not isinstance(self.aliases, (list, tuple)):```
cloud dawn
#

oof

slate swan
#

Statically typed code 💔

#

It's fine because I like doing the same for every single function I make Pepe_Laugh

pliant gulch
#

It would be quite easy to implement Iterable[str] here instead of only supporting list and tuple

velvet tinsel
slate swan
cloud dawn
#

There is loads of old code.

velvet tinsel
#

dont bothering at all lol

#

he stopped production

slate swan
velvet tinsel
slate swan
velvet tinsel
#

you got nitro

slate swan
velvet tinsel
#

:kek:

pliant gulch
slate swan
#

Shit not O(n) and O(1) thing again

#

My brain too dumb for that notlikeduck

pliant gulch
#

get_channel can be O(1) since channel doesn't require to be accessed through a Guild

#

There should be no reason why get_channel should O(n)

slate swan
#

Understood from the 2nd example more than from the 1st ngl

slate swan
pliant gulch
#

Yes, that isn't O(1)

slate swan
#

Oh

pliant gulch
#

That's O(n), like I said

slate swan
#

Then I still didn't understand it notlikeduck

pliant gulch
slate swan
pliant gulch
#

It CAN be O(1), just that danny decided not to make it O(1)

slate swan
#

I c sus

pliant gulch
#

Channels are accessed through the official API via channels/channel_id not guilds/guild_id/channels/channel_id

#

That's why you can just smack a global cache of channels

visual island
#

why not? It will improve the performance of the lib

pliant gulch
#

And if you were to set a key in the dict via the channel's ID

#

You can use dict's getitem

#

Which is O(1)

pliant gulch
#

get_channel was the first get_ method from what danny said

slate swan
#

I c feelsthinkman

visual island
#

and why if it's old?

#

it wont require some "big" changes

pliant gulch
#

You'd need to ask danny ¯_(ツ)_/¯

slate swan
cloud dawn
#

cache system is kinda bad but no one bothers to change it.

pliant gulch
#

Don't even get me started on the message cache lmao

#

That shit is O(n) as well when it can be O(1)

cloud dawn
pliant gulch
#

One of the things to influence myself to make my own wrapper

#

My message cache is O(1) getitem

cloud dawn
#

Will increase ram by some amount.

pliant gulch
#

Depends on the max amount

#

It's acts like a deque but it's also a dict

#

So it will never go over a certain amount of ram usage

#

Do keep in mind though since OrderedDict is implemented in python its slowing than a regular dict, that being implemented in C

#

Although if I have time I will just write my own Cache in C and implement that to the wrapper

cloud dawn
#

Is this not made in Python 3.10?

pliant gulch
#

What?

unkempt canyonBOT
#

lefi/state.py line 83

def __setitem__(self, key: Union[int, str], value: T) -> None:```
pliant gulch
#

No 3.9

slender perch
#
Traceback (most recent call last):
  File "main.py", line 11, in <module>
    async def on_ready(ctx):
TypeError: event() missing 1 required positional argument: 'coro'

my code

import discord
import asyncio as asyncio
import os
from getpass import getpass
from discord.ext import commands
from discord.ext.commands import Bot

token = getpass("token: ")

@Bot.event
async def on_ready(ctx):
  for member in ctx.guild.members:
      if member.name.startswith("!"):
          await member.edit(nick="fart lol")
patent lark
#

on_ready doesnt take any parameters

#

you cant pass commands.Context to discord.on_ready()

slender perch
#

how would i get the ctx.guild.members to work then?

patent lark
#

grab the guild object using the bot instance and iterate through the members

#

bot.get_guild()

#
guild = bot.get_guild(pass the guild id)
for item in guild.members:
  #code```
slender perch
#

and im assuming i would replace pass the guild id with the actual server id?

patent lark
#

yep

slender perch
#

but what if i want it to do it for every server its in

patent lark
#

iterate through bot.guilds

#

!d discord.ext.commands.Bot.guilds

unkempt canyonBOT
patent lark
#

change multiple users nicknames in many guilds is good bit of API requests though

slender perch
#

im a bit stupid, do i put the bot.guilds in the ()?

patent lark
#

iterate through bot.guilds using a for loop

for guild in bot.guilds:
  #code```
#
@bot.event
async def on_ready():
  for guild in bot.guilds:
    #code```
slender perch
cloud dawn
#

!indention

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

patent lark
#

you need to define member

#

it needs to be the member object

#

and in your case, it would be Bot.guilds not bot.guilds

slender perch
#

im sorry im a bit slow but

patent lark
#

for member in guild.members:

#

actually

cloud dawn
#
for member in [member for member in [guild.members for guild in Bot.guilds] if member[0] == "!"]:
    await member.edit(nick="yes")
patent lark
#

yikes

slate swan
cloud dawn
#

Ye lol

slender perch
#

this is my code and error based on what panda sent

#

and this is my code and error based on what im proccessing from snow

cloud dawn
#

This will never work lol

patent lark
#

xd

wispy spade
slate swan
#

yesh

patent lark
#

you need a bot constructor xd

slender perch
#

cuz im broke asf

patent lark
#

bot = commands.Bot(command_prefix="!")

#

in the most simple way, you need this

slender perch
#

ooooh, i forgot that

patent lark
#

there is much more you can do with the kwargs of the bot constructor. but thats as simple as it gets

#

!d discord.ext.commands.Bot

unkempt canyonBOT
#

class discord.ext.commands.Bot(command_prefix, help_command=<default-help-command>, description=None, **options)```
Represents a discord bot.

This class is a subclass of [`discord.Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") and as a result anything that you can do with a [`discord.Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") you can do with this bot.

This class also subclasses [`GroupMixin`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.GroupMixin "discord.ext.commands.GroupMixin") to provide the functionality to manage commands.
pliant gulch
unkempt canyonBOT
#

for ... in get_all_members()```
Returns a generator with every [`Member`](https://discordpy.readthedocs.io/en/master/api.html#discord.Member "discord.Member") the client can see.

This is equivalent to:

```py
for guild in client.guilds:
    for member in guild.members:
        yield member
slender perch
patent lark
#

smh

sick birch
#

high chance of you getting disconnected and there's nothing you can do about it

patent lark
#

you're mixing them up with the lower and uppercase b

wispy spade
slender perch
#

fucking

sick birch
#

on_ready just happens to be when your websocket recieves all the GUILD_CREATE event from the gateway

slender perch
#

one sec

patent lark
#

your bot instance isnt being used still

sick birch
#

nah its good

#

Also you're going to get rate limited insanely quickly

#

Depending on how many members there are of course but still

patent lark
#

yeah i also said that lmao. but they will do as they wish

sick birch
#

¯_(ツ)_/¯

wispy spade
#

oh well

slender perch
#

this is the best way i could think of doing it

#

im dumb asf

patent lark
#

thats the worst way actually

slender perch
patent lark
#

if you made it into a command instead. there would be no worries of getting disconnected from the API via clogging the request to verify your bots login in on_ready, just getting ratelimited from sending too many API requests would be the worry

#

i dont see any pros to this, actually.

wispy spade
#

this might be better off as a manual action (as in a command that only checks that guild) or using one of the member_* events so it's only triggered on a direct member action

patent lark
#

^

slender perch
#

ah alright

#

but also, how do i add a cooldown to the command too

patent lark
#

i forgot the doc to that

#

is it just commands.cooldown? @cloud dawn

wispy spade
#

!d discord.ext.commands.cooldown

unkempt canyonBOT
#

@discord.ext.commands.cooldown(rate, per, type=discord.ext.commands.BucketType.default)```
A decorator that adds a cooldown to a [`Command`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Command "discord.ext.commands.Command")

A cooldown allows a command to only be used a specific amount of times in a specific time frame. These cooldowns can be based either on a per-guild, per-channel, per-user, per-role or global basis. Denoted by the third argument of `type` which must be of enum type [`BucketType`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.BucketType "discord.ext.commands.BucketType").

If a cooldown is triggered, then [`CommandOnCooldown`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.CommandOnCooldown "discord.ext.commands.CommandOnCooldown") is triggered in [`on_command_error()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.discord.ext.commands.on_command_error "discord.discord.ext.commands.on_command_error") and the local error handler.

A command can only have a single cooldown.
patent lark
#

yep lol

slender perch
#

ah alright

#

thamks

patent lark
#

👍

strong sluice
#

superidol bot

slate swan
#

can someone send me the source code of the discord member class

cloud dawn
patent lark
#

oops

cloud dawn
#

speed

patent lark
#

didnt realize you already sent it lol

cloud dawn
#

Even gave him the lines

stuck parrot
#

Hi, I want to be able to change the value of alarm using discord and send the message to discord when price is lower than alarm. This is part of my code:

alarm= 0.20
#change the price alarm with discord

while True:

price = driver.find_element_by_css_selector(".last")

print(price.text)

if float(price.text) <= float(alarm):
print(price.text)
#send message to discord
time.sleep(3)
cloud dawn
stuck parrot
cloud dawn
stuck parrot
#

all right

#

but any idea of how I can do it??

cloud dawn