#discord-bots

1 messages Β· Page 996 of 1

slate swan
#

Yes

grim oar
#

Ok wait, I forgot the func name

slate swan
#

Ah shi 😭

grim oar
#

Wait.

maiden fable
#

uh

grim oar
#

!d inspect.getfullargspec

unkempt canyonBOT
#

inspect.getfullargspec(func)```
Get the names and default values of a Python function’s parameters. A
[named tuple](https://docs.python.org/3/glossary.html#term-named-tuple) is returned:

`FullArgSpec(args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults,
annotations)`
slate swan
#

Is inspect a library built in

#

Or do I have to install it

maiden fable
#

stdlib

slate swan
#

Ok

#

Oop

#

I have another problem, how could I get the function name from the command

#

Or the function object

grim oar
#

function.__name__

slate swan
#

That’s not the point πŸ’€

#

I’m getting a command from its name

#

Ok

#

How do I get a function by its name

maiden fable
#

Uh

grim oar
#

:loading:

maiden fable
#

You can use globals()

#

!d globals

unkempt canyonBOT
#

globals()```
Return the dictionary implementing the current module namespace. For code within functions, this is set when the function is defined and remains the same regardless of where the function is called.
grim oar
#

Or do you need command object by the function name?

maiden fable
#

not the command

slate swan
maiden fable
#

The bare function

grim oar
#

uh then yeah, globals

slate swan
#

How can I use that :MoyΓ  I:

grim oar
#

It returns a dict

slate swan
#

Of?

grim oar
#

globals()[func_name]

slate swan
#

Would that return a function object

maiden fable
#

yes

jade jolt
#

is there a way to check if someone is a server owner or the bot owner?

grim oar
#

!d discord.Guild.owner

unkempt canyonBOT
grim oar
#

I forgor the property for second one.

jade jolt
#

uhh

maiden fable
#

Bro

grim oar
#

ids

maiden fable
#

!d discord.ext.commands.Bot.owner_id

unkempt canyonBOT
grim oar
#

O

maiden fable
jade jolt
#

is there a way to combine it into one check?

maiden fable
#

It is a Client attr iirc, idk why not documented

#

Sure

grim oar
#

😩 haven't made discord stuff since a while

jade jolt
slate swan
#

the inspect thing isn’t getting the args I want πŸ’€

maiden fable
#

return ctx.author.id in (ctx.guild.owner.id, ctx.bot.owner_id)

jade jolt
#

ty ty

slate swan
#

FullArgSpec(args=['self', 'context'], varargs='args', varkw='kwargs', defaults=None, kwonlyargs=[], kwonlydefaults=None, annotations={'return': 'T', 'context': 'Context[BotT]', 'args': 'P.args', 'kwargs': 'P.kwargs'})

#

its returning this

maiden fable
#

mhm

#

Have fun

grim oar
#

Let's gooo gg

maiden fable
#

LMAOOOO

slate swan
grim oar
#

FullArgSpec.args

narrow grail
#

is latency in ms or something other?

maiden fable
#

ms

slate swan
narrow grail
maiden fable
#

Wait no

#

Multiply it by 1000

narrow grail
maiden fable
#

Thats sick

#

=D

grim oar
jade jolt
maiden fable
#

prolly laptop

narrow grail
slate swan
maiden fable
#

Bru

jade jolt
maiden fable
#

@narrow grail just get the free Oracle VPS

narrow grail
grim oar
maiden fable
#

U need a cc

#

@grim oar God

narrow grail
#

i paid with paysafecard

maiden fable
#

How u paying for hosting then

grim oar
maiden fable
#

Ah okay

maiden fable
grim oar
#

One of the piss colour gods in here

maiden fable
#

Lmao

grim oar
#

Totally not @elfin island

maiden fable
#

πŸ‘€

elfin island
#

evening

maiden fable
#

Evening

grim oar
#

Evening

jade jolt
#

Evening

maiden fable
#

Uh, night would be better

#

Already gonna be like 11

slate swan
grim oar
#

Yes, so ja ab.

elfin island
slate swan
slate swan
tacit token
#
from discord import Client, Intents, Embed
from discord_slash import SlashCommand, SlashContext
from discord.ext import commands
client = commands.Bot(command_prefix="!",intents=Intents.all())
slash = SlashCommand(client, sync_commands=True)
 
guild_ids = [924381291804258324]
 
@slash.slash(name="test", guild_ids=guild_ids)
async def test(ctx):
  await ctx.send("test")

client.run("")

Terminal:

-discord.errors.Forbidden: 403 Forbidden (error code: 50001): Missing Access
maiden fable
#

Wow

#

Anyways, add the application.commands scope

jade jolt
#

missing ending ]

maiden fable
#

That too

#

Uh prolly that is the issue

slate swan
# elfin island show your code
e = discord.Embed(title=f"{self.values[0]}", description=f"{bot.get_command(self.values[0].split('/')[0]).description}")
                e.set_author(name="Requested by " + interaction.user.display_name, icon_url=interaction.user.avatar.url)
                print(self.values[0].split('/')[0])
                e.add_field(name="Arguments", value=inspect.getfullargspec(globals()[self.values[0].split('/')[0]]))
                await interaction.message.edit(embed=e)
grim oar
#

How did that not syntax error

tacit token
maiden fable
maiden fable
#

the dropdown (select) selected values

slate swan
grim oar
#

Print that among us after global()

maiden fable
#

Lmao

elfin island
slate swan
maiden fable
#

BTW is it normal for an API to return a JSON this big?

tacit token
#

discord.errors.Forbidden: 403 Forbidden (error code: 50001): Missing Access

maiden fable
grim oar
#

print the stuff after global()

maiden fable
slate swan
#

😳

maiden fable
#

Then I am safe

slate swan
grim oar
#

What's happening

slate swan
#

its legit a simple ping pong bot

tacit token
slate swan
#

the bot turns online it can use the on_message event but not do anyting to commands

maiden fable
grim oar
#

Ah that process_command bullshit

maiden fable
slate swan
narrow grail
#

@maiden fable do you know what tracemalloc is? I need to enable it so that my ping command could work

elfin island
slate swan
#

( im not using on message rn i just used ti to check if bot was recieving content ) @maiden fable

maiden fable
maiden fable
maiden fable
#

add %20application.commands at the end

slate swan
narrow grail
maiden fable
jade jolt
grim oar
maiden fable
slate swan
slate swan
nova stag
#

need help

slate swan
#

rst?

grim oar
maiden fable
grim oar
maiden fable
slate swan
slate swan
maiden fable
slate swan
narrow grail
#

@maiden fable btw I did a mistake. I have a ping of 90ms. It's 0.09 not 0.9

maiden fable
#

Lol cool

slate swan
narrow grail
torn sail
maiden fable
grim oar
#

:loading: it shud work.

slate swan
torn sail
#

after a heartbeat

maiden fable
#

Eh, its actually the time bw heartbeat ack and heartbeat send (or smth)

#

Its the ws ping not the HTTP

torn sail
#

yeah not api

maiden fable
#

It still comes under API tho

torn sail
#

oh ok

#

i got my terminology wrong

maiden fable
#

Prolly I am wrong too, but eh

narrow grail
torn sail
#

yes

narrow grail
#

nice

maiden fable
#

Yea ws is also api

narrow grail
#

but how to get the other ping when sbot.latency is only websocket?

maiden fable
#

u cannot

elfin island
grim oar
narrow grail
elfin island
#

πŸ™‚

grim oar
#

I asked you that when we started

slate swan
grim oar
#

Omg

#

Let me show

elfin island
#

no nova we get your point lmao

narrow grail
#

@maiden fable

maiden fable
grim oar
#

πŸ₯Ί

maiden fable
#

@grim oar I relate to u πŸ«‚

slate swan
grim oar
#

😭 smh

slate swan
#

sorry nova πŸ™

grim oar
#

It gud

maiden fable
#

I just love it how everyone likes the answer a Helper gives πŸ‘€

#

(Not targeting u)

elfin island
#

there was a time when i wasnt yellow too πŸ™ƒ

grim oar
#

Anad is my joint bff

slate swan
#

and i have to keep all the splitting bullshit

slate swan
grim oar
#

we smoke together

maiden fable
maiden fable
grim oar
#

Then get high and do se*y stuff.

#

Yes

slate swan
#

!ot

unkempt canyonBOT
grim oar
#

Ok

elfin island
#

anyone made anything interesting with slash commands/interactions in general? some inspiration would be cool

maiden fable
maiden fable
grim oar
#

Who else needs help I will help

elfin island
#

😩 let's not be so pessimistic

maiden fable
maiden fable
grim oar
#

Yes, I help in variety of ways

maiden fable
#

And one of them involves pinging a helper

#

w o w

grim oar
#

He's like my (adopted) son

#

Who needs help I will help

elfin island
maiden fable
#

Never. Just use disnake/hikari

grim oar
#

When you want to synchronize the command tree, you know

maiden fable
#

Lmao

grim oar
#

The tree of commands need to be synchronized to work well

elfin island
#

insightful

grim oar
#

Thanks

slate swan
#
                db[f'lb{num}'] = role.name
                await ctx.respond(f"Set {num} to {role.name}")

how would i interate through the db and check if their is a value for each number?
e.g i assigned a role to number 1 and i assigned a number too role 3

maiden fable
#

@grim oar πŸ‘€

grim oar
#

I am a bit busy

slate swan
little ivy
#
global name
name = None
global id
id = None
global authorid
authorid = None
 
class Dropdown(discord.ui.Select):
    def __init__(self, client):
        self.client = client
        options = [
            discord.SelectOption(label="1", description="rolletje", emoji="πŸ“’"),
        ]
 
        super().__init__(
            placeholder="Select an option...",
            min_values=1,
            max_values=1,
            options=options,
        )
 
    async def callback(self, interaction: discord.Interaction):
        print("Callback hiero")
        if self.values[0] == "1":
            await client.add_r(authortje, "drol")
 
 
class DropdownView(discord.ui.View):
    def __init__(self, client):
        self.client = client
        super().__init__()
 
        self.add_item(Dropdown(self.client))
 
 
 
@client.slash_command(guild_id=[959432789164437604], name="selfrole", description="Take your roles")
async def selfrole(ctx):
    global name
    name = ctx.author.name
    global authorid
    authorid = ctx.author.id
    global authortje
    authortje = ctx.author
    global id
    id = ctx.guild.id
    view = DropdownView(client)
    await ctx.respond("**Selfrole menu**", view=view)
#

Hi guys! How can I add a role to someone, using the dropdown menu? I have this.

maiden fable
#

u need to use utils.get to get the role object with the name

hidden geyser
#

Hello, someone can help me with API Request, I need to get data from this json file :

[
    {
        "a": "a",
        "b": "b",
        "c": "c"
    },
    {
        "a": "a",
        "b": "b",
        "c": "c"
    },
    {
        "a": "a",
        "b": "b",
        "c": "c"
    }
]

I need to catch every "a" data

little ivy
#

Thats the description from the last line

cold oyster
#

After async def line make a new line and say '''Idk'''

little ivy
#

Not sure, test it out i'd say πŸ™‚

#

slash?

#

Like this

#

@client.slash_command(guild_id=[959432789164437604], name="suggest", description="Make a suggestion for the bot/server")

#

No idea how you can choose an account, sorry!

#

Dropdown like this?

#

Yeah

paper sluice
#

pithink if its valid python code, u can use it in any IDE

kindred drum
#

yo how do I get the id of the command message?
eg. the id of !help

slate swan
#

Anyone know how I'd respond to a button interaction by just editing the message?
The user clicks on a button, the message gets edited.

Like I just want to use :

    class Buttoning(View):
        def __init__(self):
            super().__init__(timeout=None)

        @button(emoji=myemoji, custom_id="button1", style=discord.ButtonStyle.grey)
        async def Button1(self, interaction: Interaction, press: Button):
            
            await interaction.message.edit("new msg")

However I get the "This interaction failed" msg on discord, is there any way I can like continue an interaction without actually having sent a response msg?

#

(I'm using the latest version of discord.py v2 btw)

paper sluice
#

interaction.response.edit_message(...)

slate swan
paper sluice
#

interaction.response calls the InteractionResponse class, look for that

slate swan
#

Great, thank you very much sir.

paper sluice
#

:)

slate swan
#

I got 1 more question, how do you disable a button?

paper sluice
#

button.disabled = True

#

!d discord.ui.Button.disabled

unkempt canyonBOT
south jetty
#

how can I run my bot online 24/7

slate swan
paper sluice
#
        async def Button1(self, interaction: Interaction, press: Button):

in this case u would type press.disabled = True

south jetty
#

how can I run my bot online

#

24/7

slate swan
#

like a vps or your pc

south jetty
slate swan
#

just like how u host website

#

:'/

south jetty
#

im not really a web developer

slate swan
#

neither me :>

sick birch
#

glad to see my example is helping people πŸ₯²

sick birch
paper sluice
sick birch
paper sluice
#

πŸ‘€ sick

south jetty
sick birch
#

Most good VPS aren't free

south jetty
sick birch
#

There are but they all suck

slate swan
# paper sluice ```py async def Button1(self, interaction: Interaction, press: Button): ...

It does not work for me, mind seeing if I overlooked something? This is my code simplified:



class Buttoning(View):
        def __init__(self):
            super().__init__(timeout=None)

        @button(emoji=myemoji, custom_id="button1", style=discord.ButtonStyle.grey, disabled=False)
        async def Button1(self, interaction: Interaction, press: Button):
            
            await interaction.response.edit_message("new msg")
            if this == that:
               press.disabled = True


view = Buttoning()
await ctx.send("hi", view=view)
await view.wait()

maiden fable
#

Laughs in Oracle

sick birch
#

Many reputable providers also have free tiers

south jetty
sick birch
#

I don't really count that as "free" though

#

Like hunter mentioned, oracle has a good free tier. So does AWS. Google cloud might as well

south jetty
#

Well im just 14 so I don't think I can pay for a vps 😒

paper sluice
sick birch
#

Oracle free tier does take $1 out of your CC to make sure its valid

#

AWS you just need a CC they don't take money

slate swan
sick birch
#

Yeah

paper sluice
slate swan
#

!e

print(1 == 1)
if 1 == 1:
    print(1)
unkempt canyonBOT
#

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

001 | True
002 | 1
slate swan
#

I think I might be doing wrong with the view.wait() since im not doing anything after that. I'm not sure though, I just recently switched to this version

paper sluice
paper sluice
slate swan
#

whats the problem?

paper sluice
#

the button is not being disabled apprently

slate swan
#

he probably forgot to edit the message with the current view lol

slate swan
slate swan
#

idk the default value of the kwarg but its probably falsey and would remove the view

#

you just need to send the view with the current state of the instance so it would be view=self

slate swan
#

youre welcomeπŸ’œ

mortal dove
#

is guild.categories in order of where they appear on the list for users? ie for this server would it be [information, news, lobby, ...] (As category objects ofc) or just in a random order?

slate swan
mortal dove
#

Aighty, thanks

slate swan
#

@slate swan do you by any chance know if it's possible the change the disabled value from 1 button while another button is clicked? (In the same view)

slate swan
#

!d discord.ui.View.children

unkempt canyonBOT
slate swan
#

just index the list which has button objects and use the disable property

#

!d discord.ui.Button.disabled

unkempt canyonBOT
slate swan
#

anytime!

simple kettle
#

how do i make sure it checks if the reaction is not from the bot
reaction, user = await bot.wait_for("reaction_add", check=lambda reaction, user : reaction.emoji in buttons, timeout=60.0)

rare saddle
#

How to download all images from a channel? If that in the channel only images

slate swan
#

!d discord.Member.add_role

#

eh

#

!d discord.Member.add_roles

unkempt canyonBOT
#

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

Gives the member a number of [`Role`](https://discordpy.readthedocs.io/en/master/api.html#discord.Role "discord.Role")s.

You must have the [`manage_roles`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.manage_roles "discord.Permissions.manage_roles") permission to use this, and the added [`Role`](https://discordpy.readthedocs.io/en/master/api.html#discord.Role "discord.Role")s must appear lower in the list of roles than the highest role of the member.
slate swan
#

@slate swan ^ for u

#

:")

south jetty
#

How can I add a image like this at the bottom of the embed

vale wing
#

!d discord.Embed.set_image or smth

unkempt canyonBOT
#

set_image(*, url)```
Sets the image for the embed content.

This function returns the class instance to allow for fluent-style chaining.
slate swan
#

^

slate swan
#
        else:
            season = db['season']
            week = db['week']
            keys = []
            hk = db.keys()
            try:
                for ke in hk:
                    i=0
                    i+=1
                    keys.append(ke)
            embed=discord.Embed(title=f"{ctx.guild.name} Season {season} Week {week}", description='\n'.join(keys), color=ctx.author.color, timestamp=datetime.datetime.utcnow())
#

why am i getting invaild syntax?

olive osprey
oblique adder
#

For sending content to webhook is the ratelimit per webhook or per channel of that webhook destination

boreal ravine
wicked atlas
#

I believe about 30/min, but I could be wrong

oblique adder
#

Ok thank you

#

Where can i read mor bout ratelimit?

wicked atlas
slate swan
#

how do i parse a channel ( #discord-bots like that) in a command argument?

wicked atlas
slate swan
#
            hk = db.keys()
            for ke in hk:
                    i=0
                    i+=1
                    keys.append(db[f'lb{i}'])
``` why does it only return the value of #1
boreal ravine
flat solstice
#

Hi I've got a question about finding things in strings. I have this small mockup. py tags = { "{user_name}": "(name tag)", "{user_tag}": "(tag tag)", "{user_id}": "1234", } text_b = "Hello World {user_name}:941314754851524639: It's almost my birthday" split_b = text_b.split(":") b = "" for string in split_b: b = b + string for tag, val in tags.items(): out_b = b.replace(tag, val) print(f"split_b: {split_b}") print(f"string_b: {b}") print(f"out_b: {out_b}")
What I want to do is find any place one of my tags is in a given string.
Then next to the tag there will be two colons with a number between them, this number will be a ID of a member/role/channel/guild.
I will know what type of thing the ID is based off of what tag was used in front of it,
Then I will need to grab that number and convert it into the type of thing it is
Then once I have converted it then I need to replace the tag in the string with the thing I just converted.

I hope that makes sense, I think the code mockup will help explain it

slate swan
boreal ravine
flat solstice
dull terrace
#

How does everyone store their access tokens?

#

do you keep it in the same script, or a plain text file or what

#
activity = disnake.Activity(type=disnake.ActivityType.listening, name="pooping")
await client.change_presence(activity=activity)```
#

i assume it's the same with discord, just replace disnake with discord and client with bot if that's what you use

boreal ravine
dull terrace
olive osprey
dull terrace
#

don't see anything wrong with that, but my organisation is terrible

olive osprey
#

rip, clear it up Ig

sick birch
#

It’s great don’t worry

slate swan
#

hi

mortal dove
#

Is there any kind of annotation that I can do for a message in a hybrid_command?
like

async def delmsg(self, ctx: commands.Context, message: discord.Message):
``` (Except it doesn't work) Using discord.py
slate swan
#

that message argument typehint isnt correct btw

mortal dove
#

Beta thing

#

Text and slash command

mortal dove
slate swan
#

?

strong vector
#

huh what / use for in asyc func

slate swan
#

you mean in params?

mortal dove
#

Denotes the end of positional params iirc

slate swan
#

and in paramters it means the arguments before it are positional only while * means all arguments after are keyword only

slate swan
unkempt canyonBOT
#

@discord.ext.commands.hybrid_command(name=..., **attrs)```
A decorator that transforms a function into a [`HybridCommand`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.HybridCommand "discord.ext.commands.HybridCommand").

A hybrid command is one that functions both as a regular [`Command`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Command "discord.ext.commands.Command")
and one that is also a [`app_commands.Command`](https://discordpy.readthedocs.io/en/master/interactions/api.html#discord.app_commands.Command "discord.app_commands.Command")...
final iron
mortal dove
final iron
#

@slate swan Have you checked the impl of it?

#

I'm going to guess it's shit

slate swan
#

of hybrid commands?

final iron
#

Yeah

slate swan
#

no

#

im working on my wrapper

slate swan
mortal dove
#

devs took care of it for us, for example
ctx.send
Is either ctx.interaction.response.send_message or ctx.channel.send, depending how to command was called

strong vector
slate swan
mortal dove
slate swan
#

just check src if you want to check types

strong vector
slate swan
#

best way imo

slate swan
frozen patio
#

Damn

#

I feel so accomplished

supple thorn
strong vector
supple thorn
#

Did someone order again

strong vector
frozen patio
#

The largest tier available

supple thorn
frozen patio
supple thorn
#

Will they pay

frozen patio
#

12 dollars

slate swan
#

!d discord.ext.commands.MemberConverter

unkempt canyonBOT
#

class discord.ext.commands.MemberConverter(*args, **kwargs)```
Converts to a [`Member`](https://discordpy.readthedocs.io/en/master/api.html#discord.Member "discord.Member").

All lookups are via the local guild. If in a DM context, then the lookup
is done by the global cache.

The lookup strategy is as follows (in order)...
slate swan
#

you can use it directly too

strong vector
zinc phoenix
#
@bot.command()
async def nspic(ctx, *arg):
  link = "https://images-api.nasa.gov/search?q={0}".format(*arg)
  url = requests.get(link)
  data = url.json()
  await ctx.channel.send("Đã tΓ¬m thαΊ₯y {0} kαΊΏt quαΊ£, bαΊ‘n nuα»‘n tΓ¬m kαΊΏt quαΊ£ nΓ o (tα»« 1 Δ‘αΊΏn {1})".format(len(data['collection']['items'])-1, len(data['collection']['items'])-1))
  try:
    s = bot.wait_for("message", check=lambda m: m.author == ctx.author and m.channel == ctx.channel, timeout = 30.0)
  except asyncio.TimeoutError:
    await ctx.channel.send("Đã quÑ hẑn cho phép, mời bẑn thử lẑi.")
  else:
    if str(s).content() in range(1, len(data['collection']['items'])):
      await ctx.channel.send(data['colletion']['items'][s-1]['links']['href'])
    ```
#

Im trying to use wait_for for the command

#

Can anyone help

#

The error is discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'str' object has no attribute 'content'
/usr/lib/python3.8/asyncio/events.py:81: RuntimeWarning: coroutine 'wait_for' was never awaited
self._context.run(self._callback, *self._args)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

zinc phoenix
#

Oh

strong vector
#
@bot.command()
async def nspic(ctx, *arg):
  ...
        s = await bot.wait_for(...)
  ...

strong vector
zinc phoenix
#

I've changed the code, thanks

strong vector
zinc phoenix
#

The type is "discord.message.Message"

strong vector
strong vector
zinc phoenix
#

I want the user to input an int in it

strong vector
#

int(message.content)

slate swan
#

what's better for a database, aiosqlite or sqlite3?

zinc phoenix
#

Oh

strong vector
zinc phoenix
#

Wait, so I dont have to include the () for content

strong vector
zinc phoenix
#

Thank you

strong vector
strong vector
zinc phoenix
strong vector
#
>>> string1 = "1420p"
>>> string2 = "1420"
>>> int(string1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '1420p'
>>> int(string2)
1420
>>>

as you see it raise ValueError

zinc phoenix
#

Oh

zinc phoenix
#

It throws an error

zinc phoenix
#

TypeError: list indices must be integers or slices, not str

#

Isnt int(message.content)-1 an int

slate swan
strong vector
zinc phoenix
#

Hmm ok

strong vector
#

maybe you enter an string

zinc phoenix
#

Wait it seems like I forgot to add the [0]

#

its works fine now

#

Thanks for the help guys

slate swan
slate swan
zinc phoenix
#

You mean like if the user inputs a string, the bot should tell them that they need to reinput it?

slate swan
zinc phoenix
#

Thanks

strong vector
slate swan
#

yes

#

oh hi okimii

slate swan
slate swan
slate swan
#

not helpful smh

#

!e print(type(float("nan")))

unkempt canyonBOT
#

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

<class 'float'>
slate swan
#

uh

#

nan stands for not a number btw

#

hm i figured that out but what does it stand for then

#

what

#

not a number

#

wow

#

🧠

strong vector
wicked atlas
strong vector
#

LMAO litrey your a cat

slate swan
slate swan
slate swan
slate swan
strong vector
slate swan
unkempt canyonBOT
slate swan
slate swan
radiant orbit
#

Can I ask for code help here?

slate swan
#

Yes

slate swan
radiant orbit
#

Oke!!

#

I'm having a problem with storing my token in a .env file

#

My bot runs perfectly when I put the token in the main file but if I try with a .env file it bombards me with errors

slate swan
#

!e
print(None.strip())

unkempt canyonBOT
#

@slate swan :x: Your eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "<string>", line 1, in <module>
003 | AttributeError: 'NoneType' object has no attribute 'strip'
slate swan
#

is it this?

radiant orbit
#

Nu

slate swan
#

can you send the traceback?

#

!traceback

unkempt canyonBOT
#

Please provide the full traceback for your exception in order to help us identify your issue.
While the last line of the error message tells us what kind of error you got,
the full traceback will tell us which line, and other critical information to solve your problem.
Please avoid screenshots so we can copy and paste parts of the message.

A full traceback could look like:

Traceback (most recent call last):
  File "my_file.py", line 5, in <module>
    add_three("6")
  File "my_file.py", line 2, in add_three
    a = num + 3
TypeError: can only concatenate str (not "int") to str

If the traceback is long, use our pastebin.

radiant orbit
slate swan
#

ah

#

seems like its not the right token

radiant orbit
#

Yes precisely

slate swan
#

were did you took the token from?

radiant orbit
slate swan
#

Did u hide the token in this pic?

radiant orbit
#

tokens in a diff file

slate swan
radiant orbit
#

ohh

#

yea

#

Looks like this in my .env file

slate swan
radiant orbit
#

Ahh

slate swan
#

Ye

zinc phoenix
#

Are there any ways to use multiple arguments in python

slate swan
#

Yes

radiant orbit
#

I got a different error this time!! :D

slate swan
zinc phoenix
#

Yep

radiant orbit
#

Thanks guys I can take it from here <3

slate swan
zinc phoenix
#

Oh

slate swan
#

..

zinc phoenix
#

Sorry

slate swan
#

its ok!

zinc phoenix
#

Just found it in discord.py docs so I thought it was related to this channel

slate swan
#

ah

#

and other python revelant libraries

#

How long is a rate limit

#

Nuke bot?

#

I’ve been rate limited for like 2 hours lol

#

uh sad

#

Because people were using a lot of commands at once

#

Add cooldown

#

2-3 sec

#

Yea I’ll need to, how long is a rate limit gonna be tho

#

Its in console

#

Just says temporarily

slate swan
#

U know but u dont know wtf?

#

There’s a message in console every time someone tries to run a command

#

β€œYou are being temporarily rate limited” etc etc

slate swan
#

..

slate swan
#

the wrapper wouldve handle the bucket

#

nah it was basically command spam

#

No

#

a bunch of people spamming at once?

#

Bot cannot get ratelimit

#

I mean I wasn’t doing anything else

#

This bot has been running for a whole year and I’ve never had this issue

#

In that case

#

So I just assumed it’s getting too many users

slate swan
maiden fable
#

@slate swan sleep it's early in the morning

slate swan
slate swan
#

its just the wrapper calculates the bucket and locks the command

#

with

maiden fable
slate swan
slate swan
unkempt canyonBOT
#

class asyncio.Lock```
Implements a mutex lock for asyncio tasks. Not thread-safe.

An asyncio lock can be used to guarantee exclusive access to a shared resource.

The preferred way to use a Lock is an [`async with`](https://docs.python.org/3/reference/compound_stmts.html#async-with) statement:

```py
lock = asyncio.Lock()

# ... later
async with lock:
    # access shared state
```...
slate swan
slate swan
#

i kinda find it useless that dpy calculates the bucket but whatever

slate swan
#

Does anyone know how long I’ll be locked out though?

#

yes

#

its mostly like an hour

#

kk

#

depends on cloudfare

#

@slate swan which cmd the ppl were spamming?

#

well there’s a command which adds something to a database

#

uh what?

#

It’s a specific bot that modifies save files for a certain game

#

Hard to explain out of context

#

..

#

ok

slate swan
#

I’ve been locked out over an hour but hopefully it’ll end any time now

#

right

slate swan
slate swan
#

oh

#

so thats how u define wrapper

#

API wrappers areΒ language-specific kits or packages that wrap sets of API calls into easy-to-use functions. The wrapper programmatically calls multiple API calls without requiring user interaction, further automating projects.

pliant gulch
#

You can just imagine it as ```py
await channel.fetch_message(123) -> GET /channels/{channel_id}/messages/{message_id}

#

discord.py "wraps" the API, and exposes a method you can use instead of using the endpoint itself DIRECTLY

pliant gulch
#

Hence, the term "wrapper"

dull terrace
#

can custom_ids have spaces in them?

slate swan
#

an api wrapper is just something that makes basic commands

slate swan
dull terrace
#

fuck

slate swan
#

..

slate swan
pliant gulch
#

Pretty sure custom_id's can accept strings with spaces

slate swan
slate swan
pliant gulch
#

As long as it's unique and not exceeding the 100 char limit

dull terrace
#

the way i set things up means im gonna have to insert an underscore then take it back out later

#

what's that replace thing

#

string.replace(" ", "_")

unkempt canyonBOT
#

str.replace(old, new[, count])```
Return a copy of the string with all occurrences of substring *old* replaced by *new*. If the optional argument *count* is given, only the first *count* occurrences are replaced.
dull terrace
slate swan
slate swan
#

No ot its the end

pliant gulch
#

The documentation says nothing about not allowing spaces

slate swan
#

custom_id must be unique per component; multiple buttons on the same message must not share the same

custom_id. This field is a string of max 100 characters, and can be used flexibly to maintain state or pass through other important data.

slate swan
#

😼

#

thats all they mentioned

pliant gulch
#

Yea, so I'm pretty sure it allows spaces

#

Otherwise they would've mentioned it

#

Like in a few other places they do say they don't allow spaces

#

Can't remember for which though

slate swan
#

Ok

radiant orbit
#

Is this the right way to get my token from the .env file?

#

wait wait nvm

#

It's working now just didn't save the files

smoky bloom
#
@bot.event
async def on_member_join(member):
    if member.guild == bot.get_guild(960516503613079582):
      button = Button(label = 'Verify', style = discord.ButtonStyle.green, emoji="βœ…")
      guild = bot.get_guild(960516503613079582)
      member = member
      this_role = discord.utils.get(guild.roles,id=int(961235844704919562))
   
      async def button_callback(interaction):
        
      
      
    
        await interaction.response.member.add_roles(this_role)

  

      
      guild = bot.get_guild(960516503613079582)
      member = member
      this_role = discord.utils.get(guild.roles,id=int(961235844704919562))
    
      button.callback = button_callback
      view = View()
      view.add_item(button)
      await bot.get_channel(960516503613079584).send(f"{member.mention} has joined the class ! Bhak bsdk pehle May I come in ma'am bol ", view=view)
#

Hi can anyone tell me whats wrong with this code? im trying to create a verification system

slate swan
#

Is there anyway for me to get all the IDs of people who have access to a specific channel?

slate swan
smoky bloom
#

I want to create a button that gives people a role when clicked

slate swan
#

What line....

#

And on this line:

this_role = discord.utils.get(guild.roles,id=int(961235844704919562))```

doing int(961235844704919562) is useless as 961235844704919562 is already an int
smoky bloom
#

ok but that won't help in this error

slate swan
#

And you've done that twice, try be a bit more efficient and your code can run faster

smoky bloom
#

AttributeError: 'InteractionResponse' object has no attribute 'member'

slate swan
#

What line...

slate swan
gaunt ice
smoky bloom
slate swan
#

yo hack

slate swan
#

Doesn't look like interaction is defined

slate swan
#

Where's interaction on that code

#

Ohh

#

!d discord.Interaction.user

#

Sorry

unkempt canyonBOT
slate swan
#

cant it be interaction.author.add_roles()?

smoky bloom
slate swan
#

disnake has aliases of user and author while dpy doesnt

slate swan
smoky bloom
slate swan
smoky bloom
#

disnake

slate swan
#

its good for u

#

!d disnake.Interaction.author

unkempt canyonBOT
slate swan
#

.

radiant orbit
#

I wanna fetch the name of the server my bot joins so it prints to the terminal "EggwuhBot has joined 'server'", how do I call the name of the server?

slate swan
#

Is there anyway for me to get all the IDs of people who have access to a specific channel?

radiant orbit
#

Also sorry I can't send embedded I'm working with a vm

unkempt canyonBOT
radiant orbit
#

ty ty Pepe_Pray

slate swan
#

how to get client name i forgot

unkempt canyonBOT
slate swan
#

uh ok

#

Is there anyway for me to get all the IDs of people who have access to a specific channel?

slate swan
unkempt canyonBOT
slate swan
#

cool

slate swan
unkempt canyonBOT
#

property id```
Equivalent to [`User.id`](https://discordpy.readthedocs.io/en/master/api.html#discord.User.id "discord.User.id")
slate swan
#

im speed

#

πŸ”₯

#

i accidently opened my bot folder with vlc media player

#

It only fetches by bots info

slate swan
#

code

#

It only prints this

[<Member id=932589533071200702 name='Test' discriminator='2477' bot=True nick=None guild=<Guild id=963264462117407764 name='Test Bot Server' shard_id=None chunked=False member_count=3>>]```
#

code?

#
channel = client.get_channel(payload.channel_id)
print(channel.members)```
#

@slate swan this

#

!intents

unkempt canyonBOT
#

Using intents in discord.py

Intents are a feature of Discord that tells the gateway exactly which events to send your bot. By default, discord.py has all intents enabled, except for the Members and Presences intents, which are needed for events such as on_member and to get members' statuses.

To enable one of these intents, you need to first go to the Discord developer portal, then to the bot page of your bot's application. Scroll down to the Privileged Gateway Intents section, then enable the intents that you need.

Next, in your bot you need to set the intents you want to connect with in the bot's constructor using the intents keyword argument, like this:

from discord import Intents
from discord.ext import commands

intents = Intents.default()
intents.members = True

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

For more info about using intents, see the discord.py docs on intents, and for general information about them, see the Discord developer documentation on intents.

slate swan
#

I have intents

#

..

#

then your bot is the only one that can access the chat

#

...

#

this is the 2nd time

#

...

#

I can access it too

slate swan
slate swan
#

also why ur bot name is test :?

slate swan
slate swan
#

@slate swan can u pls show us the code of intents

slate swan
#

oh

gaunt ice
#

.

slate swan
#
intents = discord.Intents.default()
client = commands.Bot(command_prefix = bot_prefix, intents = intents)
intents.members = True 
client.remove_command('help')```
#

bro

gaunt ice
#

we not gon hack ur skool lmao

slate swan
#

see, clearly you dont have them.

#

sarth was right

#

the intents.members=True line must be above client defination :)

#

Ok

#

πŸ‘

#

that fixes your old issue you were facing that day as well

#

It works

#

But is there anyway to just fetch the IDs?

#

it looks like a bunch of junk.

#

.id

slate swan
torn sail
slate swan
#

idk

#

use for loop

torn sail
#

Yes

slate swan
#

or a list iteration

slate swan
#

Huh?

#

i have a short list comprehension for doing that "id only" stuff but its like playing with the internals..

slate swan
unkempt canyonBOT
#

Do you ever find yourself writing something like this?

>>> squares = []
>>> for n in range(5):
...    squares.append(n ** 2)
[0, 1, 4, 9, 16]

Using list comprehensions can make this both shorter and more readable. As a list comprehension, the same code would look like this:

>>> [n ** 2 for n in range(5)]
[0, 1, 4, 9, 16]

List comprehensions also get an if statement:

>>> [n ** 2 for n in range(5) if n % 2 == 0]
[0, 4, 16]

For more info, see this pythonforbeginners.com post.

slate swan
#

this is what they mean

slate swan
#

you can have if statements as well

#

ids = [ mem_map[0] for mem_map in channel.guild._members.items() if channel.permissions_for(mem_map[1]).read_messages]

#

😳 don't do this

#

you cant call print in the list comp lol

#

uh

#

Bruh im still confused

#

!e ( print(a) for a in (1,2,3)) # why not?

unkempt canyonBOT
#

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

[No output]
slate swan
#

im bad at list compe

#

and thats a generator

supple thorn
slate swan
slate swan
pliant gulch
#

!e ```py
[print(i) for i in range(10)]

unkempt canyonBOT
#

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

001 | 0
002 | 1
003 | 2
004 | 3
005 | 4
006 | 5
007 | 6
008 | 7
009 | 8
010 | 9
slate swan
#

doesnt change a thing

#

what will be the expression

#

Im confused still @slate swan

frozen patio
#

I am grouping commands correct yes?

slate swan
#

How do i get their ids

slate swan
slate swan
slate swan
#

because one time hunter said about something about that you cant call print dynamically in something but i forgot

slate swan
frozen patio
frozen patio
slate swan
#

helpdaily

#

name like this

frozen patio
#

Oh

supple thorn
unkempt canyonBOT
#

@supple thorn :white_check_mark: Your eval job has completed with return code 0.

1 2 3
frozen patio
#

I thought it was like

slate swan
frozen patio
#

$help daily

frozen patio
slate swan
frozen patio
#

Yes

slate swan
#

then add in it

frozen patio
#

I do

#

Hmmm

slate swan
#

you can use the name kwarg in @command decorator alternatively ```py
@bot.group(name="help")
async def my_help_group(ctx):
...

@my_help_group.command()
... ```

#

..

slate swan
slate swan
#

isnt that esoteric

#

smh

slate swan
supple thorn
slate swan
#

nah

slate swan
#

its just unpacking a tuple comp

supple thorn
#

I just got reminded i still have to debug my upload method

#

Fuck

slate swan
#

..

slate swan
#

alr ill continue with my giv cmd

#

definitely not a simple selectmenu callback 🀑

supple thorn
#

I forgot sarth uses hikari

slate swan
#

i just realised i added an and instead of ==

supple thorn
#

fun.bot

slate swan
#

fun being an instance of lightbulb.Plugin ( cogs kinda thing)

supple thorn
slate swan
supple thorn
#

I only dm hunter when i need to

#

Like when okimii and sarth are offline

slate swan
slate swan
slate swan
slate swan
#

and you see how my hun hun appears and responds to mepithink

#

lmao

maiden fable
#

Stop it oki

supple thorn
#

Hunter ignore okimii now kek

slate swan
#

"hun hun"

supple thorn
#

Don't give the satisfaction

slate swan
slate swan
maiden fable
slate swan
#

websocket is a pain

#

yes

#

i hate websockets and discords gateway

slate swan
radiant orbit
#

I'm not sure what I'm doing wrong, it's saying guild isn't defined

slate swan
radiant orbit
#

Error happens when I try to change my bot's prefix

slate swan
#

!e a

unkempt canyonBOT
#

@slate swan :x: Your eval job has completed with return code 1.

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

..

#

well it says that because guild isnt really defined

slate swan
supple thorn
slate swan
supple thorn
#

πŸ˜”

slate swan
#

also, don't use json as a database

maiden fable
slate swan
radiant orbit
slate swan
supple thorn
#

Trying to get my notifs back up to 20k+ again

slate swan
sick birch
slate swan
#

that was long ago!

supple thorn
slate swan
slate swan
slate swan
# radiant orbit What should I use?

sqlite as a local database is a good option, you'll just need to learn 4-5 statements
for better databases in bigger production you can go for remote dbs like postgresql, mysql or mongodb ( mongo is json type)

sick birch
torn sail
#

I like xbow

radiant orbit
#

ah okok

slate swan
slate swan
supple thorn
radiant orbit
#

So that would be for having diff prefixes for diff servers?

slate swan
supple thorn
#

I was not stalking your account πŸ‘€

sick birch
#

hmm

slate swan
torn sail
#

πŸ€”

slate swan
#

no tutorial found there

gaunt ice
#

.

slate swan
slate swan
gaunt ice
#

kat

radiant orbit
slate swan
radiant orbit
#

Thank you <33

slate swan
slate swan
#

wait

slate swan
#

get flash bang

#

seems like a "you" issue

#

no way

#

bad wifi moment

slate swan
#

cool

#

they added the next button

keen talon
slate swan
#

πŸ’œ

#

the next button was not there

#

in the past

slate swan
#

and its always been there

#

ive always seen that hyper link there

#

idk since i learned sql from school

#

ew

keen talon
slate swan
#

im self taught 😏

slate swan
slate swan
#

im on 9th πŸ˜‘

#

same

#

they teach basic python

#

like prinitng

#

var

slate swan
keen talon
slate swan
#

they'll keep teaching you file reading operation until class 12th 🀑

slate swan
#

when i heard python in the course i smiled because i know my group is gonna suffer next year

#

even if it is basic py😏

#

in 8th there was a chap called visual basic ;-;

#

πŸ—Ώ

slate swan
#

me with 1 year of python experience 😳

slate swan
keen talon
slate swan
#
with open("logs.json") as f:
      logs = json.load(f)

should i add it inside the function like !setlogs
or outside cog class or in cog class
(json no comments)

slate swan
#

which is better

slate swan
#

..

slate swan
#

so you wont need to be opening the file on each command invocation and you should be using aiofiles because it would be blocking

#

wait

slate swan
#

he meant cog and not command oopsie

#

well yes it should be in the cog sorry

slate swan
#

cog

#

uh ok

slate swan
keen talon
gaunt ice
slate swan
#

probably add it as an attribute for the cog

slate swan
#

sarth and hunter are my lovely indian bros

gaunt ice
sick birch
#

guys this is getting a bit off topic now

gaunt ice
#

yes

slate swan
#

Robin mad he arena 3

quaint epoch
#

!ot

unkempt canyonBOT
gaunt ice
sick birch
slate swan
#

Yall mad yoy guys dont have hog rider

slate swan
gaunt ice
#

ot

slate swan
#

you guys can be max arena but i got golden hair hog rider😈

sick birch
#

.topic

lament depotBOT
#
**Do you think there's a way in which Discord could handle bots better?**

Suggest more topics here!