#discord-bots

1 messages ยท Page 638 of 1

velvet tinsel
#

discord-slash or disnake

maiden fable
velvet tinsel
#

hai kayle ๐Ÿ˜„

slate swan
pastel cobalt
#

can someone help me

maiden fable
boreal ravine
#

aight

upbeat otter
#

Why does discord have NSFW channels then

#

oof

boreal ravine
#
    async def send_cog_help(self, cog):
        coge = self.context.bot.get_cog(str(cog).title())
        title = coge.qualified_name or "No"
        await self.send_help_embed(
            f"{title} Category", coge.description, coge.get_commands()
        )
```  but I'm getting a `NoneType` issue though at `coge`
maiden fable
upbeat otter
boreal ravine
#

What

velvet tinsel
velvet tinsel
maiden fable
boreal ravine
maiden fable
maiden fable
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.

boreal ravine
velvet tinsel
#

coge sounds like a bad version of code or cogs

boreal ravine
#

it exists, my help command says so

velvet tinsel
#

or doge

upbeat otter
slate swan
#
from discord import Client, Intents, Embed
from discord_slash import SlashCommand, SlashContext

bot = Client(intents=Intents.default())
slash = SlashCommand(bot)

@slash.slash(name="test")
async def test(ctx: SlashContext):
    embed = Embed(title="Embed Test")
    await ctx.send(embed=embed)

bot.run("discord_token")

@maiden fable ? slash commands on d.py

velvet tinsel
maiden fable
upbeat otter
maiden fable
boreal ravine
velvet tinsel
#

disnake ๐Ÿ˜

maiden fable
velvet tinsel
#

hunter

maiden fable
#

Hm?

velvet tinsel
#

why is your pfp so cheerful

maiden fable
velvet tinsel
boreal ravine
maiden fable
#

Damn almost 23k messages in this channel alone ๐Ÿ˜

boreal ravine
#
    async def send_cog_help(self, cog):
        coge = self.context.bot.get_cog(str(cog).title())
        print(cog)
        print(str(cog).title())
        print(coge)
``` ^^^
boreal ravine
maiden fable
velvet tinsel
#

I need to learn cogs
wtf even are cogs

jade tartan
#

How do i make an embed underline a message?

velvet tinsel
slate swan
maiden fable
upbeat otter
maiden fable
upbeat otter
velvet tinsel
#

hi

maiden fable
velvet tinsel
#

ive got no messagess

jade tartan
#

Underline?

velvet tinsel
upbeat otter
velvet tinsel
maiden fable
upbeat otter
#

thats what most people do

maiden fable
#

I have also done that ngl

upbeat otter
#

everywhere

velvet tinsel
maiden fable
#

Actually a few times

#

5-6 times but this is OT so leave it haha

upbeat otter
#

I solemnly swear that I am upto no good

#

lmao

maiden fable
slate swan
#

i cannot acess nsfw channel bcoz I entered my real age which was under 16 lol

maiden fable
slate swan
#

didnt check recently

upbeat otter
waxen granite
maiden fable
maiden fable
upbeat otter
maiden fable
#

!ot if u wanna continue

unkempt canyonBOT
slate swan
#

you guys epic

velvet tinsel
#

hunter what have you done

upbeat otter
boreal ravine
#

How does it not recognize it's a cog? Is it because of the casting i did?

maiden fable
velvet tinsel
#

๐Ÿ™‚

velvet tinsel
#

`!ot

maiden fable
#

O

velvet tinsel
#

.!ot

upbeat otter
#

I needed an nsfw channel to make my insulting bot work ๐Ÿ‘€

velvet tinsel
#

i my code still aint finished
but who cares

#

it doesn't work anyways

maiden fable
#

I won't be surprised if a mod comes here and warns us all ๐Ÿ˜

slate swan
# boreal ravine but is it a cog though
async def command_callback(self, ctx, *, command=None):
        await self.prepare_help_command(ctx, command)
        bot = ctx.bot

        if command is None:
            mapping = self.get_bot_mapping()
            return await self.send_bot_help(mapping)

        # Check if it's a cog
        cog = bot.get_cog(command)
        if cog is not None:
            return await self.send_cog_help(cog)

when you use your help command , this function is called before everything , the first phase checks if its a command , and as you can see its using cog = bot.get_cog(command) , and your command variable is not in the same case as the cog , it does not call the send_cog_help function , hope i was clear

#

Lol

boreal ravine
slate swan
jovial plover
#

Is there a way to backup a server instead of using templates?

slate swan
#

yes its complex tho

jovial plover
#

I want to make my own

boreal ravine
jovial plover
maiden fable
tulip lily
#

oh sorry

#

Hello world

boreal ravine
tulip lily
slate swan
#

is this clear?

boreal ravine
tulip lily
tulip lily
maiden fable
slate swan
tulip lily
tulip lily
slate swan
# boreal ravine Very clear
        cog = bot.get_cog(command)
        if cog is not None:
            return await self.send_cog_help(cog)``` 
so do you not except the help command to call the `send_cog_help` function now , right?
boreal ravine
#

I guess

slate swan
#

thats what i meant , and if you change the command to command.lower() and the cog names to lower , it the help command becomes case insensitive

#

as in that case , the arg sent with help command would always be lower , and so are your cog names

boreal ravine
#

hm

manic wing
#

async def command(ctx, input:string): and then subclass string, the parent class being str. You just make it all lower

boreal ravine
#

So what do I gotta do to make my cogs case insensitive

#

๐Ÿ˜จ

manic wing
#

!e py class string(str): def __str__(self): return self.lower() def x(text:string): print(string(text)) x("HELLO")

#

aw

boreal ravine
#

that isn't lower

manic wing
unkempt canyonBOT
#

str.lower()```
Return a copy of the string with all the cased characters [4](https://docs.python.org/3/library/stdtypes.html#id15) converted to lowercase.

The lowercasing algorithm used is described in section 3.13 of the Unicode Standard.
boreal ravine
#

but the command is already lower

slate swan
boreal ravine
#

you said don't make change in the internals though

slate swan
#

i said its not recommended

boreal ravine
slate swan
#

unless you know what you are doing :p

boreal ravine
#

I don't

slate swan
#

well , it wont break anything

boreal ravine
slate swan
boreal ravine
#

so I should do that?

slate swan
#

yea just change line 839 from py cog = bot.get_cog(command) to py cog = bot.get_cog(command.lower())

spring flax
#

what format does message.created_at return?

slate swan
spring flax
slate swan
#

yea ig , gimme a second ill confirm

#

yes , same

spring flax
#

okay thanks

reef shell
boreal ravine
#

@slate swan guide me more please, this is my code

    async def send_cog_help(self, cog):
        the_cog_name = cog.qualified_name.title()
        the_new_cog = self.context.bot.get_cog(the_cog_name)

        if the_new_cog is not None:

            title = the_new_cog.qualified_name or "No"
            await self.send_help_embed(
                f"{title} Category", the_new_cog.description, the_new_cog.get_commands()
            )
``` how would I check if it isnt a command tho
reef shell
#

the 3rd line is unnecessary

boreal ravine
reef shell
#

the_new_cog

boreal ravine
#

why not

slate swan
reef shell
#

^

boreal ravine
reef shell
#

Covert to what

boreal ravine
#

because i did fun and the cog was Fun

#

just ignore the bot.get_cog part

reef shell
#

That doesnโ€™t change the value of cog param.

slate swan
#

did you do what i said , kayle?

boreal ravine
slate swan
#

so doing any changes inside your send_cog_help wont fetch the cog

boreal ravine
#

oh

#

so how do i make it

#

exist..?

slate swan
#

same capitalisation

reef shell
#

Get the cog in on_help_command_error

slate swan
#

or just try what i told

boreal ravine
boreal ravine
slate swan
#

I get this error "discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: object NoneType can't be used in 'await' expression" But the command still does what it's suppost to

reef shell
#

That's a way i could think of to get a cog with lowercase str

slate swan
#

๐Ÿคฆ what's so confusing in this ,

rename all your cogs in lower case

change line 839 from py cog = bot.get_cog(command) to py cog = bot.get_cog(command.lower())

In discord/ext/commands/help.py

slate swan
reef shell
#

bruh cring

boreal ravine
reef shell
#

is that a clown or whatcring

boreal ravine
#

your saying I should change something in discord/ext/commands/help.py

slate swan
boreal ravine
#

but I dont wanna edit the internal files

#

is there someway else I could do what I want

slate swan
#

there's a easy way , but is kinda weird

boreal ravine
#

alright

slate swan
#

are your cogs all in same capitalisation type?

#

like the first letter is capital for all and others in lower case

boreal ravine
#

PEP8 recommends capital class names

slate swan
#

you get a error like No command called {0} found. when you try to get help for cog in different case right?

velvet tinsel
#

Hi

velvet tinsel
#

Kayle, is your problem still unsolved?

#

Itโ€™s -2 here

#

Brrrr I hate England

slate swan
# boreal ravine Yes, I do.

so as sherlock said you can use the on_help_command_error thing , and check if the error is an instance of command_not_found

boreal ravine
#

hm

slate swan
#

the error is a string so you need to somehow get the command name from the string

velvet tinsel
slate swan
#

!d discord.ext.commands.HelpCommand.on_help_command_error

unkempt canyonBOT
#

await on_help_command_error(ctx, error)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

The help commandโ€™s error handler, as specified by [Error Handling](https://discordpy.readthedocs.io/en/master/ext/commands/commands.html#ext-commands-error-handler).

Useful to override if you need some specific behaviour when the error handler is called.

By default this method does nothing and just propagates to the default error handlers.
slate swan
#

and you can use bot.get_cog(<the cog name you got in error>.title()

#

since you have all cog names like first character as upper , and others lower , .title would work

#

and call send_cog_help from there

boreal ravine
#

hm

boreal ravine
# slate swan cog*

how would I access something local though

async def on_help_command_error(self, ctx, error):
  cog = self.bot.get_cog(ctx.command.name)

  the_cog = cog

async def send_cog_help(self, ctx, cog):
  ...
rocky mist
#

can some1 help???

velvet tinsel
#

๐Ÿ˜‚

#

Bro

#

Learn discord py

rocky mist
quick gust
rocky mist
#

but like why?

velvet tinsel
#

๐Ÿคทโ€โ™‚๏ธ

rocky mist
#

im not that dumb

quick gust
rocky mist
#

lmao

quick gust
#

its discord.ext not .py

velvet tinsel
quick gust
rocky mist
#

i accidentally deleted all the imports

#

and it happened

quick gust
#

so

velvet tinsel
#

๐Ÿ’€

slate swan
#

AttributeError: 'Client' object has no attribute 'command'

velvet tinsel
#

What

quick gust
#

you see, have imported commands not command

#

do this,

from discord.ext.commands import command

velvet tinsel
quick gust
quick gust
velvet tinsel
#

๐Ÿ˜ญ I donโ€™t have my pc

rocky mist
slate swan
quick gust
#

you need to do the same thing I said to vapure

quick gust
velvet tinsel
#

has discord py done something

rocky mist
boreal ravine
quick gust
rocky mist
velvet tinsel
#

I do that and it work

boreal ravine
velvet tinsel
#

For my code

#

My for loop still doesnโ€™t work

boreal ravine
velvet tinsel
#

Iโ€™ll have to ask my dad

quick gust
boreal ravine
quick gust
#

from discord.ext.commands import command

#

i literally gave u the raw import

velvet tinsel
rocky mist
#

still

boreal ravine
quick gust
#

brooooo

boreal ravine
#

๐Ÿ’€

quick gust
#

this guy has two discord.ext.commands

boreal ravine
quick gust
#

just combine them ๐Ÿ˜‚

velvet tinsel
rocky mist
#

@quick gust

#

are you a troller or anythin?sxyhodor

velvet tinsel
#

@quick gust is good guy

quick gust
#

fs

velvet tinsel
#

He wonโ€™t troll like me

quick gust
#

ffs, why did u remove ur first one.......

velvet tinsel
#

What does fs mean

quick gust
#

ffs*

velvet tinsel
#

What does that mean

#

Iโ€™m bad at abbreviations

quick gust
#

just do this man for god's sake,

from discord.ext.commands import command```
quick gust
velvet tinsel
#

Sweet

rocky mist
velvet tinsel
#

Iโ€™m just going to watch this

rocky mist
#

i know im dumb so ok?

velvet tinsel
#

I wish okimii was here

quick gust
#

holy shit

#

i cant be arsed

velvet tinsel
#

Did he declare client twice?

quick gust
#

sarthak is here he'll help

slate swan
velvet tinsel
#

Oh

velvet tinsel
quick gust
#

yeah i think

quick gust
slate swan
#

AttributeError: 'Client' object has no attribute 'command'

velvet tinsel
#

Thank infernum

boreal ravine
#

Wait @slate swan

#

should I make the on_command_error in the class?

#

on_help*

slate swan
#

Use Bot instead

#

With Client you are limited to events and similar

#

See the difference here:

#

So you need

bot = commands.Bot(...)

instead of

client = Client(...)
#

At the top of your file

boreal ravine
#

Where'd you get that image

#

@slate swan Can I put on_help_command_error anywhere? Does it work with subclassed help commands?

boreal ravine
#

isn't working for some reason

slate swan
#

show code

boreal ravine
#

i put it in my bot class if thats ok

slate swan
#

nu , its a method of HelpCommand object

boreal ravine
#

hm

#

aight br

#

@slate swan doesn't change

#
    async def on_help_command_error(ctx, error):
        await ctx.send("no")
``` ^^^
#

wait i missed self

#

oops

#

Wait, it still doesn't work if I put self inside

#

:(

slate swan
tall canopy
#

helllllo how to make the bot mobile status

slate swan
#

you cant

tall canopy
#

em okkk thanks

slate swan
#

how do I add this feature in my discord bot?

#

this comes whenever you click on the discord bot profile

boreal ravine
#

go to url or something mess around with it and it should pop up

boreal ravine
boreal ravine
slate swan
#

oh

boreal ravine
# boreal ravine yeah im certain

my class looks like this

class HelpCommand(...):
  def __init__(self):
    ...
  async def on_help_command_error(ctx, error):
    ...
```^^^
reef shell
# slate swan how do I add this feature in my discord bot?

How to get the Add to server button to your bot's profile:

Article: https://discord.com/blog/discord-bots-and-app-discovery-announcement

https://cdn.discordapp.com/attachments/381963689470984203/910617928615989308/Screenshot_20211118_015023.png

Discord Developer Portal

Integrate your service with Discord โ€” whether it's a bot or a game or whatever your wildest imagination can come up with.

velvet tinsel
#

Sherlock

#

Hai

shadow wraith
#

can someone show me an example of how to list all people with a specific role

#

hello?

open wraith
#

this could help

unkempt canyonBOT
open wraith
#

essentially u need to make use of ctx.message.server.members and if role in <current-member>.roles

slate swan
#

no need to do that , just role.members would be enough.

open wraith
#

ah

slate swan
#

and ctx.message.server aint a thing ,its guild

open wraith
#

right it changed to guild

shadow wraith
#

can you show example

#

h

open wraith
#

ctx.guild.members would give you the members of a guild/server and u can iterate through it like for each_member in ctx.guild.members and see if each_member.roles matches ur role?

pliant gulch
#

That is really inefficient compared to just using specific_role.members

#

Granted that specific_role is a discord.Role object

open wraith
#

ah, i didnt know that

maiden fable
#

How's lefi going on?

open wraith
#

so ctx.guild.roles?

pliant gulch
#

Guild.roles would be a list of all roles

#

You want what Sarthak said

inland crest
#

hi

pliant gulch
inland crest
#

i am new

#

how are you all?

#

wht is lefi

visual island
#

Hey, is it possible to make something like typing.Optional with custom converter where it passes the value to the next arg if the value type isn't the type given?

maiden fable
open wraith
#

oooh https://github.com/an-dyy/Lefi this urs?

pliant gulch
#

Yea it is

#

And yes its the most boring part

#

I can't do anything cool till I finish docs

open wraith
#

what does it do
smthn like pprint?

maiden fable
#

Lmao facts

#

It's boring to write docs ;-;

pliant gulch
inland crest
#

i only know ||print '' Hello World ''||

#

lol

pliant gulch
#

Python 2 syntax ๐Ÿค”

maiden fable
unkempt canyonBOT
#
Resources

The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.

open wraith
maiden fable
#

b

#

Anyways, mind explaining more?

velvet tinsel
#

c

#

,!ot

#

!ot

visual island
velvet tinsel
#

Hai icy

#

Pycharm professional ๐Ÿ˜ญIโ€™m jealous

maiden fable
maiden fable
visual island
#

so, I have

class Literal(Converter):
    """A class for custom Literal"""
    values: tuple[str, ...] | str

    def __class_getitem__(cls, item):
        self = cls()
        self.values = item
        return self

    async def convert(self, ctx, argument):
        """Converts the argument to any of the exact value given"""
        if argument in self.values:
            return argument
        raise UnexpectedArgument(f"\"{argument}\" is not a valid argument. "
                                 f"Possible argument(s): {', '.join(self.values)}")


```this thing here, so the problem is that I want to make this as a merge of `typing.Literal` and `typing.Optional`. But the problem is `ctx.args` returns an uncomplete list. Due to the fact that the args isn't processed yet. How to implement `typing.Optional` here though?
velvet tinsel
#

Oh

visual island
#

probably a secret function like ctx.redirect_args() or something?

#

idk

velvet tinsel
#

I donโ€™t know Iโ€™ll leave it to Hunter

#

๐Ÿ˜ญ๐Ÿ’€Iโ€™m dumb

maiden fable
maiden fable
pliant gulch
#

You can do this through get_context afaik

maiden fable
maiden fable
pliant gulch
#

View iirc its called holdon

#

This is created along with Context

#

And it handles arg parsing

#

If you override this with your own class or subclass this

#

You can set an instance var for the last arg

#

If its not isinstance

maiden fable
#

Wait, wtf is even this ๐Ÿ˜ญ

pliant gulch
#

And replace the next, by changing index

pliant gulch
#

I have one for lefi but its a lot more compact

maiden fable
#

O, gonna read your source so that I don't lose my sanity

pliant gulch
visual island
#

and where should I pass the class?

pliant gulch
visual island
unkempt canyonBOT
#

discord/ext/commands/bot.py line 934

view = StringView(message.content)```
pliant gulch
#

Yea it is in get_context

maiden fable
#

So what's the use of this parser?

visual island
pliant gulch
#

It parses args from a string

maiden fable
#

(I know I am dumb)

maiden fable
pliant gulch
visual island
#

okay it's much complicated than i thought

pliant gulch
visual island
#

oh, anyways will subclassing Greedy do something?

hard mirage
#

is anyone in here a good bot developer?

pliant gulch
maiden fable
#

I get the message content, zips the args and kwargs from the message and I just pass those to the function

pliant gulch
hard mirage
#

i mean discord bots

visual island
maiden fable
hard mirage
#

ok

pliant gulch
maiden fable
hard mirage
#

does anyone want to help my friend with his server?

#

by coding bots

maiden fable
#

It's a hackery implementation but since it's a private wrapper/code, I don't really care haha

maiden fable
pliant gulch
#

Either way I think you have to use iteration and inspect.signature

maiden fable
pliant gulch
#

Compare it with the list of arguments

maiden fable
hard mirage
#

i wrote in general what we need

visual island
maiden fable
#

I use func.__code__ to get the number of args

maiden fable
visual island
pliant gulch
maiden fable
visual island
unkempt canyonBOT
#

discord/ext/commands/converter.py lines 993 to 994

origin = getattr(converter, '__origin__', None)
args = getattr(converter, '__args__', ())```
maiden fable
#

Okay okay calm down, sorry

pliant gulch
maiden fable
#

Ah that's the problem. I ain't converting to the type hinted type, I am passing raw strings

pliant gulch
unkempt canyonBOT
#

@pliant gulch :white_check_mark: Your eval job has completed with return code 0.

(<class 'str'>, <class 'NoneType'>)
boreal ravine
unkempt canyonBOT
#

discord/ext/commands/core.py line 580

async def _transform_greedy_pos(self, ctx: Context, param: inspect.Parameter, required: bool, converter: Any) -> Any:```
boreal ravine
#

why is everybody making a wrapper smh

visual island
#

I'm just a casual bot coder CH_ThumbsUpSmile

maiden fable
#

Lmao

boreal ravine
#

I meant andy ofc

#

Can anyone help me now?

#

My on_help_command_error isn't working for some reason...

#

It keeps getting replaced with this instead of my on_help_command_error

maiden fable
#

I think that's triggered whenever there's an error in sending like lacking perms

boreal ravine
#

it's for the help command

maiden fable
boreal ravine
#

!d discord.ext.commands.HelpCommand.on_help_command_error

unkempt canyonBOT
#

await on_help_command_error(ctx, error)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

The help commandโ€™s error handler, as specified by [Error Handling](https://discordpy.readthedocs.io/en/master/ext/commands/commands.html#ext-commands-error-handler).

Useful to override if you need some specific behaviour when the error handler is called.

By default this method does nothing and just propagates to the default error handlers.
maiden fable
#

command error handler

#

This is for those errors like Missing Permissions

boreal ravine
#

it has admin

maiden fable
boreal ravine
#

What

slate swan
#

kayle man stuck with the help thingy ๐Ÿ˜”

maiden fable
#

I am telling u when that function will be called. it will be called when the bot won't have send message perms in the channel, for example

slate swan
#

btw kayle , any reason for you to not name cogs in lower case?

unkempt canyonBOT
#

PEP 8 is the official style guide for Python. It includes comprehensive guidelines for code formatting, variable naming, and making your code easy to read. Professional Python developers are usually required to follow the guidelines, and will often use code-linters like flake8 to verify that the code they're writing complies with the style guide.

More information:
โ€ข PEP 8 document
โ€ข Our PEP 8 song! :notes:

boreal ravine
#

๐Ÿ™‚

slate swan
boreal ravine
slate swan
#

it takes a name kwarg too

boreal ravine
#

I wanna make my cogs case sensitive

boreal ravine
maiden fable
#

Yea...

slate swan
#
class Mycog(commands.Cog , name = 'my cog name')```
slate swan
boreal ravine
#

Like if the class name was cog but the name was Cog and we did cog would the command work

pliant gulch
#

Following pep8 correctly it would actually be MyCog

slate swan
slate swan
boreal ravine
#

yes

#

if we did both cog and Cog would it work

slate swan
#

it will get registered as Cog so only that will work

boreal ravine
#

bruh

pliant gulch
#

It wouldn't work in native python as it would say Cog is undefined while using cog

#

It only works in discord.py where it finds a Cog by the name, cog

slate swan
#

yea

pliant gulch
#

No only Cog as it was the name passed

slate swan
#

oh yea , sorry i said the opposite

slate swan
#

rename all your cogs in lower case

change line 839 from py cog = bot.get_cog(command) to py cog = bot.get_cog(command.lower())

In discord/ext/commands/help.py

slate swan
boreal ravine
unkempt canyonBOT
#

classmethod datetime.utcnow()```
Return the current UTC date and time, with [`tzinfo`](https://docs.python.org/3/library/datetime.html#datetime.datetime.tzinfo "datetime.datetime.tzinfo") `None`.

This is like [`now()`](https://docs.python.org/3/library/datetime.html#datetime.datetime.now "datetime.datetime.now"), but returns the current UTC date and time, as a naive [`datetime`](https://docs.python.org/3/library/datetime.html#datetime.datetime "datetime.datetime") object. An aware current UTC datetime can be obtained by calling `datetime.now(timezone.utc)`. See also [`now()`](https://docs.python.org/3/library/datetime.html#datetime.datetime.now "datetime.datetime.now").

Warning

Because naive `datetime` objects are treated by many `datetime` methods as local times, it is preferred to use aware datetimes to represent times in UTC. As such, the recommended way to create an object representing the current time in UTC is by calling `datetime.now(timezone.utc)`.
slate swan
#

\t <- what's this for

sullen shoal
#

basically same as hitting tab

#

!e

print("def h:\n\tprint(1)\n\tprint(2)")
slate swan
#

Ah i see

unkempt canyonBOT
#

@sullen shoal :white_check_mark: Your eval job has completed with return code 0.

001 | def h:
002 | 	print(1)
003 | 	print(2)
slate swan
#

Thx

obsidian ledge
#

can someone tell me how i make a bot that detects how much a user has clicked a button? like if a button has been sent 5 times and its the same button and a user clicked it 3 times and another use clicked it 2 times how do i make the bot show the total amount each of the user have clicked it?

sullen shoal
#

make a dict, handle the callback, the key would be the id

#

if the key doesnt exist, set it to 0

obsidian ledge
#

can u show me a code example?

sullen shoal
#

i wrote smth similar to this yesterday, not exactly what you want but should help

#

i dont think it will help, gotta give some new example wait

#
d = {}
def callback(author):
  if author in d:
      d[author] += 1
  else:
      d[author] = 0
#

smth like this

#

you understood?

#

the dict then will contain all the users with how many times they clicked as the value

#

d[author] += 1
if that doesnt work,
d[author] = d[author] + 1 should work

obsidian ledge
#

is it supposed to look something like this?

#

im kinda new to coding so i dont really know alot of stuff

sullen shoal
#

well thats not gonna work just by copy pasting the entire thing and hoping it to work

#

button_callback
the name says it all

#

the dict has to be an attribute of your discord.ui.View subclass

#

as in my code, while initializing it should be an empty dict

#

im not going to explain that much because you are not supposed to be making discord bots until you know enough about python and OOP to understand what im currently saying

obsidian ledge
#

okay

sullen shoal
#

consider learning about classes, OOP and decorators (spend atleast 2 weeks practicing these)

sullen shoal
#

: |

slow fog
#

do you have your own discord sever

sullen shoal
#

no, why you asking tho

slow fog
#

s

magic ore
#

!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
sullen shoal
#

tbh i skipped that thing when i was checking the docs of collections

slow fog
#

myxi do you have a nice pfp to use

sullen shoal
slow fog
#

Sus

#

oh thats like your pfp

#

cool

boreal ravine
#

Imagine not using the default profile picture

sullen shoal
#

dont like that thing anymore, discord made it shit

slow fog
#

yea exactly

#

the icon

boreal ravine
slow fog
#

The current one

sullen shoal
#

compare it with the old one

slow fog
#

yes

boreal ravine
slow fog
#

Lol

sullen shoal
#

discord redesigned their logo some time ago

boreal ravine
#

I honestly didn't realize it'd changed and I've been using this for a solid 5 months

slow fog
#

oh

#

thats why lol

boreal ravine
slow fog
#

No

boreal ravine
#

Which one then

slow fog
#

check the discord icon from 2017 or 2019

sullen shoal
#

look how shit the new one looks

slow fog
#

Yes

boreal ravine
#

honestly

#

it's just a small detail change

#

smh

sullen shoal
#

: |

umbral dome
#

Helllppp

#

I can defined user

slow fog
umbral dome
#

I want to do send.user

slow fog
#

lol

umbral dome
#

to send the person using the bot a dm message

tawdry perch
#

member.send("message")

#

oh wait

#

the command author?

slow fog
umbral dome
#

yes

#

I want to send it to the author

tawdry perch
#

ctx.author.send("message") to send it to author

umbral dome
#

Thanks alot

tawdry perch
#

np

umbral dome
#

Diden work

#

It just diden send

slate swan
#

Use a try and except

tawdry perch
#

show code?

#

and does the user has DMs enabled

umbral dome
slate swan
#

Depends if the author has dms on but that too

tawdry perch
umbral dome
slate swan
#

Await it

umbral dome
#

okay to sek

slate swan
tawdry perch
#

I'm fast

slate swan
#

Me tooyert

tawdry perch
#

I nearly made a succesfull copy of defcon but it fked up

slate swan
#

jam_cavedude ๐Ÿ˜ญ

tawdry perch
#

just atleast 1 error that I have not yet figured out ;-;

slate swan
#

๐Ÿ˜”

#

Damn

boreal ravine
boreal ravine
tawdry perch
#

!src defcon

unkempt canyonBOT
#
Command: defcon

Check the DEFCON status or run a subcommand.

Source Code
tawdry perch
boreal ravine
#

error

tawdry perch
boreal ravine
#

wait

#

whats defcon though

maiden fable
tawdry perch
#

may I explain it in the help channel?

maiden fable
#

Sure, ig

boreal ravine
#

Python Defense Mechanism

velvet tinsel
#

Okimii

#

Hai jam_cavedude

#

I need help

#

๐Ÿ˜ญ

boreal ravine
#

๐Ÿ˜จ

maiden fable
velvet tinsel
#

pls

maiden fable
velvet tinsel
#

figure it out yoursel-nah, just kidding

#

you won't kill me if I reveal the fact that I'm using json as a db?

#

๐Ÿ˜ฆ

maiden fable
velvet tinsel
#

ok

#

when I do ;use laptop it says you don't own this item!

#

it's from the big first if statement

#

when I do ;use phone it completely ignores me

hollow mortar
#

hey any one good with visual studio

#

there is something is aw in yt video

velvet tinsel
hollow mortar
#

kk ty

velvet tinsel
#

hunter u there ;-;

#

;-;

boreal ravine
#

Python so weird

#

!e

import asyncio

async def main():
  await function()

async def function():
  print("Hi")

asyncio.run(main())
#

hm

unkempt canyonBOT
#

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

Hi
slate swan
#

why is my exec code not sending its just printing it in terminal and not sending the results

slate swan
slate swan
# boreal ravine send it then?

just sends None in a embed but the error embed works
@bot.command()
async def val(ctx,*,code: str):
try:
vercode = code.strip("```").replace("py","",1)
embed0 = disnake.Embed(title="Terminal",description=exec(vercode))
await ctx.send(embed=embed0)
except Exception as error:
embed1 = disnake.Embed(title="Terminal",description=error)
await ctx.send(embed=embed1)

#

cant send it as a code block lmao

boreal ravine
#

hm

slate swan
#

it works fine btw it just sends None

#

but works in the terminal

boreal ravine
#

assign something to exec() function

#

and then use that var inside description

slate swan
slate swan
boreal ravine
#

show code

slate swan
#

alr

slate swan
# boreal ravine show code

only thing i changed

executation = exec(vercode)
        embed0 = disnake.Embed(title="Terminal",description=executation)
boreal ravine
#

hm

velvet tinsel
#

It's for pybot

#

๐Ÿ˜„

slate swan
#

yah

velvet tinsel
#

Im excited

#

...to edit your code

#

:)

slate swan
#

๐Ÿ™‚

velvet tinsel
#

๐Ÿ™‚

#

there's not enough colour, tho

slate swan
#

still dont know why it doesnt work

velvet tinsel
#

errr

#

let me check my bookmarks

#

here ^ this might help

#

;-; maybe

slate swan
#

im going to check it out

#

uses a api

#

rip

velvet tinsel
#

OK

#

;-;

brave flint
#

umm hello so im doing custom help

#

and i wanna like ?help class

#

so how i put the name and async def

velvet tinsel
#

errrr

#

elaborate

brave flint
velvet tinsel
#

you

brave flint
#

ok so how i elaborate it?

#

docs mybe?

velvet tinsel
#

err

#

just like write a transcript of what you want to happen

brave flint
#

huh

#

i cant get it

velvet tinsel
#

like this

slate swan
#

i made a spotify command and it doesnt work for me

velvet tinsel
#
me: !help
bot: something...
velvet tinsel
slate swan
#

from discord import Spotify

@client.command()
async def spotify(ctx, user: discord.Member = None):
if user == None:
user = ctx.author
pass
if user.activities:
for activity in user.activities:
if isinstance(activity, Spotify):
embed = discord.Embed(
title = f"{user.name}'s Spotify",
description = "Listening to {}".format(activity.title),
color = 0xC902FF)
embed.set_thumbnail(url=activity.album_cover_url)
embed.add_field(name="Artist", value=activity.artist)
embed.add_field(name="Album", value=activity.album)
await ctx.send(embed=embed)

velvet tinsel
#

ok

#

any errors?

slate swan
#

something like this is suppsoed to show

#

but for some reason it doesnt work

velvet tinsel
#

ok

#

what does it show?

slate swan
#

nothing

velvet tinsel
#

ok

slate swan
#

nothing in the main console aswell

velvet tinsel
#

maybe user.activities is False

#

make an else statement

#

and await ctx.send("nothing")

slate swan
#

didnt work

velvet tinsel
#

what does it send?

slate swan
#

nthing

velvet tinsel
#

the word nothing?

slate swan
#

nah

#

literally blank

velvet tinsel
#

oh

#

remove pass

#

you don't need it

slate swan
#

should be a return

brave flint
#

how to set embed value as none?

spring flax
brave flint
#

embed.add_field(name="?help class for classed command help", value=None, inline=False)

#

returned that

slow fog
#

Replace it with

value="",
#

or
''

#

its working for me

sullen shoal
#

!e print(eval("1+5"))

unkempt canyonBOT
#

@sullen shoal :white_check_mark: Your eval job has completed with return code 0.

6
slate swan
#

It does print but sends a result of None in a embed

sullen shoal
#

i already sent a working snippet some time ago i think

slate swan
sullen shoal
#

what youre currently doing is running this py file:

1+5```
#

which does nothing

slate swan
#

No no it works it just doesnt sends a result but sends a error but when it works it only prints it in the vsc terminal

#

Still confused about lambda lmao

sullen shoal
#

what was the code

brave flint
slate swan
# sullen shoal what was the code

@bot.command()
async def val(ctx,*,code: str):
try:
vercode = code.strip("```").replace("py","",1)
executation = exec(vercode)
embed1 = disnake.Embed(title="Terminal",description=executation)
await ctx.send(embed=embed1)
except Exception as error:
embed2 = disnake.Embed(title="Terminal",description=error)
await ctx.send(embed=embed2)

sullen shoal
#

what was the code you passed to it

slate swan
#

cant send it as a code block as it will be half one

slate swan
sullen shoal
#

value of code arg

slate swan
#
print("works")
#

does print it in the vsc terminal but it never prints it

sullen shoal
#

what was your expectation

slate swan
#

to send the results as a embed but it just sends None

sullen shoal
#

exec executed the code you passed to it
it will not return anything unless you do something i showed some while ago

#

what you did was calling the print statement

#

and it did it

#

!e

print("bot is running.")
exec("print('works')")```
unkempt canyonBOT
#

@sullen shoal :white_check_mark: Your eval job has completed with return code 0.

001 | bot is running.
002 | works
sullen shoal
#

thats basically what you did

slate swan
#

i see

sullen shoal
#

!e

print(eval("'hello'"))```
unkempt canyonBOT
#

@sullen shoal :white_check_mark: Your eval job has completed with return code 0.

hello
sullen shoal
#

because "hello" is an expression, eval will return the value of an expression

slate swan
#

jam_cavedude alr

#

Im still having a stroke ๐Ÿ˜”

sullen shoal
#

why

slate swan
#

This makes me have a stroke๐Ÿ˜”

sullen shoal
#

why tho

slate swan
sullen shoal
#

you can assign the value of the global variable to a local variable of the function then delete the global one with del keyword if thats the problem

slate swan
#

No it wasnt ๐Ÿ˜”

sullen shoal
#

i didnt even do any kind of maths there tho

slate swan
#

Ik im taking classes and algebra broke my brain :#

sullen shoal
#

oh

#

yeah that's kinda pain

slate swan
#

Yes it is

sullen shoal
#

but why you blaming my code cuz of it ๐Ÿ˜”

slate swan
#

๐Ÿ’€

sullen shoal
#

bruh

slate swan
#

Didnt mean to offend you๐Ÿ˜”

sullen shoal
#

i mean yeah there could be some other pro solutions like coding your own python interpreter to make it work but i thought thats gonna be easier

slate swan
#

No that's a better idea

sullen shoal
#

might aswell use code library

#

!d code

unkempt canyonBOT
#

Source code: Lib/code.py

The code module provides facilities to implement read-eval-print loops in Python. Two classes and convenience functions are included which can be used to build applications which provide an interactive interpreter prompt.

slate swan
#

No need im starting from scratch

#

About to do my own programming language

sullen shoal
#

great

slate swan
#

Yup

boreal ravine
#

๐Ÿ˜จ

tawdry perch
#

defcon be still broken ;-;

pliant gulch
boreal ravine
slate swan
sullen shoal
#

i think you should use code i think it will work great for it

slate swan
#

No need look at my process;
010101010111001010101

sullen shoal
#

nice

slate swan
#

Yupyert

sullen shoal
#

!e

import code

c = code.compile_command("print(hi)")
i = code.InteractiveInterpreter(locals=dict(hi="hello world!"))

i.runcode(c)```
unkempt canyonBOT
#

@sullen shoal :white_check_mark: Your eval job has completed with return code 0.

hello world!
sullen shoal
#

you may go with it, if you want

slate swan
sullen shoal
#

atleast somewhat better than exec

slate swan
#

a programming language made with python very pog

sullen shoal
#

i wonder how slow that's gonna be

#

c > python > then your language

#

perfect

pliant gulch
#

A python language made with python is gonna be comedically slow

boreal ravine
sullen shoal
#

c programming language

boreal ravine
#

Wait whats c made out of

#

if python is made out of c, whats c made out of

#

๐Ÿ˜จ

valid niche
#

python is just a concept

#

it's an idea

boreal ravine
valid niche
#

although the main implementation made by the PSF is CPython

#

which is written in C

boreal ravine
#

So whats C made out of?

sullen shoal
#

assembly afaik

valid niche
#

C is a programming lanuage

slate swan
valid niche
#

languages aren't made of anything

boreal ravine
slate swan
#

Like fast fast

valid niche
#

languages are just concepts, rules we set

velvet tinsel
#

@slate swan

valid niche
#

C is defined as this and that

velvet tinsel
#

Why did you use disnake

valid niche
#

python is defined as this and that

velvet tinsel
#

๐Ÿ˜ญ

sullen shoal
boreal ravine
valid niche
#

it's up to people to write something else that can IMPLEMENT these concepts

boreal ravine
#

๐Ÿค”

valid niche
#

it's just like english

valid niche
#

english is also a language

#

it's made of purely concepts and rules, it's not made of anything, it's not something you can see hold or touch

#

it's purely a concept, a set of rules

boreal ravine
tiny latch
#

seriously

valid niche
#

but it's going off topic

brave flint
slow fog
#

Thats weird

brave flint
#

idk why but im trying to do it again

maiden fable
#

Oh hi there seb! Long time no see

boreal ravine
brave flint
valid niche
#

this channel sometimes drives me insane

maiden fable
slow fog
# brave flint i tried use \u200 and bot crashed ๐Ÿ™‚

try this maybe

place = '' name = '' level = '' for x in character_list: place += x[0] + '\n' name += x[1] + '\n' level += x[2] + '\n' embed.add_field(name='Platz', value=place, inline=True) embed.add_field(name='Name', value=name, inline=True) embed.add_field(name='Level', value=level, inline=True) return await client.say(embed=embed)
#

kinda complicated lol

slow fog
#

oh

#

lol

brave flint
brave flint
#

trying use \n\u200

slow fog
#

oh

maiden fable
#

No

#

Old code iirc

slow fog
brave flint
tawdry perch
grim oar
#

It's old yeah

maiden fable
#

Novia, done with the docs for Lefi?

grim oar
#

No am not doing shit atm, exams ๐Ÿ˜ฉ

maiden fable
#

Lmao

maiden fable
#

๐Ÿ˜ณ

#

Nvm that was lame

grim oar
#

Im also having constipation so that's kinda correct

#

anyways ot

maiden fable
#

;-; yea

tawdry perch
#

I'm thinking of adding a log feature (better than old), what things I should log in server?

grim oar
#

messages

#

channel updates, member updates

tawdry perch
#

So basicially every single action I can think of?

dapper cobalt
grim oar
#

I mean I won't log presence update

tawdry perch
#

that will be a lot of stuff to send to channels in embeds

dapper cobalt
#

Webhooks.

tawdry perch
#

huh?

grim oar
#

Use webhooks

dapper cobalt
#

!d discord.Webhook

unkempt canyonBOT
#

class discord.Webhook```
Represents an asynchronous Discord webhook.

Webhooks are a form to send messages to channels in Discord without a bot user or authentication.

There are two main ways to use Webhooks. The first is through the ones received by the library such as [`Guild.webhooks()`](https://discordpy.readthedocs.io/en/master/api.html#discord.Guild.webhooks "discord.Guild.webhooks") and [`TextChannel.webhooks()`](https://discordpy.readthedocs.io/en/master/api.html#discord.TextChannel.webhooks "discord.TextChannel.webhooks"). The ones received by the library will automatically be bound using the libraryโ€™s internal HTTP session.

The second form involves creating a webhook object manually using the [`from_url()`](https://discordpy.readthedocs.io/en/master/api.html#discord.Webhook.from_url "discord.Webhook.from_url") or [`partial()`](https://discordpy.readthedocs.io/en/master/api.html#discord.Webhook.partial "discord.Webhook.partial") classmethods.

For example, creating a webhook from a URL and using [aiohttp](https://docs.aiohttp.org/en/stable/index.html "(in aiohttp v3.7)"):
dapper cobalt
#

Will prevent the bot from getting ratelimited if many guilds get so many updates at the same time.

tawdry perch
#

I have tried once but my brains can't handle this stuff

grim oar
#

Time to make it handle hehe

dapper cobalt
#

Ah. Gotta make a discordpy webhooks repository, then.

grim oar
tawdry perch
#

does it build a embed by default?

dapper cobalt
#

Anyhow, you've got this example.

from discord import Webhook
import aiohttp

async def foo():
    async with aiohttp.ClientSession() as session:
        webhook = Webhook.from_url('url-here', session=session)
        await webhook.send('Hello World', username='Foo')
grim oar
dapper cobalt
tawdry perch
#

sigh time to make a embed creator function

grim oar
#

ctx.send.

tawdry perch
#

that will be painful

#

How would I even implement one?

sullen shoal
#

embed creator?

tawdry perch
#
async def create_embed(title, description, field, value):
    embed = discord.Embed(title=title, description=description)
    embed.add_field(name=field, value=value)
```smth like this?
sullen shoal
#

i would've just subclassed discord.Embed

#

and add my methods that i want

#

or attrs

tawdry perch
#
class foo(discord.Embed)
``` do you mean this?
sullen shoal
#

yes

tawdry perch
#

!subclass

#

uh

sullen shoal
#

now it has all the attributes and methods of Embed, you can even use that to create your embeds

#

you wont see any difference

tawdry perch
#

how would that work? I can just import discord and use the embed from there as well and it would work the same way, right?

sullen shoal
#

to create an embed now you just gotta do embed = foo()
then embed.add_field() or whatever you want

tawdry perch
#

oh I see

#

that will be a lot of painful hours along this...

sullen shoal
#

i dont think thats gonna happen tho

#

what do you want to do

tawdry perch
#

build embeds for webhooks without needing to do it again every time

sullen shoal
#

add your own method to use the attributes you can do self.title and to call methods self.add_field()

#

basic OOP

tawdry perch
#

I suck at oop

sullen shoal
#

its useful for your life, you should learn it

tawdry perch
#

I have been doing it a bit, but not this much

#

so just smth like this? ```py
import discord

class factory(discord.Embed):
def init(self):
self.embed = factory()

async def mod_log(self, title, description, field, value):
    embed = self.embed(title=title, description=description)
    embed.add_field(name=field, value=value)
    return embed
sage otter
#

PEP8 doesnโ€™t like your class names.

#

Pls cap them.

sullen shoal
#

you have to pass *args, **kwargs to it

tawdry perch
#

to.. what?

sullen shoal
#

to the constructor of the parent class

tawdry perch
#

into the self.embed?

sullen shoal
tawdry perch
#

I'm confused I don't understand what you mean

sullen shoal
#

its something you will learn by OOP tutorials of python

#

im not going to explain OOP here