#Basic Pycord Help

1 messages · Page 35 of 1

sage tendon
#

screenshot

dawn vault
sage tendon
#

Permissions aren't intents

#

go to Bot > Privileged Gateway Intents

#

oh wait its right above that

#

yea just scroll up

dawn vault
#

oh I am stupid

#

also is there any way to make a message get sent in a certain channel at a specific time of day?

sage tendon
dawn vault
#

Unclear

fresh sierra
#

so you can add a parameter for it run only at this time

sage tendon
fresh sierra
#

i think he didnt read the whole guide but only the example

#
You can also pass in a datetime.time object or a sequence of them in the time parameter which will make it run at the specified time(s).

dawn vault
sage tendon
#

or just google "python datetime" and you'll find enough

dawn vault
#

I got it

#

except

#

I don't know how to send messages

sage tendon
#

get a channel by ID and .send() using it

rugged lodgeBOT
fresh sierra
#

i might be to late

shell radish
#

that doesn't seem like a datetime.time object

fresh sierra
shell radish
#

that seems like a datetime.datetime object

#

not a datetime.time object

fresh sierra
shell radish
fresh sierra
dawn vault
fresh sierra
#

thanks for the correction

fresh sierra
dawn vault
#

everything

shell radish
#

so ```py
partial_channel = bot.get_partial_messageable(id)
await partial_channel.send(...)

sage tendon
#

if you do it in a cog and have the task properly defined you can just do

channel = self.bot.get_channel(channel id here)
await channel.send(...)
#

lol

#

i've never seen partial_messageable used ngl
when should you use it over get_channel

shell radish
sage tendon
#

right

shell radish
#

you don't need the full channel object to send a message

fresh sierra
#

self.bot.get_or_fetch_channel ?

sage tendon
shell radish
#

and that is enough to send a message

fresh sierra
sage tendon
#

ah ic
so you can just send on that regardless of the channel being cached or not?

shell radish
#

yeah, you still have to handle the channel deleted case yourself tho

sage tendon
#

well if its deleted you have different problems /hj

fresh sierra
#

also why does all fetch return None, except the channel return an error ? is that a reason ?

shell radish
sage tendon
fresh sierra
shell radish
#

All fetches make an API request and will throw an error if x does not exist

fresh sierra
shell radish
#

get relies on cache

fresh sierra
#

this doesnt

dawn vault
#

I do not get datetime

fresh sierra
#

get_or_fetch_user too but i think its different

sage tendon
#

To make it better, time in any way shape or form is every developer's hell

shell radish
dawn vault
#

I do not understand

sage tendon
#

no

#

the datetime object goes into the parentheses

#

it's always @tasks.loop

rugged lodgeBOT
#

examples/background_task.py lines 28 to 33

@tasks.loop(
    time=time(3, 0, tzinfo=timezone.utc)
)  # Task that runs every day at 3 AM UTC
async def time_task(self):
    channel = self.get_channel(1234567)  # Your Channel ID goes here
    await channel.send("It's 3 AM!")```
fresh sierra
sage tendon
shell radish
sage tendon
#

as i said, time is hell for most developers :)
but yea, check this

shell radish
#

the example uses from datetime import time

dawn vault
fresh sierra
#
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix="!")

# suggestion possible ?

#member :
await bot.get_or_fetch_user() # -> raise no error and return None

#role
role = guild.get_role() or await guild._fetch_role() # -> raise no error and return None

#channel
channel = bot.get_channel() or await bot.fetch_channel() # raison error 

#fix :
try:
    channel = bot.get_channel() or await bot.fetch_channel() # raison error 
except:
    channel = None

# suggestion1: 
 await bot.fetch_channel() do not raise error

# suggestion2:
await bot.get_or_fetch_channel() # -> raise no error and return None
fresh sierra
sage tendon
fresh sierra
#

need to explain more we are not magician

sage tendon
#

is it 3am utc for you?

fresh sierra
#

+timezone

#

-timezone

shell radish
fresh sierra
#

(someone know the command ?)

fresh sierra
dawn vault
#
  File "d:\Rembot\bot.py", line 203, in <module>
    @tasks.loop(time=time(3, 0, tzinfo=timezone.utc))
                                       ^^^^^^^^
NameError: name 'timezone' is not defined```
sage tendon
#

probably also directly imported from datetime

shell radish
sage tendon
#

..

#

from datetime import timezone

#

blind guess

fresh sierra
sage tendon
#

from discord.utils import get_or_fetch :)
5 characters saved

dawn vault
#

how do i change the datetime timezone?

sage tendon
#

put a different timezone there i'd guess

dawn vault
#

oh well

#

and it doesn't work

sage tendon
#

"doesn't work" is a most terrible description of your issue

#

what doesn't work, why do you think / know that

dawn vault
#

I have it set to send at a certain time but when that time comes it doesn't send

sage tendon
#

did you start the task?

dawn vault
#

yes

sage tendon
#

show your code

shell radish
#

do you know what UTC is?

dawn vault
fresh sierra
dawn vault
sage tendon
# dawn vault

see that squiggly line? it means something's wrong

#

address it

dawn vault
#

I am in utc+2

sage tendon
dawn vault
shell radish
sage tendon
#

you forgot the self parameter in the task function

dawn vault
fresh sierra
# dawn vault

if you are not using a cog, pls remove the self.bot and only use bot.get_channel

sage tendon
#

oh wiat

shell radish
#

it is 15:26 in utc rn

sage tendon
#

thats not in a cog is it

#

if it's not in a cog you can remove the self altogether

fresh sierra
# dawn vault

also are you starting the loop with qotd.start() ?

dawn vault
#

i thought the opposite

sage tendon
shell radish
#

google UTC

fresh sierra
dawn vault
shell radish
#

utc + 2 = me

so utc = me - 2

#

lol

fresh sierra
#

equation facepalm

shell radish
shell radish
fresh sierra
sage tendon
#

instanceof("programming", computerscience) = True

fresh sierra
#

math are everywhere

#

like illuminati !!!

deft kestrel
#

pycord has an event that checked if user used a command? I mean something like this:
on_use_command or something like that

sage tendon
#

on_application_command for slash commands

#

do not use that with @bot.event though, make a listener

deft kestrel
#

sure thanks

round venture
#

is there a way to refresh discord slash commands cause I hate having to wait after making a slash command

sage tendon
#

restart discord

round venture
#

alr

sage tendon
#

ctrl+r

round venture
#

ty

round venture
#

how do I create a channel with a bot? I've never done it and I don't see it on the docs

#

anc give roles*

#

and*

#

and how do I see if a user has a role 😐, im kinda asking for a bit but the docs aren't very well written (no offense to anyone I just think it leaves out a lot)

round venture
#

I searched up role, give role, channel, create channel

little cobalt
#

search for it

round venture
#

i did

shell radish
#

depends on the context

round venture
#

oh

#

what about a slash command context

#

so ApplicationContext

shell radish
#

i mean context in the literal sense, not in code

round venture
#

ahh

#

wait is it ctx.guild.create_text_channel()

#

i think i found it

shell radish
#

where do you want to create a channel, whom do you want to give the role to

#

etc

round venture
#

inside of a category

#

and a text channel

shell radish
#

this category is in the guild that the command was invoked from?

round venture
#

i see ctx.guild.create_text_channel

#

how do i reference the category?

#

is it like ctx.guild.get_category or smth?

little cobalt
#

what do you gonna do if you dont have ctx?

round venture
sage tendon
#

categories are also just channels internally

round venture
#

how would I get one

sage tendon
#

bot.get_channel(id)
if you are very sure its cached

#

(usually it is)

round venture
#

alr tysm

#

wait is there guild.getchannel?

shell radish
#

you can use ctx.channel.category

sage tendon
#

^^ if you wanna create it in the category the command invoked in
if not, you need to get the category

round venture
#

it's already there

#

this bot is only for my server so wont be in any other servers so it will always be there 100% of the itme

#

time*

sage tendon
round venture
#

ah

#

so would i just do guild.get_channel()

shell radish
#

probably just fetch it to be safe

round venture
#

alr

#

tyty

sage tendon
#

or better yet, run a check if its none, and if it is, then fetch

#

always good to fetch conversatively

#

(or use discord.utils.get_or_fetch to make that one line)

shell radish
#

ratelimits aren't a problem here

sage tendon
#

quicker, if anything

little cobalt
#

I started to do all the time get and fetch

sage tendon
#

yea it's nice but you can't always use it

round venture
#

hmm, the category doesn't seem to work

little cobalt
round venture
#

im doing this await guild.create_text_channel(f"{user.name}s-cell", category=guild.get_channel("1234883417217302619")). It's creating the channel but not in the category

shell radish
#

it should be an int not a str

round venture
#

oh yea

#

whoops

little cobalt
#

you did ""

round venture
#

duh, lol

shell radish
#

and user.name can have illegal characters so be aware of that

sage tendon
#

what happens in that case? are they ignored, or will it fail?

shell radish
#

throws a 4xx iirc

sage tendon
#

wait, don't pomelo usernames use the same charset as channel names now?

#

no space, only a-Z and 1-9, dashes, underscores?

#

and .

round venture
#

hmm, how about removing roles from someone? how would I do that

sage tendon
#

Docs are useful :)

round venture
#

but how would I remove all roles

#

from a member

little cobalt
sage tendon
#

edit :)

round venture
#

whats the difference between a member and a user

#

how do I get a member from a user?

sage tendon
#

A user is just a plain user
A member is basically a guild-user

#

you can go member > user but not reverse

round venture
#

oh yea that makes sense

sage tendon
#

but member has everything a user has anyway iirc

round venture
#

what is snowflake

sage tendon
#

an ID

round venture
#

is that just another word for ids

#

ah

#

so does remove_roles take a list of ids?

sage tendon
#

read the documentation :)

#

but i'd just use edit because the lsit of roles you pass there is what the member will have after the fact, so if you pass an empty list, it removes all the roles instantly

sage tendon
#

really the best advice i can give you is to use the docs, a lot
sometimes you need to think a little, like if a ban function is on a member or a guild (actually both in the case of ban in particular, nice example facepalm ) but you can really find everything you need on the docs, what type everything needs to be, etc

round venture
#

laaast thing, how do I reference a role

#

wait nvm

#

i prob know

sage tendon
#

you dont have to to remove all roles

#

member.edit(roles=[])

fresh sierra
#

How to pycord

sage tendon
#

pycord is an ffmpeg wrapper

carmine minnow
#

how can I make my buttons persistent view when my class takes parameters?

class ManualReview(discord.ui.View):
    def __init__(self, primDept, secDept, dob, age, firstName, lastName, primCallsign, secCallsign):
        super().__init__(timeout=None)

        self.primDept = primDept
        self.secDept = secDept
        self.dob = dob
        self.age = age
        self.firstName = firstName
        self.lastName = lastName

        self.primCallsign = primCallsign
        self.secCallign = secCallsign


    @discord.ui.button(label="Accept", style=discord.ButtonStyle.green, custom_id="manual_accept")
    async def accept_callback(self, button, interaction):
        await Onboard.onboard(self, interaction, self.primDept, self.secDept)
        ...

    @discord.ui.button(label="Deny", style=discord.ButtonStyle.red, custom_id="manual_deny")
    async def deny_callback(self, button, interaction):
        ...
sage tendon
carmine minnow
#

when using the View i'm doing

            self.bot.add_view(ManualReview(self.primDept, self.secDept, birthday, age, firstName, lastName, primCallsign, secCallsign))
            await logs.send(f"{interaction.user.mention}", embed=embed, view=ManualReview(self.primDept, self.secDept, birthday, age, firstName, lastName, primCallsign, secCallsign))

but its not working

carmine minnow
sage tendon
#

i dont see why thats a problem

carmine minnow
#

because the parameters are variable to a command, how am i supposed to set it on initilization

sage tendon
#

add the view to the bot when the command is called

carmine minnow
sage tendon
#

what doesnt work

#

wait, no

carmine minnow
#

the buttons dont work when I restart the bot

sage tendon
#

you are creating a different view lol

carmine minnow
#

yep.

#

😭

sage tendon
#

yea, dont
pass the view you made

carmine minnow
#
            vooiw = ManualReview(self.primDept, self.secDept, birthday, age, firstName, lastName, primCallsign, secCallsign)
            self.bot.add_view(vooiw)
            await logs.send(f"{interaction.user.mention}", embed=embed, view=vooiw)
sage tendon
#

yea

carmine minnow
#

I see

#

thank you :3

carmine minnow
rugged lodgeBOT
#

Here's the persistent example.

carmine minnow
sage tendon
#

hm i htink what i said was actually wrong, apparently it works differently and you dont need to pass exactly the view you made

#

mb

carmine minnow
#

oh

#

I see

#

could it have to do with me passing the bot object from my cog?

sage tendon
#

?

carmine minnow
#
class ApplicationModal(discord.ui.Modal):
    def __init__(self, primDept, secDept, bot, *args, **kwargs) -> None:
        super().__init__(*args, **kwargs)

bot is being passed from a cog

sage tendon
#

did you also do self.persistent_views_added = True

carmine minnow
#

i dont think that does anything

sage tendon
#

might be important shrug

#

tbh i never did persistent views so thats about all i can tell you

carmine minnow
#

in the example its just a bool to track which views have been made persistent

#

it doesnt actually do anything outside of their use

sage tendon
#

ah yea
yea idk

#

what if you just create a dummy version of your view with whatever parameters and add it to your bot in the on_ready, and then in the command you make the version of the view you want

#

should work i think

carmine minnow
sage tendon
#

if your view still is made then

carmine minnow
#

yeah it didnt like it

#
2024-04-30 19:54:26.046070 | loaded cogs.verification.verify
Traceback (most recent call last):
  File "F:\Coding\[bots]\SOFLRP\bot.py", line 32, in <module>
    client.add_view(ManualReview(None, None, None, None, None, None, None, None))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "F:\Coding\[bots]\SOFLRP\cogs\verification\manual.py", line 9, in __init__
    super().__init__(timeout=None)
  File "C:\Python311\Lib\site-packages\discord\ui\view.py", line 183, in __init__
    loop = asyncio.get_running_loop()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: no running event loop
sage tendon
#

yea idk, everything else would be guessing
maybe someone else knows

#

its definitely possible tho

carmine minnow
#

yea

round venture
#

Hey guys, I keep getting 'NoneType' object is not subscriptable, any ideas?

#

the AddBalance and GiveItem arent breaking it btw

sage tendon
#

something is none, what that is is in your error

round venture
#

hold up wait

sage tendon
#

yes, it is

round venture
#

no

sage tendon
#

else python wouldn't explicitly say it's none

round venture
#

it wasnt

#

i was doing a try catch

#

give me a sec

#

im removing it

#

i was printing it in console

#

no clue what those are

#

oh wai tnvm

#

hold up

sage tendon
round venture
#

nvm fixed

round venture
sour widget
#

hello, how can I make autocomplete with guild channels like this?

fresh sierra
sour widget
fresh sierra
sour widget
fresh sierra
#

Also you should use the decoration it will be easier for you and better looking. If you want to keep ur thing without decorator I will check why it doesn’t work for you

#

Here an example for using decorator

#
    @commands.slash_command()
    @discord.option(name="member", input=discord.Member, required=False)
    @discord.option(name="round", input=int, default=1, required=False)
    async def rockpaperscissors(self, ctx: discord.ApplicationContext, member: discord.Member, round: int):
sour widget
#

thanks

sour widget
sour widget
#

ah, there is a parameter_name...

fresh sierra
carmine minnow
lapis dock
#

you would need to store the custom parameters in a database and load them when you are creating the view

sage tendon
#

Their issue is, i think, that the view needs kinda "working" parameters, and not just a bunch of empty strings for example
I tried helping them yesterday but i got stuck at that, my last idea was also just to pass any parameters but i dont think that works for their views

lapis dock
carmine minnow
fast condor
#

is there an official lib for testing bots? I found dpytest on github but that doesnt seem to have much work done recently. How does one write their unittests properly?

sage tendon
#

honestly i doubt you need unit tests in the scope of discord bots
usually its enough to just test your commands with a few inputs and make sure nothing dumb can happen

fast condor
#

I have like 20 different functionalities it is taking over and with every line of code I write I feel fear to break something

sage tendon
#

wdym

fast condor
#

If I improve a game or something I want to be sure I didnt break a part of it in the process

sage tendon
#

make an error handler that sends any error into a channel on your server
and test it yourself as much as you can

fast condor
#

well undesired behaviour might still occure without it fully breaking. So I guess the answer is no real unittesting library?

sage tendon
#

i wouldnt know of one, maybe the others do

fast condor
#

alr thx nevertheless

edgy nest
echo wraith
#

It's there a way to get the current ping with the gateway?

sage tendon
#

i use {round(self.bot.latency * 1000)}ms but not sure if thats the exact right one

#

but i labelled it "API latency" in my command so i guess it is the gateway ping

echo wraith
#

I was able to add it to my status page

frail ocean
#

Is there a way to get the voice channel count in a category

fresh sierra
#

there is no attribute but you can just sum them

frail ocean
#

And how?

fresh sierra
#

like that :

voice_channel_count = sum(isinstance(channel, discord.VoiceChannel) for channel in category.channels)
frail ocean
#

Ah okay

#

Thanks a lot

#

Dumb question but was is isinstance doing

sage tendon
#

checks if its a voice channel

fresh sierra
#

so if channel is a class discord.VoiceChannel

#

so you can use that for everything
isinstance(1, int)

#

etc etc

frail ocean
#

Ah okay thanks

little cobalt
#

What would be a good way to run your bot at the background?

#

I currently use pm2

deft bronze
#

Didnt work

#

Today the task repeated again

#

It repeats after the first time

#

Like the first task works great, the seconds sends two times

round venture
#

is there a way to get the user from AutocompleteContext

little cobalt
round venture
#

command sender

little cobalt
#

with ctx.author

#

like the prefix commands

sage tendon
#

check the docs for the context stuff especially

#

way faster than asking here

#

and you learn new stuff too

round venture
#

couldnt*

sage tendon
#

just search for autocompletecontext

round venture
#

when I do something like deleting a channel, adding roles it requires the person who ran the command to have permissions to do that. Is there a way to bypass that?

round venture
sage tendon
#

don't add the discord. infront

sage tendon
round venture
#

oh

#

what the flip

#

im blind ⁉️

sage tendon
round venture
#

really?

#

lemme test that

sage tendon
#

for autocomplete it's ctx.interaction.user
unless author is an undocumented shortcut

little cobalt
#

ok its interaction

fresh sierra
fresh sierra
#

#1235497796694704208 is there a way to do that with bridge ?

warm jay
#

Whats the command for /ping?

little cobalt
#

/ping

#

;3

warm jay
#

its {bot.latency} aint_no_way_skull

little cobalt
#

yus ^^

#

but add a * 1000 to it

warm jay
#

ok

warm jay
# little cobalt yus ^^
@bot.command()
async def ping(ctx):
    await ctx.respond(f':ping_pong: `{bot.latency * 10000}` is the ~~bot~~ app ping!')
```?
little cobalt
#

you did 1_0000 not 1_000 ;3

warm jay
#

OH

#

other then that, that should work

little cobalt
#

btw you can do a _ at big numbers

warm jay
#

ik that trick

little cobalt
#

like ```py
number: int = 1_000

warm jay
#

** I already know that trick**

#

but thanks

sage tendon
#

(with 1000)

warm jay
#

thats what I want, ms

sage tendon
#

yea just so you add it after the number :)

round venture
#

erm how do I run a while true loop with the bot still online?? I did it with threading but it still doesnt work

sage tendon
#

for what?

round venture
sage tendon
#

what does it do

round venture
#

its not relevant to the solution though

sage tendon
#

ah
you can use tasks for that

round venture
#

how does that work?

#

is that a built in python feature or a pycord feature

rugged lodgeBOT
#

Here's the background task example.

round venture
#

i see

#

is seconds how often it runs?

sage tendon
#

yes

round venture
#

k

#

now what if I wanted to have it do something every 5-20 seconds

#

but its random

#

can i just put a random.randint in it?

sage tendon
#

no

round venture
#

how should I do that then

sage tendon
#

you can change the interval of tasks though

round venture
#

ah

sage tendon
round venture
#

rt

#

ty

sage tendon
#

so just make another task to change the other one's interval

round venture
#

am I doing this wrong? nothing is happening

sage tendon
#

do you start it?

round venture
sage tendon
round venture
#

nvm i see

arctic plover
#

why am i getting this error when trying to fetch a channel?

File "C:\Users\path-to-venv\venv\Lib\site-packages\discord\client.py", line 1805, in fetch_channel
    data = await self.http.get_channel(channel_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\path-to-venv\venv\Lib\site-packages\discord\http.py", line 285, in request
    async with self.__session.request(
               ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: '_MissingSentinel' object has no attribute 'request'
sage tendon
#

show the line in your code that causes that

arctic plover
#
channel = await bot.fetch_channel(1229836602516312104)
#

nothing interesting

sage tendon
#

can you run pip list in your console and post the output here

arctic plover
#
a2wsgi             1.10.4
aiohttp            3.9.3
aiosignal          1.3.1
annotated-types    0.6.0
anyio              4.3.0
attrs              23.2.0
beautifulsoup4     4.12.3
blinker            1.7.0
Brotli             1.1.0
certifi            2024.2.2
charset-normalizer 3.3.2
click              8.1.7
colorama           0.4.6
DateTime           5.5
Discord-Anti-Spam  1.8.1
fastapi            0.110.1
Flask              3.0.3
frozenlist         1.4.1
fuzzywuzzy         0.18.0
gunicorn           22.0.0
h11                0.14.0
idna               3.6
itsdangerous       2.1.2
Jinja2             3.1.3
keyboard           0.13.5
lxml               5.2.1
MarkupSafe         2.1.5
multidict          6.0.5
mutagen            1.47.0
ngrok              1.2.0
packaging          24.0
pip                24.0
py-cord            2.5.0
pycryptodomex      3.20.0
pydantic           2.6.4
pydantic_core      2.16.3
pytz               2024.1
requests           2.31.0
setuptools         68.2.0
sniffio            1.3.1
soupsieve          2.5
starlette          0.37.2
sudo               1.0.0
typing_extensions  4.11.0
urllib3            2.2.1
uvicorn            0.29.0
websockets         12.0
Werkzeug           3.0.2
wheel              0.41.2
yarl               1.9.4
yt-dlp             2024.3.10
zope.interface     6.3
sage tendon
#

are you running that before on_ready?

arctic plover
#

nah

sage tendon
#

where are you running that line of code

little cobalt
#

what is Discord-Anti-Spam?

fresh sierra
#

you mean an official discord thing ?

arctic plover
sage tendon
fresh sierra
sage tendon
#

i think they run it in a cog init using the passed bot parameter so they don't need self, and all that is running when the cog loads aka before on_ready

arctic plover
sage tendon
#

show the function

fresh sierra
#

init are not async

#

await is async

arctic plover
sage tendon
#

we need some info here

arctic plover
#

i`ll try to make it shorter

fresh sierra
#

do like function :
remove until the channel = await

sage tendon
#

from where in your main.py are you calling that function then

sage tendon
#

i mean just your main file CFquinn_cry

lofty parcel
#

My gawd just paste your file

#

?paste

#

?tag paste

limber wagonBOT
#

Please copy and paste your code here. This makes it easier for everyone helping you.

lofty parcel
#

Why is it so hard to show your file

#

You ain't hacking the nasa and we don't care at all what your bot is about

arctic plover
#

bot.py:

import discord
bot = discord.Bot(intents=discord.Intents.all())

main.py:

from bot import bot

@bot.event
async def on_ready():
    print('Ready')

bot.run('token')

web.py

@app.post('/feed')
async def feed_post(request: Request):
    xml = await request.body()
    await youtube_handler(xml)
    return Response(status_code=204, media_type='text/plain')

youtube.py:

from bot import bot

async def youtube_handler(xml):
    # useless code
    message = 'Any message'
    channel = await bot.fetch_channel(1229836602516312104)
    message = asyncio.run_coroutine_threadsafe(channel.send(message), bot.loop)
#

like this

lofty parcel
#

You use cogs.

sage tendon
#

wtf lmao

arctic plover
lofty parcel
#

So what

#

It is still wrong.

sage tendon
#

w h a t in the HELL

lofty parcel
#

I'm assuming you don't know how to code. So, learn python first then come back at developing bots.

#

?tag lp

limber wagonBOT
arctic plover
sage tendon
#

...what

arctic plover
# sage tendon ...what
import uvicorn
import fastapi
import asyncio
import discord
import threading

bot = discord.Bot(intents=discord.Intents.all())


async def main():
    await bot.get_user(584650504710127616).send('hi')


app = fastapi.FastAPI()


@app.get('/')
async def index():
    await main()
    return 'Hello World'


def run_bot():
    bot.run('token')


bot_thread = threading.Thread(target=run_bot)
bot_thread.start()
uvicorn.run(app, port=8000)

Output:

INFO:     127.0.0.1:52423 - "GET / HTTP/1.1" 500 Internal Server Error
RuntimeError: Timeout context manager should be used inside a task
#

you should use same loop

arctic plover
#

it`s example

sage tendon
#

.rtfm bot.start

little cobalt
#

you dont need threading for that

arctic plover
sage tendon
#

there is no reason to introduce threading into something that doesnt need it at all

sage tendon
#

(apparently)

arctic plover
#

I was just explaining why you need to use run_coroutine_threadsafe

sage tendon
#

yea, but please dont use threading
its completely unnecessary and overcomplicates things

arctic plover
#

kk

sage tendon
#

You fix your bot

#
  1. dont use threading
  2. use cogs
hybrid tinsel
#

how do i populate options with a dynamic list of something for the select menu?
currently i just have the sample but i want to be able to set an arbitrary amount of options (like taking an input number, lets say 10, and then it just puts 1-10 as options)

the specific use case im trying to do is to list people in a voice channel and then display them as choices

sage tendon
#

i think the easiest way to do it is to just pass the voice channel members to the view init, and then handle creating the options there, and then just do options = choices

#

but there might be a better way, never did selects

warm jay
#

When I do

@bot.command()
async def start_server(ctx):
    subprocess.run(f'{SERVER_PATH}\\run.bat', shell=True)

or

@bot.command()
async def start_server(ctx):
    os.system(f'{SERVER_PATH}\\run.bat')

I always get this error, but that file is in the same dir as the .bat file

sage tendon
#

well, that isn't really specific to pycord

warm jay
#

Well idk what to post it in

#

To the python server I guess

sage tendon
#

not really

#

that error is from the bat for all i can see

warm jay
#

when I manually run the file, it runs

#

I'll just go to python server

hybrid tinsel
# sage tendon i think the easiest way to do it is to just pass the voice channel members to th...

is there a correct way of doing this LOL

class PartyView(discord.ui.View):
    def __init__(self, bot):
        self.bot = bot
        self.choices = []
        
        for i in range(10):
            self.choices.append(discord.SelectOption(label=f"Option {i}"))
    
    @discord.ui.select(
        placeholder = "Select an option",
        min_values = 1,
        max_values = 2,
        options = self.choices
    )
    async def select_callback(self, select, interaction):
        await interaction.response.send_message(f"Selected option {select.values[0]}")

im not sure if im just blanking but i cant seem to access choices in the init?

#

or maybe im just misunderstanding how decorators work 💀

sage tendon
#

pass the vc members to the view and make them the values

#

im not sure selectoptios work without a value

#

hold on

#

ah no the value is the label by default

#

but it should work the way you did it

#

did you restart discord after changing it

hybrid tinsel
#

well, not technically a discord problem (maybe?)

its just that its not accessing the choices list for some reason

sage tendon
#

ah, yea..

#

i forgot python's OOP sucks sometimes

fresh sierra
#

you can do it without the decorator

#

like that :

    select = discord.ui.Select(placeholder=ur thing, etc etc options=self.options)
    self.add_item(select)
    select.callback = self.select_callback
fresh sierra
fresh sierra
sage tendon
#

object oriented programming

fresh sierra
#

ok

hybrid tinsel
# fresh sierra like that : select = discord.ui.Select(placeholder=ur thing, etc etc o...

this fixed the funky thing about not being able to access the choices from the init but now im running into weirder issues 😭

class PartyView(discord.ui.View):
    def __init__(self, bot):
        self.bot = bot
        self.choices = []
        
        for i in range(10):
            self.choices.append(discord.SelectOption(label=f"Option {i}"))
            
    def select_callback(self, select):
        select = discord.ui.Select(placeholder="Select an option", min_values=1, max_values=1, options=self.choices)
        self.add_item(select)
        select.callback = self.select_callback
            
class Party(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
    
    @discord.slash_command()
    async def check(self, ctx, channel: discord.VoiceChannel):
        vc = self.bot.get_channel(channel.id)
        member_ids = [member.id for member in vc.members]
        
        await ctx.respond(" ".join([f"{member_id}" for member_id in member_ids]))
        await ctx.respond("Choose flavor!", view=PartyView(bot=self.bot))

still playing around with the logic so im not really going to put the member list in as choices before i understand wtf im doing

lofty parcel
lofty parcel
#

well they aint doing that either

#

are they

sage tendon
sage tendon
#

move this into your init

fresh sierra
#

like that :

class PartyView(discord.ui.View):
    def __init__(self, bot):
        super().__init__(timeout=None)
        self.bot = bot
        self.choices = []
        
        for i in range(10):
            self.choices.append(discord.SelectOption(label=f"Option {i}"))
        
        select = discord.ui.Select(placeholder="Select an option", min_values=1, max_values=1, options=self.choices)
        self.add_item(select)
        select.callback = self.select_callback

    async def select_callback(self, interaction: discord.Interaction):
      
#

like that

sage tendon
#

also keep the select callback async

lofty parcel
#

you can reduce it with

select = discord.ui.Select(placeholder="Select an option", min_values=1, max_values=1, options=[discord.SelectOption(label=f"Option {i}") for i in range(10)])
fresh sierra
#

and to access to the value i know but label idk,
value is like that :
value = interaction.data["values"][0] for one choice and values = interaction.data["values"] for multiple

#

but dont dropdown choice need a value ?

sage tendon
#

no

fresh sierra
#

nope, only label

sage tendon
#

i said this above already

fresh sierra
#

so maybe interaction.data["labels"][0]

#

idk for that he will need to do some test

sage tendon
#

go by value

#

in case thats ever changed

lofty parcel
#

value defaults to the label

fresh sierra
sage tendon
#

They only want the members in a certain voice channel, not simply a member selector

fresh sierra
fresh sierra
sage tendon
#

just pass the channel members to the init
i doubt the view has a lifetime of more than a few seconds

fresh sierra
#

yep if the view doesnt last that not quit difficult

torpid jackal
#

I was going through the docs, still couldn't figure it out, how to respond to slash commands with ephemeral response? (which is only visible to the user who issued command)

#

I tried ctx.respond("Message", ephemeral=True), no luck

lofty parcel
torpid jackal
#

it's sending normal messages as response.

lofty parcel
#

Are you deferring the interaction?

torpid jackal
#

yes

lofty parcel
#

You must pass ephemeral=True to ctx.defer too

torpid jackal
#

Ooooh. gotcha. will try

#

yup. that worked. Thanks!

deft bronze
#

How can i manage more than 100 msg in this

lofty parcel
deft bronze
#

if i have more than 100 msg, only 100 are deleted

lofty parcel
#

You should purge the channel twice if it's more than 100.

deft bronze
#

Hoy can i handle that?

#

Can i loop the history until is no longer >1?

balmy flicker
#

hey guys!

I got an unstable behavior with if bot.user.mentioned_in(message):

it works well when I reply to a bot message(so context will not contain the mention info, but message.mentions will contain the bot as a member).

it sometimes doesn't work when I mention my bot with '@' sign.
Python debugger shows <@&1234> while bot's id is not 1234.
However, when I paste <@&1234> to discord, it's converted to my bot name correctly.

Why does a bot have two different id?
Need some help. 🍻

lofty parcel
#

You can try splitting the purge

lofty parcel
balmy flicker
lofty parcel
#

Youre probably mentioning your bot's role, not the bot itself.

balmy flicker
hazy turret
#

Is there an easy way to find out which invite code a user used to join the server?
Because the member object doesn't have this information, does it?

fresh sierra
#

You can just store each invite to see which one has gotten 1 more utilisation

#

The thing that I don’t understand is why we can’t access to the invite code because on discord we have something to do that, the new thing

lapis dock
#

I think they will not add it to bots. They have dealt with a lot of abuse with invite tracking and such.

olive ridge
#

Yo, guys, I can't seem to find a menu in pycord's documentation in regards to messaging users privately, is such option even available with pycord? Because the standard method of using await member.send("Text") doesn't really work for me. and responds to my command with Uknown integration message

fresh sierra
#

respond to the interaction

#

and send the message

#

with that : await member.send("Text")

#

you only send the message in private message, but you dont answer too the interaction

olive ridge
waxen ore
#

Which pycord version supports wavelink?

shell radish
#

it’s which version of wavelink supports pycord

waxen ore
#

so which?

shell radish
#

all of them

waxen ore
#

yeah, exactly

shell radish
#

at least the recent ones

shell radish
waxen ore
#

so i don't get it, wavelink needs discord.py utils to work so it installs, but we can no longer import discord bcs we got some kind of conflict, right?

shell radish
#

you can get around the discord issue by not installing it

#

there’s a flag you can set that would make it not install dependencies

waxen ore
waxen ore
shell radish
#

then you can re-install py-cord independently

waxen ore
#

it works, thanks

fresh sierra
#

2.5 was giving an error

#

While 2.4 was working

wanton raven
#

how can you refresh a page with discord.ext.pages

#

well how do you use paginator.refresh() would be a better question

lofty parcel
#

What are you trying to do?

wanton raven
#

pages.Paginator.refresh

#

from discord.ext

lofty parcel
wanton raven
#

there is no documentation

#

but it does exist

lofty parcel
#

It's probably not stable.

wanton raven
#

oh

#

alright

lofty parcel
#

What are you trying to do that makes you think you need to use that

wanton raven
#

so basically I've setted up pages that will show information about specific users but the page need to get the information from a seperate json file

#

and when i use the command to show the pages it shows the information entered before the bot started not the updated one

#

sorry if my explanations aren't that clear

errant trout
# wanton raven

this is View.refresh for handling components, unrelated to paginator

wanton raven
#

yeah

#

i realised that now

#

mb

errant trout
#

because ideally whenever you use the command you should be making a new Paginator

wanton raven
# errant trout how are you loading the pages
import discord
from discord.ext import commands, pages
from discord.commands import Option

class Case(commands.Cog):
    def __init__(self, bot: commands.Bot) -> None:
        self.bot = bot
        self.pages = [
            [
                discord.Embed(title="Mutes", description=""),
                discord.Embed(title="Warns", description=f""),
            ]
        ]

    def get_pages(self):
        return self.pages

#commands...

def setup(bot: commands.Bot):
    bot.add_cog(Case(bot))
lofty parcel
wanton raven
#

oh

#

fair

#

ill try that

lofty parcel
#

That's how you'll get the latest data from your json.

wanton raven
#

thanks

frail laurel
#

is message id unique to discord as a whole or only to guilds??

#

i mean can 2 separate servers have the same message id

fresh sierra
#

Every id is unique

fresh sierra
#

.tag no json

sly karmaBOT
#

JSON is a convenient and easy-to-read data storage protocol that's widely accepted by most programming languages. However, we caution against its use for storing and retrieving data in an asynchronous environment like a Discord bot. Don’t use json!

  • It's a file-based data storage, which makes it vulnerable to race conditions
  • You'll need to implement your own synchronization primitives to avoid corrupting data
  • If you're not careful, you could accidentally wipe your entire JSON file.

Solution? Use a database. Recommended schema are SQLite, PostgreSQL, and MongoDB.

  • Async libraries exist on pypi for each of these
    sqlite -- aiosqlite (or Danny's wrapper: asqlite)
    postgresql -- asyncpg
    mongodb -- motor
  • Databases organize your data into tables, and are fast at inserting, retrieving, and removing records
  • You can impose uniqueness constraints to ensure against duplication
  • The Python libraries enforce synchronization for you
  • The query language is intuitive, you can get running with simple queries in just a few hours!
sage tendon
#

hours? nah, way quicker

upper flint
#

Is there an event that catches new messages specifically in one channel only?

sage tendon
#

No

upper flint
#

Alr, my bad

sage tendon
#

just make an if clause

upper flint
#

There is one issue

#

The list of channels I want to track is dynamic. Sometimes I add something to this list and sometimes I remove something from it. Should I update event to track new channels everytime that happens?

#

I am adding these channels somewhere else in the code directly to the database

#

Nvm, I think I can just create a list somewhere in the bot itself and add/remove these channels from there when updating.

balmy flicker
#

can I run multiple pycord instances one as an API gateway and others provide different features? so users won't get affected when I'm actively coding for new features.

maiden bloom
#

Is it still not possible to set a custom bot status that doesn't include "Playing" or "Watching", etc.?

maiden bloom
# lofty parcel It is possible.

Can you give an example or correct mine? This doesn't seem to work:

bot.activity = discord.Activity(type=discord.ActivityType.custom, name=f"Testing custom status.")
lofty parcel
boreal sky
#

Is there a way to check that a message exists?

#

Some kind of caching must be going on because my bot is thinking that a message still exists after being deleted

fresh sierra
sage tendon
boreal sky
fresh sierra
#

.rtfm fetch_message

boreal sky
#

Hmmm

#

I see

cobalt comet
#

how to create command groups inside cog?

rugged lodgeBOT
#

Here's the slash cog groups example.

little cobalt
#

@cobalt comet

cobalt comet
little cobalt
#

Idk if they also have groups

cobalt comet
#

how do i do this part inside cog?

little cobalt
little cobalt
cobalt comet
cobalt comet
little cobalt
#

just do that at a cog?

#

I dont really see the issue

cobalt comet
#

like what's the decorator for command group inside cog?

little cobalt
#

for the message command it is a good question

cobalt comet
fresh sierra
cobalt comet
rugged lodgeBOT
#

Here's the bridge commands example.

fresh sierra
deft kestrel
#

just a quick question so the discord.ext its just normal discord import?

sage tendon
#

message commands are something completely different

deft kestrel
#

how many inputs i can add to modal?

sage tendon
#

just blindly guessing from discord's usual limits, either 5 or 10

#

just try it shrug

deft kestrel
#

i checked and its 5 if i want more then 5 then i need two modals?

sage tendon
#

yea, but at that point i'd consider if modals are the right choice

#

why do you need so many different inputs

deft kestrel
#

for a ticket system

sage tendon
#

well, you cant follow up a modal with another modal instantly
so i think you have to make it another button press or whatever you do rn

#

or you combine multiple things into one textfield

little cobalt
deft kestrel
lapis dock
# deft kestrel yh yh

A good way to "hide" this drawback is to have the button actually serve a purpose instead of just saying "continue" you could have 2 buttons, a confirm and an edit for example

deft kestrel
#

pycord still isnt good with python 3.12 right

little cobalt
deft kestrel
sage tendon
#

works fine

#

Pycord works fine on 3.12

deft kestrel
#

so i can move to 3.12

sage tendon
#

that's what I'm saying

frail laurel
#

Do I really have to pass bot instance to every view with buttons I create?

class Report_vent(discord.ui.View):
    def __init__(self, bot):
        self.bot = bot
        super().__init__()

Can't I just do something like this?
report_channel = await interaction.fetch_channel(REPORT_CHANNEL)
without doing self.bot.fetch_channel xd

sage tendon
#

No

#

an interaction object does not have a fetch_channel method

#

and how many views do you have that this is an issue lol

#

also the naming convention for classes is Pascalcase, not a mix of snakecase and making the word capital

sage tendon
#

bruh

#

also don't use fetch unless you really have to

deft kestrel
sage tendon
#

well, install py-cord lol

deft kestrel
#

i have

sage tendon
#

you do not

deft kestrel
#

from the ```py
pip list

sage tendon
#

If you install a new version of python it does not have any modules

sage tendon
#

you should use a venv anyway, if you don't already

deft kestrel
#

i have venv

#
include-system-site-packages = false
version = 3.12.3
#

from the venv file

sage tendon
#

I don't think it's working then

deft kestrel
#

you maybe know how to fix this?

sage tendon
#

fix your venv I suppose

#

because I don't think it's working right

#

and uninstall python 3.11 to make sure there's no weird stuff

lofty parcel
sage tendon
#

ah, good to know

#

time to change all my views

modern trail
#

I'm refactoring my bot from a single module into cogs, and in the cog i'm testing, None is suddenly being returned from self.bot.get_channel when previously it was returning the channel object, what are possible reasons for that? Could it be missing intents or something? from not passing the bot object to the cog correctly? I went into a debugger and checked its value:

>>> self.bot.intents
<Intents value=3276799>
languid sage
#

Any way to edit a message of an expired interaction? (the 15 minutes limit)
The interaction is responded as it should but the command could take more than 15 minutes and can't edit it past it:
HTTPException: 401 Unauthorized (error code: 50027): Invalid Webhook Token

sage tendon
#

Usually happens when your get runs before on_ready

modern trail
#

oh hmm, so the cog loads before on_ready?

sage tendon
#

yes

#

i think you can use await bot.wait_until_ready() in the cog init
I'm not sure if that works but it should

modern trail
#

i'll look into that, thanks

sage tendon
#

Actually, it might get stuck lol
Because it loads the cog but the cog load gets delayed until the bot is ready which never happens
Well, tell me what happens, I'm curious now too

modern trail
#

haha i'll let you know then yea

#

oh wait, the cog's __init__ method can't return a coroutine, so I can't call that function at all

sage tendon
#

oh yea facepalm

#

im tired

modern trail
#

heh

sage tendon
#

honestly i just run the get_channel in every command i need it in, i never did it at cog level, so not sure what the best solution is for this

modern trail
#

yea I was originally just invoking it at the moment when I actually needed the channel, I've only changed it to being defined in the cog's init method because I figured if i could get away with just calling it once i might as well

#

but it's already cached, so i suppose it's not a big deal

sage tendon
#

yea maybe someone else knows the best way to do it at cog-level like this

modern trail
#

changed it back to invoking it when i need it and it works again, so you were definitely right about it not being cached yet. thanks for your help @sage tendon

sage tendon
#

np

pastel goblet
#

Does anyone know if its still possible to make command groups with a main command? So like
/command -> Does some thing
/command add-> Does something else
/command remove -> does something else

sage tendon
#

dont think thats possible or has ever been possible, no

fresh sierra
upper flint
#

When someone creates a forum thread

#

Does pycord fire on_thread_create() event?

#

How can I differenciate between threads in a text channel and in a forum channel?

upper flint
#

Thanks, will do

umbral gazelle
#

How to solve python int too large to convert to c int?

str(timedelta(seconds=round(track.length / 1000)))
sage tendon
#

what

umbral gazelle
sage tendon
#

well first of all i dont get the issue, and secondly, that is unrelated to pycord

umbral gazelle
upper flint
sage tendon
#

Am I being dumb?
Why does message.author return the bot for a slash command invocation?

#

Okay it was message.interaction.user
But is there a way to get the member object and not just the user?

sage tendon
#

ctx.guild.get_member(message.interaction.user.id).display_name
my god. fixed

errant trout
sage tendon
#

wasn't the case from my testing

#

because display_name didn't return my guild-nickname, just my global name

errant trout
#

idk always worked fine for me GuraSquintSmol

#

does interaction.user.nick work

sage tendon
#

nah i changed it now, dw, im not touching that again :>
(i dont wanna break it)

waxen ore
#

what am i doing wrong that the options are not displaying on discord?

code:

@bot.command(description="Choose loop mode")
@option("mode", description="Choose mode", choices=["none", "song", "queue"], required=True)
async def loop(ctx, mode: str) -> None:
sage tendon
#

did you restart discord? also, required=True is not necessary

waxen ore
#

why not if it is required?

sage tendon
#

because thats the default

lofty parcel
#

required defaults to true

waxen ore
#

oh, okay, i will check it and let u know

#

still nothing

#

it's like option decorator doesnt work

#

should i change @bot.command to @bot.slash_command?

sage tendon
#

i think you can't typehint it in the function header if you use the option decorator

#

but not sure

waxen ore
#

hmmm, let me check

waxen ore
sage tendon
#

remove the typehint
restart discord
try again

waxen ore
sage tendon
waxen ore
waxen ore
errant trout
#

if you are using discord.Bot, then bot.command is valid

#

but otherwise slash_command

waxen ore
#

and it doesnt work anyway

#

lol

#

i will try to use slash_command and let u know

lofty parcel
#

Can you try typehinting discord.Option instead of the decorator

sage tendon
#

my only idea still is that you didnt restart discord (not your bot, like, discord on your pc)
because that looks like it should work

waxen ore
waxen ore
sage tendon
#

thats very weird

#

i hate discord.Option ngl

waxen ore
#

but w/e, if it works dont touch it

#

btw bot.slash_command changes nothing

#

just fyi

sage tendon
#

where are you importing the decorator from

waxen ore
sage tendon
#

hm

#

i wanna know why it doesnt work for you lol

#

does it work in other commands?

waxen ore
#

i got one command that needs it

#

w8

#

i will create other one

shell radish
#

try removing the command, running the bot, then adding the command back

sage tendon
#

i was thinking it was the missing type parameter, but it should default to str, so idk

waxen ore
waxen ore
#

one more question, for some time now when i use any command it pops up for about half a second and then i get a response from my bot, it's not a big deal but it annoys me a bit, is it the fault of my bot or my discord?

waxen ore
#

do i need to reinstall?

shell radish
#

its just a bug that discord hasn't fixed yet because weekend or something

#

probably gonna be fixed on monday tbh

waxen ore
weary meteor
#

lets say i have a button which is attached to a message with an embed, how do i get the content of the embed, footer, title etc etc

shell radish
#

interaction.message.embeds[0]

weary meteor
#

ah okay, thank you

weary meteor
shell radish
#

yeah, surely, you know how to get the information from an Embed object, right?

weary meteor
#

ah yeah nvm im a little slow, im more than a couple beers in 😅

shell radish
#

code is best served when sober

balmy flicker
#

is create_thread a correct way to create post in a forum channel? it runs without any effect. no errors, no warnings.

errant trout
edgy nest
#

thats a normal channel

#

not forum

fresh sierra
fresh sierra
sage tendon
#

no, I get them as part of channel history for a certain purpose

fresh sierra
#

Ok

quartz umbra
#

Is it possible to edit a user's message?

sage tendon
#

No

quartz umbra
#

I've seen a bot that like imitates a user, like my name and profile but it says APP next to it

#

how does that work?

sage tendon
#

That's a webhook

quartz umbra
#

that's what a webhook is?

sage tendon
#

Webhooks can be used for a lot of things

quartz umbra
#

Hmm. Do you have any idea how I might approach adding something like this?

sage tendon
#

no idea

quartz umbra
#

alright thank you

#

is it true that code for discord.py has a chance at working with pycord?

sage tendon
#

less so every day

quartz umbra
#

i see

sage tendon
#

pycord is a discord.py fork, but everything since slash commands were added is different
discord.py does slash commands completely differently than pycord, for the worse because discord.py's version sucks

lapis dock
#

Most of the code inside your commands should still work for the most part (you might have to change a few lines relating to how you respond) as that is mostly just python

quartz umbra
#

I see. I do prefer py-cords version. Can I clarify something? I've just watched a youtube video and from my understanding, are webhooks just a way for someone to interact with a discord guild via POST HTTP requests?

lapis dock
#

That sounds about right

#

You can get started with them here

#

.rtfm Webhook

quartz umbra
#

I see. Is it possible to create and delete webhooks entirely programatically if the bot has administrator commands?

sage tendon
#

yes

quartz umbra
#

Alright, so to my original problem of attempting to imitate a user, when i wanna send a response, does this pseudocode sound right? ```

  • create new webhook with username as user and profile pic as user
  • create coroutine that sends a POST request to this webhook url to send the actual response
  • Delete webhook
By the way, do webhooks register immediately?
sage tendon
#

wdym immediately

quartz umbra
#

like you know how global slash commands can take upto an hour to register while when you set guild ids its essentially immediate? I wanted to know if this process occurs quick enough to be feasible.

#

And for final clarification (so sorry!), it is possible to create a webhook url in pycord only, right?

sage tendon
quartz umbra
sage tendon
#

slash commands are virtually instant

#

its just a dumb thing discord said when they were released

quartz umbra
#

oh i see.

sage tendon
#

it might take longer with HUGE bots but idk

sage tendon
#

it might seem that they take longer because the discord client is slow as hell, thats why you always restart discord after adding / changing a command

lapis dock
#

It did used to take that long, they just made it better and there is less stress of bots switching over

quartz umbra
# sage tendon wdym

like a webhook is an interface where you can customize the username and profile picture, right? They each carry a URL. I understand you can create a webhook instance from a URL, but is it possible to create a brand new webhook with URL in a given channel in py-cord only? (and delete it)

sage tendon
quartz umbra
#

I'm so rusty to discord bot dev, I haven't made one in like 2-3 years 😅

lapis dock
#

all good, we are happy to help

quartz umbra
#

🙂

errant trout
#

Per channel

#

Every time you send on a webhook, you can do it with a custom name and profile picture

sage tendon
#

But that will affect old messages via the webhook too, no?

errant trout
#

No

#

When you create a webhook, the username and pfp are just default placeholders

#

Webhook.send includes username and avatar_url params

sage tendon
#

So if i send a message with a red pfp, and then a message with a blue pfp, and restart discord, both messages will still have their proper pfp?

errant trout
#

Yes

sage tendon
#

I guess I need to teach a certain bot dev about that then because they are KILLING my webhook section in my server

errant trout
#

If you've ever seen bots like tweetshift in action it might make more sense

sage tendon
#

doesn't that create a huge storage concern for discord though? i mean those pfps are essentially "undeletable"

errant trout
#

Eh

#

That's no different from any attachment on discord

lapis dock
#

sounds like a discord problem doggokek

errant trout
#

They're attached to the message itself

errant trout
sage tendon
#

Does a deferred message just have None as its content?

errant trout
#

Idk if it counts as a message

sage tendon
#

I am almost certain it does, i had a few issues when a deferred message was put into the channel mesage history

errant trout
#

Well

#

Just defer -> print message content -> respond and see what happens

sage tendon
#

how to get the ctx message again 💀 i hate how its not ctx.message

fresh sierra
#

ctx.messagz return None

sage tendon
#

ctx.response right

fresh sierra
#

Ctx.message is user command so ctx.message can’t be the response of the bot

#

Cos bridge will break everything

errant trout
#

If you defer, can you right click > copy id

fresh sierra
#

I forgot that

errant trout
#

Then fetch it and see what happens

#

The problem with this concept is that intrinsically, first response does not return anything useful

#

Maybe get_original_response works idk

fresh sierra
sage tendon
#

Ok, a deferred message's content is an empty string

errant trout
#

There you go

fresh sierra
sage tendon
#

what

fresh sierra
sage tendon
#

invisible doesn't apply to application commands

errant trout
#

They mean ephemeral

#

Probably works

sage tendon
#

i doubt it'd be different

quartz umbra
#

Wait so then if I only have to make one webhook per channel, is there a way to see if there's an existing webhook for a channel so I don't have to store a dB?

#

Noting all the URLs?

#

Like, if there's no webhook on the current channel, create one, if not, use the existing one

fresh sierra
errant trout
#

invisible DOES exist, but only for components

fresh sierra
errant trout
#

it hides the "thinking" text

fresh sierra
errant trout
#

oh no you were correct

#

guild.webhooks fetches every webhook in the guild

#

didn't consider that

#

then you can just filter by webhook.channel

fresh sierra
#

both can work

quartz umbra
errant trout
#

webhooks isn't an attribute; you have to fetch

#

so what i'd recommend is on startup you fetch all the webhooks you have, then you can check it using a basic filter