#Basic Pycord Help

1 messages · Page 34 of 1

sage tendon
#

yea because thats not how activities work

shell radish
#

activites have barely anything to do with discord

#

it's majority website stuff

deft kestrel
shell radish
#

and pypresence supports the Discord authentication part

sage tendon
shell radish
#

you only need the sdk if you are interacting with discord (which you may or may not need)

sage tendon
#

I have yet to hear of native python support in browser engines

shell radish
deft kestrel
#

ts = 🤮

sage tendon
#

-> any

lofty parcel
#

Bleh, just curious, does ApplicationContext have a method to respond with a response type 10? aka premium button

sage tendon
#

like to bring up the premium subscribe modal?

lofty parcel
#

Yeah, the response with a button to subscribe

#

It's only for apps with monetization, but pycord supports entitlements and that, so...

sage tendon
#

not sure, i dont think so

lean garnet
#

Hi, is it possible to use automod via Pycord ? (to obtain this badge)

shell radish
#

yes

deft kestrel
#

how i can make an option in a command that has only the staff in my server?

sage tendon
#

use choices=[discord.OptionChoice...

#

read the docs on optionchoice

deft kestrel
#

thanks i will take a look

boreal sky
lean garnet
#

I streamed a game for 15 mins to obtain it

boreal sky
#

I'm so confused

lean garnet
#

I was thinking you asked for this badge

lean garnet
boreal sky
lean garnet
#

sorry

boreal sky
lean garnet
boreal sky
#

Got a link for that one?

lean garnet
#

maybe

#

I'll check

boreal sky
#

I see

#

Interesting

deft kestrel
#

what sql system i should use sqlite3 , aiosqlite or something else?

little cobalt
deft kestrel
little cobalt
#

one is asyncio one is not

deft kestrel
little cobalt
#

use aiosqlite

#

you might have to change a few things

deft kestrel
#

ok

fresh sierra
#

Is that really better to use a asynchronous db than a def of it doesn’t change that lunch thing

little cobalt
#

I dont use aiosqlite for my DB

deft kestrel
little cobalt
#

pymongo with motor (MongoDB) which is a NOSQL DB

deft kestrel
#

is it possible to make the bot use a command?

lofty parcel
deft kestrel
sage tendon
#

copy the code?

#

or make a helper function and call that in both commands, or whatever

#

you have the entirety of python to work with

keen stag
#

hey for some reason I keep getting this error: AttributeError: 'NoneType' object has no attribute 'edit'
from the following function:```py
@tasks.loop(seconds=10)
async def updateEmbedMessage(self):

    if(self.configManager.getMessageId() == ""):
        print("No Embed Message")
        return
    
    message: Message = self.configManager.getMessagebyId(self.bot, self.configManager.getMessageId())
    values = self.getEmbedData()

    statusEmbed = StatusEmbed.getEmbed(
        serverName= values["serverName"],
        playerOnline= values["players"],
        maxPlayer= values["maxPlayers"],
        latency= values["latency"],
        iconLink= values["iconLink"],
        statusColor= discord.Color.green()
    )

    await message.edit(embed=statusEmbed)
    print("Update Embed")
I dont know how to fix this right now.
sage tendon
#

message is none

#

error is quite clear about that

keen stag
#

but why

sage tendon
#

thats for you to find out

keen stag
#

It should get the message from my configManager.

sage tendon
#

whatever your message getting function is, it doesnt work properly

sage tendon
dense summit
#

It's not really related to Pycord but i would need help, im using requests and when i pass the proxies in the parameters it doesn't use them and it returns my IP

#

How can i fix that?

deft kestrel
#

how i can check if a user has the permission to manage_channels?

sage tendon
#

@discord.has_permissions(manage_channels=True)
or you use the @discord.default_permissions(manage_channels=True) decorator to hide the command from them entirely which is usually better

sage tendon
#

and you should never use requests

keen stag
#

Hey back again with another problem. For some reason the ```py
message: Message = self.bot.get_message(self.configManager.getMessageId())

Wont give me the message. But the getMessageId works.
sage tendon
#

the message isnt cached

keen stag
#

?

sage tendon
#

its not in the bots cache

#

so it can't be get'd

#

use discord.utils.get_or_fetch

keen stag
#

can you give me an example. I dont understand how to use it.
This is what I have right now:

            message: Message = utils.get_or_fetch(channel, 'message', self.configManager.getMessageId())
sage tendon
#

well, does it work?

#

(check first if the channel is not null as well)

shell radish
sage tendon
#

right

keen stag
#

it says channel not defined so I tried it with the dicord.TextChannel. There I get the error discord.TextChannel has no attribute 'get_message'.. And I tried it with await still doesent work

sage tendon
#

get the channel first

#

should normally be cached

keen stag
#

So I need to save the channel id too?

sage tendon
#

well, yes

shell radish
#

I don't think get_or_fetch is applicable here

sage tendon
#

no?

shell radish
#

since messages aren't cached with channel objects

sage tendon
shell radish
#

probably just message = get() or await fetch(), although you need to handle the error in case the message is deleted or something

keen stag
#

can you give me an example or send me a documentation page?

shell radish
#

what do you not understand?

keen stag
#

how does get() work?

shell radish
#

it is pseudocode

#

get represents bot.get_message here

sage tendon
#

they did trhat tho

#

its not cached

keen stag
#

yea

#

thats why I asked

#

The main problem is that I dont have Context. I run this in a Task.loop

sage tendon
#

i still think get or fetch should work but squid says it doesnt so idk

keen stag
#

@shell radish Do you have any Idears?

sage tendon
#

cna you still try get_or_fetch, and pass the channel you get via bot.get_channel

#

because the channel should be cached

keen stag
#

I try that.

sage tendon
#

squid might be right tho

tranquil thicket
#

When I am trying to add a slash command inside a cog i get an error saying Bot has no attribute 'add_command'

sage tendon
#

why are you using that?

tranquil thicket
#

I need the slash command to be able to access a member variable in the cog

sage tendon
#

you dont use add_command
you just use the decorator

tranquil thicket
#

I used the @commands.command decorator

sage tendon
#

ah, hm

#

which pycord version

tranquil thicket
#

2.4.1

#

I downgraded from 2.5 because of a bug a few weeks ago

fresh sierra
sage tendon
#

what bug

tranquil thicket
#

I can't remember hold on

sage tendon
#

not aware of any noticable bug with 2.5 rn

fresh sierra
tranquil thicket
fresh sierra
#

json are not that good

fresh sierra
#

just open the github repo

#

you will see a lot of them

tranquil thicket
#

yeah thought about that was just trying to do a quick and dirty but should use a small db

sage tendon
sage tendon
fresh sierra
#

like the fact that the / commands are just broken

tranquil thicket
sage tendon
tranquil thicket
#

has nothing to do with other bug

sage tendon
#

do you use bot.add_command anywhere manually

tranquil thicket
#

no

fresh sierra
sage tendon
#

literally zero issue on 3 slash only bots on 2.5

fresh sierra
#

so you dont have issue = there is no issue...

#

man pls

sage tendon
fresh sierra
#

but yes is true that the slash commands doesnt unload when a cog is unloaded is not a bug

sage tendon
fresh sierra
#

you should use bot = commands.Bot and not discord.Bot or discord.Client

tranquil thicket
#

That may be it

sage tendon
#

discord.Bot is slash only i think

tranquil thicket
#

Changing to commands.bot let it run at least

fresh sierra
#

.tag client

sly karmaBOT
#
discord.Client # just for events
discord.Bot # events + slash/user/msg commands
commands.Bot # above + prefixed commands
bridge.Bot # above + bridge commands (application commands and text commands in one)
fresh sierra
#

so you should have bot = commands.Bot(command_prefix="yourprefix")

tranquil thicket
#

none of my commands are available but it doesnt error

#

I just want slash commands tho

fresh sierra
tranquil thicket
#

i dont care about the prefix

fresh sierra
#

that's for prefix commands

#

.rtfm slash_commands

sage tendon
#

if yo uwant slash commands use discord.Bot and discord.slash_command

fresh sierra
sage tendon
#

.rtfm slash

fresh sierra
#

here

sage tendon
#

wonder if rtfm means read the fucking manual

fresh sierra
#

moght be

rugged lodgeBOT
#
The name's Bond

I'm here to keep the server organized.
The dropdown below lets you view commands I offer.

Server Count

102

Member Count

13760

Ping

108.14ms

shell radish
lofty parcel
#

Why the hell get_or_fetch requires a channel?

sage tendon
#

?

fresh sierra
shell radish
fresh sierra
#

i got a ping in a post that disappear

#

i will never know what was the question

shell radish
#

it doesn't work because channel doesn't have any message-related attrs that g_or_f accepts

winged vault
#

Does pycord support the discord store purchases?

#

Like being able to detect if a purchase has gone through

winged vault
lofty parcel
#

Oh, lol, fetch is a method from a channel not the bot. Yeah.

fresh sierra
#

what is discord store purchases ?

#

like entitlement

shell radish
winged vault
#

oh

shell radish
#

actually, it seems like it is gateway so you should open a github issue as a feature request

sage tendon
#

isn't that what SKUs are?

shell radish
austere moth
#

in what order does discord.Interaction callback is called?
I have multiple discord.Interaction callback in View and Modal subclasses. but it seems like on_interaction listener is called first.
is there a way to prioritize active View or Modal callback over commands.Cog listener? or maybe to ignore it?

edgy nest
#

there's no specific order in which they're executed, they're just scheduled and run concurrently when it recieves the event

fresh sierra
austere moth
#

I have a clear objective on each interaction but for some reason Modal and View callback is ignored when there's on_interaction listener in the Cog

fresh sierra
#

Because with that listener it then ignore the callback because the callback is handle in the on interaction I guess

austere moth
#

because the interaction callback in View's interaction_check didnt get called for some reason

austere moth
#

sure, give me a moment

#
class EditorView(View):
    def __init__(
        self,
        name: str,
        message: discord.Message = None,
    ):
        super().__init__(timeout=None)
        self.name = name
        self.ticket_message = None
        if message is not None:
            self.ticket_message = message
            # just to add Buttons/Selects
            self.setup_items()
        else:
            raise AttributeError("message cannot be None")

    async def interaction_check(self, interaction: discord.Interaction):
        modal = EditorModal(self.ctx, self.name, message=self.ticket_message)
        match interaction.custom_id:
            case "add_select":
                modal.add_select()
                await interaction.response.send_modal(modal)
            case "add_option":
                modal.add_field()
                await interaction.response.send_modal(modal)
            case "edit_embed":
                modal.edit_embed()
                await interaction.response.send_modal(modal)
        return True
class EditorModal(Modal):
    def __init__(
        self,
        ctx: discord.ApplicationContext,
        name: str,
        message: discord.Message = None,
    ):
        super().__init__(title="Ticket Editor")
        self.ctx = ctx
        self.name = name
        self.action = None
        if message is not None:
            self.message = message
        else:
            raise AttributeError("Message cannot be empty")

    async def callback(self, interaction: discord.Interaction):
        match self.action:
            case "add_select":
                await self.callback_select(interaction)
            case "edit_embed":
                await self.callback_embed(interaction)
            case "add_field":
                await self.callback_field(interaction)
            case None:
                await interaction.response.send_message("Unknown Interaction")
                self.stop()
fresh sierra
#

Because the setup items is the one that receive the callback

#

For the interaction check can be triggered

austere moth
#

Setup items is just bunch of add items tbh

def setup_items(self):
    self.add_item(
        Button(
            label="Add Select",
            custom_id="editor-select-add",
            style=discord.ButtonStyle.green,
        )
    )
    self.add_item(
        Button(
            label="Edit Title/Description",
            custom_id="editor-embed-edit",
            style=discord.ButtonStyle.green,
        )
    )
    self.add_item(
        Button(
            label="Add Field",
            custom_id="editor-field-add",
            style=discord.ButtonStyle.green,
        )
    )
    self.add_item(
        Select(
            placeholder="Select Field to Remove",
            custom_id="editor-field-remove",
            options=(
                [
                    SelectOption(label=field.name, value=field.name)
                    for field in self.ticket_message.embeds[0].fields
                ]
                if len(self.ticket_message.embeds[0].fields) > 0
                else [SelectOption(label="No Fields", value="No Fields")]
            ),
        )
    )
    view = View.from_message(self.ticket_message, timeout=None)
    self.add_item(
        Select(
            placeholder="Selection to Remove",
            custom_id="editor-select-remove",
            options=(
                [
                    SelectOption(
                        label=", ".join(
                            [option.label for option in select.options]
                        ),
                        value=select.custom_id,
                    )
                    for select in filter(
                        lambda item: isinstance(item, Select), view.children
                    )
                ]
                if len(list(filter(lambda item: isinstance(item, Select), view.children))) > 0
                else [SelectOption(label="No Selects", value="No Selects")]
            ),
        )
    )
fresh sierra
#

You add the items but you don’t put any callback

#

You need to pass the callback

#

You can do button = …

#

Button.callback =

#

Self.add item (button)

#

And then you can remove ur listener

austere moth
#

the bulk of the callback is in Modal subclass, didnt include it since it's too long to fit in a single message
every callback is based on the component's custom id and I just used match case to determine which function to call with the given id

also idk that it's possible to set a callback with Button.callback

fresh sierra
austere moth
# fresh sierra How did you set the callback so ?

subclassing Modal

async def callback(self, interaction: discord.Interaction):
    logger.info("[EditorModal] Interaction with ID: %s", interaction.custom_id)
    match self.action:
        case "modal-select-add":
            await self.callback_select(interaction)
        case "modal-embed-edit":
            await self.callback_embed(interaction)
        case "modal-field-add":
            await self.callback_field(interaction)
        case None:
            await interaction.response.send_message("Unknown Interaction")
            self.stop()
async def callback_select(self, interaction: discord.Interaction):
    view = View.from_message(self.message, timeout=None)
    self.item = Select(
        placeholder=self.children[0].value, custom_id=f"ticket-{self.name}-options"
    )
    options = re.split(r"[,\n]", self.children[1].value)
    for option in options:
        self.item.add_option(label=option, value=option)
        k = re.split("\W+", option)[0].lower()
        config.update(f"tickets.{self.name}.options.{k}", option)
    save_config()
    view.add_item(self.item)
    view.add_item(TicketButton(self.name))
    await self.message.edit(view=view, embeds=self.message.embeds)
    await interaction.response.send_message("Select options added!", ephemeral=True)
    self.stop()
async def callback_embed(self, interaction: discord.Interaction):
    title = self.children[0].value
    description = self.children[1].value
    config.update(f"tickets.{self.name}.title", title)
    config.update(f"tickets.{self.name}.description", description)
    save_config()
    if len(self.message.embeds) > 0:
        self.message.embeds[0].title = title
        self.message.embeds[0].description = description
    else:
        self.message.embeds = [discord.Embed(title=title, description=description)]
    self.message = await self.message.edit(embeds=self.message.embeds)
    await interaction.response.send_message("Embed updated!", ephemeral=True)
    self.stop()
#

I changed almost all custom ids to make it easier just now

fresh sierra
#

I don’t see anything about call back for the button here

#

Whatever, I think you should redo it using the button.callback method

#

It will be better for you and for the future

#

Do you want to see an example of how it looks ?

austere moth
#

not really, I already have something in mind as to how to do it

#

thanks for confirming that Cog's listener overrides everything on subclasses though

fresh sierra
#

But you might just do something really hard for nothing

austere moth
#

totally can see myself having that doggokek
well it's more fun that way

fresh sierra
#

you might face limitation

#

but if want to do that do it ;)

austere moth
#

thanks again btw. really helps

fresh sierra
#

with pleasure

#

im only doing that kind of thing

#

good luck tho

stray pasture
#

Does anyone know where that error could be coming from ?

#

It is happening randomly, and making the bot crash completely

sage tendon
#

do you have bad net?

stray pasture
#

but in that case, the bot crashes completely, it does not even fire the events for reconnection

maiden bloom
lofty hedge
#

what version of python does latest version of py-cord support

sage tendon
#

3.12

elder girder
#

Is it normal for my sharded bot to fire on_ready() some time after launch? I have some tasks that start there and I get errors for the bot trying to start those tasks again in on_ready() while they're running.

sage tendon
#

p sure that can happen, yes

#

i mean it does for you, so, yea

elder girder
#

Is it okay to let that happen or should I add a flag to prevent it?

#

I already made it check if the tasks are running before trying to launch them so the errors are gone.

sage tendon
#

ah, yea, then its okay

elder girder
#

Although I don't want it to reset my database connections and HTTP clients so I'll probably just prevent executing it more than once.

fresh sierra
shell radish
atomic fern
#

how to catch 400 bad request missing permission (the bot) in on_command_error event? I'm using commands.BotMissingPermissions but not catched

elder girder
fresh sierra
#

But I’m not sure about that

#

Maybe someone her can correct me if I’m wrong

sage tendon
atomic fern
#

edit role position to be higher than author top role position

elder girder
sage tendon
#

dont wait for the error to happen to handle it :>

maiden bloom
#

Is it possible to assign a user a role while a bot is starting up but hasn't reached on_ready() yet? Can I run a separate instance until the initial bot has reached the on_ready()? Using AutoShardedBot

#

I'm assuming event listeners such as on_guild_join() aren't triggered until the bot is ready as well?

grizzled loom
grizzled loom
# sage tendon what are you doing that causes that error

brings up a question i never thought about. what would happen if their highest roles are equal and both have permissions to edit roles?
(context; meaning both, the bot and the member were assigned a self made role that's higher than the bots role)

#

assuming we did an equal or higher check of course!

maiden bloom
grizzled loom
maiden bloom
grizzled loom
#

all have their up and downsides obviously

maiden bloom
fresh sierra
grizzled loom
# sage tendon not possible

i mean it should be possible to, for example, kick someone with an equally high role, if the bot has kick permissions and the member does not have admin.
interesting that it's not doable for role manipulation, wasn't aware! : D

sage tendon
#

that would be absolutely catastrophic

grizzled loom
#

never thought about it before, had no need to

sage tendon
#

that would mean any mods in any server could kick every other mod

grizzled loom
#

I stated if one has the permission to kick and the other does not

sage tendon
#

Something that's doable with a teamspeak-like permission system though :3

grizzled loom
#

hahahaha 😄

#

Yeah, you're right, does sound catastrophic! 😄

#

guess we just found sth. discord does better

sage tendon
#

better than teamspeak? hell no

grizzled loom
#

the kick szenario i meant.

sage tendon
#

but safer, considering all the nuts that claim to "own" servers, yet have not a clue about anything beyond creating channels

sage tendon
grizzled loom
#

I think that's better. kicks and bans should be allowed with some safety in mind.

vestal folio
#

how do i get the user id of the user who presses the button?

sage tendon
#

read the docs

#

or member

little cobalt
vestal folio
maiden bloom
lofty parcel
lofty parcel
little cobalt
lofty parcel
little cobalt
#

@frail ocean did the docs bite you?

lofty parcel
#

Lmfao the actual ping and question kills me

frail ocean
little cobalt
#

@lofty parcel no

#

get that star away

lofty parcel
#

oh yes

little cobalt
#

no

lofty parcel
#

How many do we need? 2? 3?

little cobalt
#

Im not gonna say how many you need for it xd

frail ocean
viscid bobcat
#

hello!

#
def some_func(id=message_id):
    guild = bot.get_guild(guild_id)
    channel = guild.get_channel(channel_id)
    bot.loop.create_task(some_other_func(channel, id))

any idea why this keep returning none for the guild ? my id is correct i double checked

grizzled loom
viscid bobcat
#

it's a global variable

#

it's not a scope issue neither

grizzled loom
viscid bobcat
#

I will clean up my code later, i am just trying to see if i can execute functions without using the bot

#

basically, i would like to execute actions with a bot using fetches without using a webhook

#

can't find infos about this in the docs

grizzled loom
#

with only the message, asssuming it is type discord.Message, available you can:

message.author.guild.id

IF you have the members intend in your bot.

#

else you may try guild_id instead, idk if that's availible within this context though.

#

this should deliver the guild id if your bots cache is loaded and you have the needed intents

viscid bobcat
#

that is not meant to be a message interaction, will it still work ?

#

i mean, would I be able to execute my function in python (so use it along with a fetch afterwards?)

grizzled loom
#

oh right. you only have a message id

viscid bobcat
#

guild is predefined as well as the channel

grizzled loom
#

before we start over complicating things, give some context please. why does this function only have this id available? and can you give it something more useful like the message object itself or ctx or.. any other sensible starting point?

viscid bobcat
#

what i am trying to do is recreate this slash command in ways that could be used without direct interactions with the bot

@bot.slash_command()
async def hi(ctx, message_id=int(message_id)):
    channel =bot.get_channel(int(channel_id))
    message = await channel.fetch_message(message_id)
    out = message.attachments[0].url
    await ctx.respond(out)
#

(get first attachment url by message id)

sage tendon
#

I'm so confused about that

viscid bobcat
#
def get_img_by_id(id=message_id):
    image_url = ''
    guild = bot.get_guild(guild_id)
    channel = guild.get_channel(channel_id)
    bot.loop.create_task(retrieve_image(channel, id))


async def retrieve_image(channel, id=message_id):
  await bot.wait_until_ready()
  await channel.send('Uploading...')
#   message = channel.fetch_message(id)
#   image_url = message.attachments[0].url.split("/")[5]
#   return image_url

would result into something like this..

grizzled loom
#

why not use ctx? everything you'll need is in there

viscid bobcat
#

can i use ctx without bot interaction ?

sage tendon
#

No

grizzled loom
#

you cant do any slash command without bot interaction at all

viscid bobcat
#

what i am trying to do is retrieve images so ctx wont work for me then

sage tendon
#

I might be a bit dumb rn but what even is the point of this, especially without ever interacting with the bot

viscid bobcat
#

to address the issue of discord new image urls

grizzled loom
#

I fail to see how getting some pic would make bot interactions unusable

viscid bobcat
#

there is no more permanent urls for hosted images through discord but message id is still permanent

#

if i store a pic through discord i cant retrieve it after approx one week

#

but if i get this url through message id, it would be the latest url so it will work

grizzled loom
#

I think I am starting to understand

#

did you try fetching the message with the picture instead of getting it?

viscid bobcat
#

wdym by fetching the message ? what would be the difference ?

grizzled loom
viscid bobcat
#

would be perfect but i read on internet that i can't use api for such purposes as it requires the bot for auth

#

maybe i'm wrong

grizzled loom
#

it's recommended to go easy on fetch operations, cause each one will send an api request and therefore may lead to reaching a limitation if you overdo it. However if you need an object, regardless if its a member or a message and get returns None you try fetch next.

Keep in mind that fetch can still fail, when the message was deleted or the bot is not allowed to see history or was removed from a server or some such thing. in those cases the message you're trying to fetch will still be None.

viscid bobcat
#

i really don't know what to do, let me give an example

#

here is an image that i just uploaded

#
https://media.discordapp.net/attachments/1132206148309749830/1233727789299929098/image.png
#

before this was enough to retrieve it

#

but now, if you try to open this url it wont work, it will give an error like "This content is no longer available."

#

so if you want to get the file (eg. by opening in browser) there is some kind of secret added to the url which renews each week

#
https://cdn.discordapp.com/attachments/1132206148309749830/1233727789299929098/image.png?ex=662e260a&is=662cd48a&hm=db7ae0051a25f9f7406479574517967c5f1e34786a239d8eabfdbca1996b8abc&

so i can access this url like this but next week it will no longer be working, i just need to figure out how can i get my images to work again

sage tendon
viscid bobcat
#

i'll just look for some other ways to host my images

sage tendon
#

image links will always work within discord

#

can't you just copy the URL?

fresh sierra
sage tendon
#

yes

#

#discord-api-updates

#

I already said that

viscid bobcat
#

it sucks

viscid bobcat
#

i was hosting images through discord since almost 2 years now

#

and, i am using them for my summary notes and stuff (for class)

sage tendon
#

For outside discord? yeah, that's just not what discord is for, and exactly what they're trying to prevent now

viscid bobcat
#

now all users lost their pfp and all the posts no longer have their images

#

i don't even know where should i move my stuff now

#

i am hosting my website through free services (as well as the db) and it wont be enough to start hosting images, especially since there is no rates about how uch images can be uploaded

#

any idea of a free permanent alternative ?

sage tendon
#

not for free

viscid bobcat
#

replit woudl've been a great alternative if they had not shut down their free hosting service (10GB disk for free)

grizzled loom
#

come now, toothy, how much is a ten GB plan? we can get virtual machines with like 30 for just shy of 3$ if its only for storage. must be a fraction of that, not a reason to steal in my book.

sage tendon
#

wasnt commenting on that

grizzled loom
#

i am not exactly sure how to read this emoji

sage tendon
#

"damn didnt expect that harsh response suddenly"

grizzled loom
#

me neither, just hit a nerve there.

tribal crown
#

👋

How is is that I send a message to a specific channel?

I'm currently trying:

info = self.get_channel()
await info.message.send("Astral Dynamics Assistant is ready!")

But this is giving me a TextChannel object has no attribute message error.

I've used ctx.respond/send etc.. but this message doesn't have a ctx to respond too 😄

sage tendon
#

yea, discord.TextChannel doesnt have .message :)

#

it's just .send

#

.rtfm TextChannel

tribal crown
#

I'm an idiot x)

#

Thanks

#

I ddn;t see ".send" at all D:

viscid bobcat
sage tendon
viscid bobcat
#

i made my own tool adapted to my personal usage, that's the reason
it is basically markdown with extended support (supports all of discord functionnalities, twemojis, multiple themes, custom textboxes, ability to insert images from web quickly, ability to create multiple choice questions, LaTeX...) w/ live preview

deft kestrel
#

how i can handle

discord.ext.commands.errors.MissingPermissions
sage tendon
#

check if you have permissions before doing what you're doing

deft kestrel
#

i am doing this:

    # auto craetes logs
    @commands.slash_command(name="auto-setup-logs", description="setup every thing for you that related to logs")
    @commands.has_permissions(manage_channels = True)
    @commands.cooldown(1, 10)
    async def setup_logs(self, ctx, staff_role: discord.Role): 
        try:
            #the rest of the code:
        except (discord.ext.commands.errors.MissingPermissions) as e:
            ctx.response.send_message("You dont have permission to do this!",  ephemeral=True)
sage tendon
#

again, check permissions before trying to do whatever you're doing in the try

#

there's no need to wait for it to error, make sure it can't happen

#

and i'd use @discord.default_permissions for slash commands

deft kestrel
little cobalt
#

you can also use has_permissions

#

its fine but the permission cannot get changed for it

sage tendon
#

has permissions wont hide the command from the user for all i know

little cobalt
#

that is right

sage tendon
#

what are you doing

tribal crown
#

🤔 I just added a command to my bot. Restarted it, but now it doesn't have the new commands on the server?

sage tendon
#

restart discord

little cobalt
#

@deft kestrel you also should start to use an Error Handler for your commands so you dont need all the try and except at your code

deft kestrel
#
    # auto craetes logs
    @commands.slash_command(name="auto-setup-logs", description="setup every thing for you that related to logs")
    @commands.has_permissions(manage_channels = True)
    @commands.cooldown(1, 10)
    async def setup_logs(self, ctx, staff_role: discord.Role): 
        if (ctx.user.has_permissions(manage_channels = True)):

like that?

sage tendon
#

no

#

again, what are you doing in the code

tribal crown
#

Magic, it worked

deft kestrel
#

creating every channel i need for the logs
add it db and thats it

sage tendon
#

Then check if your bot has permissions to create a channel
if not, return

tribal crown
sage tendon
#

wtf no

tribal crown
#

I tried it once.. it was terrible

deft kestrel
deft kestrel
sage tendon
#

That's not the error you're getting

#

you get that error because your BOT cant create the channels

deft kestrel
#

he can create in my account i can
but on my alt i cant because in my alt he doesnt have the permissions

sage tendon
#

or wait no

#

Yea, well, again

#

use @discord.default_permissions

#

i told you this a while ago, too

#

and 5m ago too

#

has_permissions should not be used

grizzled loom
#

If i read your code correctly the error is caused because of the @permission decorator. It stops the command from executing if the user does not have the needed permissions and therefore raises an error instead of doing its job.

there is several ways how you can resolve it

#

a) remove the decorator, control access through server settings
b) have your own permission check that checks what permissions the command user has, return if the wanted ones are not among them (or send a response and return/end the command afterwards)
c) leave as is and build an error handler

sage tendon
deft kestrel
sly ember
#

why is player still not defined

sage tendon
#

probably because whatever you're doing is not right at all

#

what is [Players] supposed to be

#

you can either have a string or a single member as input type (among a few others, and I suppose you pass these 1:1 from a slash command option)

#

your IDE even tells you it's not correct by the squiggly line under it

#

and I'm not sure you understand what a classmethod is

#

remove that decorator

#

If you want to typehint a list of something, you need to use list[type]

sly ember
sage tendon
#

I mean, read the error and read your code

#

your auto responder is also missing a setup function

fresh sierra
#

i just did one yesterday

sly ember
#

😂

fresh sierra
#

good luck with that

#

if you want look #creations can still help for the visual

lofty parcel
#

How the fuck you make a tetris game on discord

sage tendon
#

mfw you need 50 edits just for one piece to drop

fresh sierra
#

i will do like my snake game

sly ember
#

cant fix this sht damn it

Unhandled exception in internal background task 'checkGames'.
Traceback (most recent call last):
  File "C:\Users\lenov\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\tasks\__init__.py", line 169, in _loop
    await self.coro(*args, **kwargs)
  File "c:\Users\lenov\Desktop\cogs\cogs\gewinnt.py", line 98, in checkGames
    games = await Connect4.getAll(self.pool)
  File "c:\Users\lenov\Desktop\cogs\cogs\gewinnt.py", line 220, in getAll
    async with self.pool.acquire() as conn:
AttributeError: 'Pool' object has no attribute 'pool'

https://paste.pythondiscord.com/4TPQ

fresh sierra
#

but with tetris

lofty parcel
#

I'm also surprised by the snake game

#

My god, makes me feel dumb

fresh sierra
fresh sierra
#

snake ?

lofty parcel
#

Autocorrect

fresh sierra
#

dw

#

why are u surprised ?

sly ember
lofty parcel
fresh sierra
#

from main import ...

fresh sierra
sly ember
sage tendon
#

I've seen you here like 10 times now with the exact same issue but it's always ever so slightly different

sly ember
#

😅

fresh sierra
lofty parcel
fresh sierra
#

and the ... should be ur database

lofty parcel
#

Can't you just self.bot.pool

sly ember
#

i hate my life, cant even fix this god damn error

fresh sierra
sly ember
# fresh sierra <@1200442339475345461> did u try that ?
Unhandled exception in internal background task 'checkGames'.
Traceback (most recent call last):
  File "C:\Users\lenov\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\tasks\__init__.py", line 169, in _loop
    await self.coro(*args, **kwargs)
  File "c:\Users\lenov\Desktop\cogs\cogs\gewinnt.py", line 98, in checkGames
    games = await Connect4.getAll(self.pool)
  File "c:\Users\lenov\Desktop\cogs\cogs\gewinnt.py", line 220, in getAll
    async with self.bot.pool.acquire() as conn:
AttributeError: 'Pool' object has no attribute 'bot'
lapis dock
#

your getAll is a static method, static methods do not take a self argument

#

So

games = await Connect4.getAll(self.pool)
...
 @staticmethod
async def getAll(self):
    async with self.pool.acquire() as conn:

So self is treated as a normal positional argument so essentially you are doing
self.pool.pool.acquire
as in getAll self = self.pool
You could fix it by changing self to pool and not doing self.pool

sly ember
#
Unhandled exception in internal background task 'checkGames'.
Traceback (most recent call last):
  File "C:\Users\lenov\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\tasks\__init__.py", line 169, in _loop
    await self.coro(*args, **kwargs)
  File "c:\Users\lenov\Desktop\cogs\cogs\gewinnt.py", line 98, in checkGames
    games = await Connect4.getAll(self.pool)
AttributeError: 'Connect4Game' object has no attribute 'pool'

sage tendon
#

pool = pool
bruh

fresh sierra
#

will be better

sage tendon
#

If they used an actual IDE it would've showed that as well

sly ember
#

i use vscode

sage tendon
#

yea, not an IDE

#

just fancy notepad with plugins

fresh sierra
sage tendon
#

in my eyes

sage tendon
fresh sierra
#

to then in the command

sage tendon
#

yea

fresh sierra
#

be able to use pool

sly ember
#

huh

fresh sierra
#

so why self.pool = pool is useless ?

sage tendon
#

that's not what I said

lapis dock
fresh sierra
#

something that do anything is useless

sage tendon
#

self.pool = pool does something
pool = pool doesn't

#

that's what I said

deft kestrel
#

how i can send a message with the bot
but the message is: using `````` ```

sage tendon
#

escape them with \

vestal folio
#

i have a problem with pycord is the import from slash_command not ```from discort import slash_command````??

sage tendon
#

discord.slash_command

#

so, from discord import slash_command

#

yes

vestal folio
#
Traceback (most recent call last):
  File "/home/container/main.py", line 9, in <module>
    from discord import slash_command
ImportError: cannot import name 'slash_command' from 'discord' (/home/container/.local/lib/python3.10/site-packages/discord/__init__.py)```
sage tendon
#

pycord version?

vestal folio
#

newest

sage tendon
vestal folio
#

i have in the requirements.txt py-cord

vestal folio
little cobalt
sage tendon
#

saying newest is cool but doesnt have to be correct :>

vestal folio
#

i have the problem one

#

now is that

Traceback (most recent call last):
  File "/home/container/.local/lib/python3.12/site-packages/discord/ext/commands/bot.py", line 935, in _load_from_module_spec
    spec.loader.exec_module(lib)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/home/container/cogs/moderation.py", line 9, in <module>
    from discord.commands import slash_commands, Option
  File "/home/container/.local/lib/python3.12/site-packages/discord/commands/__init__.py", line 26, in <module>
    from .context import *
  File "/home/container/.local/lib/python3.12/site-packages/discord/commands/context.py", line 69, in <module>
    class ApplicationContext(discord.abc.Messageable):
  File "/home/container/.local/lib/python3.12/site-packages/discord/commands/context.py", line 271, in ApplicationContext
    @discord.utils.copy_doc(Interaction.respond)
                            ^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'Interaction' has no attribute 'respond'. Did you mean: 'response'?
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/home/container/main.py", line 46, in <module>
    bot.run(token)
  File "/home/container/.local/lib/python3.12/site-packages/ezcord/bot.py", line 888, in run
    super().run(token, **kwargs)
  File "/home/container/.local/lib/python3.12/site-packages/discord/client.py", line 860, in run
    asyncio.run(runner())
  File "/usr/local/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/container/.local/lib/python3.12/site-packages/discord/client.py", line 849, in runner
    await self.start(token, reconnect=reconnect)
  File "/home/container/.local/lib/python3.12/site-packages/ezcord/bot.py", line 914, in start
    await super().start(token, **kwargs)
  File "/home/container/.local/lib/python3.12/site-packages/discord/client.py", line 777, in start
    await self.login(token)
  File "/home/container/.local/lib/python3.12/site-packages/discord/client.py", line 621, in login
    await self.setup_hook()
  File "/home/container/.local/lib/python3.12/site-packages/ezcord/bot.py", line 833, in setup_hook
    await self.load_extension(cog)
  File "/home/container/.local/lib/python3.12/site-packages/discord/ext/commands/bot.py", line 1013, in load_extension
    await self._load_from_module_spec(spec, name)
  File "/home/container/.local/lib/python3.12/site-packages/discord/ext/commands/bot.py", line 938, in _load_from_module_spec
    raise errors.ExtensionFailed(key, e) from e
discord.ext.commands.errors.ExtensionFailed: Extension 'cogs.moderation' raised an error: AttributeError: type object 'Interaction' has no attribute 'respond'```
sage tendon
#

what is your python setup lmfao

vestal folio
vestal folio
#

that ist a bug

sage tendon
#

that is most likely why

#

no, its not a bug, its the reason why it doesnt work (most likely)

vestal folio
#

from pterodaxctyl

#

wait

sage tendon
vestal folio
#

i have vby server create python 3.12 selectet

sage tendon
vestal folio
#

ok the directory .local is the problem i have that deleted

vestal folio
# sage tendon <:shrug:900978835816849409>
File "/home/container/cogs/moderation.py", line 9, in <module>
    from discord.commands import slash_commands, Option
ImportError: cannot import name 'slash_commands' from 'discord.commands' (/home/container/.local/lib/python3.12/site-packages/discord/commands/__init__.py). Did you mean: 'slash_command'?
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/home/container/main.py", line 45, in <module>
    bot.load_cogs(subdirectories=True)
  File "/home/container/.local/lib/python3.12/site-packages/ezcord/bot.py", line 318, in load_cogs
    self.load_extension(cog)
  File "/home/container/.local/lib/python3.12/site-packages/discord/cog.py", line 912, in load_extension
    self._load_from_module_spec(spec, name)
  File "/home/container/.local/lib/python3.12/site-packages/discord/cog.py", line 781, in _load_from_module_spec
    raise errors.ExtensionFailed(key, e) from e
discord.errors.ExtensionFailed: Extension 'cogs.moderation' raised an error: ImportError: cannot import name 'slash_commands' from 'discord.commands' (/home/container/.local/lib/python3.12/site-packages/discord/commands/__init__.py)```
#

requirements

ezcord
py-cord

little cobalt
#

I wonder how you got the stuff installed and how you run it

lofty parcel
#

Remove ezcord

little cobalt
#

ezcord should be fine

lofty parcel
#

Don't use some shitty extension

sage tendon
#

dude

#

you typed slash_commands @vestal folio

little cobalt
#

lul

sage tendon
#

it quite literally tells you and even suggests the right thing

vestal folio
#

ups

#

i hav see that

sage tendon
#

thats why the order is this

  1. read error ENTIRELY
  2. send error here
#

and not just step 2 :3

sly ember
sage tendon
little cobalt
sage tendon
#

thats why i make em

sly ember
#

or people cant read

sage tendon
#

you were already told to remove the staticmethod decorator from that function

#

why do you not do that

sly ember
sage tendon
little cobalt
sly ember
sage tendon
#

i mean, dont laugh, fix it

sly ember
#

i cant 😢

sage tendon
#

it tells you exactly what's wrong

#

your self is Connect4Game
it does not have an acquire function

deft kestrel
#

i have a problem i made a file that his name is functions
and i added to the file this:

# Defining sub-groups
setup_group = discord.SlashCommandGroup(name = "setup", description="Setup")
messages_group = discord.SlashCommandGroup(name = "message", description = "Log messages")
roles_group = discord.SlashCommandGroup(name = "role", description = "Log roles")
members_group = discord.SlashCommandGroup(name = "member", description = "Log member")
channels_group = discord.SlashCommandGroup(name = "channel", description = "Log channels")

and when i import it to other files its showing me the options to add those kind of groups but when i restart my discord to see them i dont see them

sage tendon
#

define them in a cog

deft kestrel
#

but then i cant import them

sage tendon
#

do you need them across multiple cogs?

deft kestrel
#

yes

sage tendon
#

ah

#

there was a solution but i dont remember it

deft kestrel
#

Please ping me as soon as you remember it

sage tendon
#

i dont think i will remember it

lofty parcel
#

Lmfao

sage tendon
#

oh

#

is your functions file a cog?

#

wait

#

no nvm i dont think that was it

sage tendon
#

but i dont think that works

deft kestrel
#

no it does not have any cog its just defs

sly ember
#

Still trying to fix that cryLaptop

Unhandled exception in internal background task 'checkGames'.
Traceback (most recent call last):
  File "C:\Users\lenov\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\tasks\__init__.py", line 169, in _loop
    await self.coro(*args, **kwargs)
  File "c:\Users\lenov\Desktop\cogs\cogs\gewinnt.py", line 98, in checkGames
    games = await Connect4.getAll(self)
  File "c:\Users\lenov\Desktop\cogs\cogs\gewinnt.py", line 220, in getAll
    async with self.acquire() as conn:
AttributeError: 'Connect4Game' object has no attribute 'acquire'
lofty parcel
#

Do you realise it gotta be self.pool

#

Not just self

sly ember
#
Unhandled exception in internal background task 'checkGames'.
Traceback (most recent call last):
  File "C:\Users\lenov\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\tasks\__init__.py", line 169, in _loop
    await self.coro(*args, **kwargs)
  File "c:\Users\lenov\Desktop\cogs\cogs\gewinnt.py", line 98, in checkGames
    games = await Connect4.getAll(self.pool)
  File "c:\Users\lenov\Desktop\cogs\cogs\gewinnt.py", line 224, in getAll
    for (guild_id, message_id, players, waiting) in cursor:
TypeError: 'Cursor' object is not iterable
lofty parcel
#

It ain't iterable

#

Read

#

You probably want what cursor.execute returns

#

Read your own code.

#

That's all I know of SQL

sage tendon
#

please read your errors, seriously @sly ember

#

you keep posting your tracebacks here

#

if you cant read them you cant develop a bot properly

#

besides, the mysql library has nothing to do with pycord so thats out of scope for here anyway

tribal crown
#

Figured out my issue. Had some names spelt wrong

deft kestrel
deft kestrel
#

discord.User could be an array? there's something like that? to select more users

sage tendon
#

no

#

also you should use discord.Member

deft kestrel
sage tendon
#

you can solve it by making multiple optional options

deft kestrel
sage tendon
#

make multiple member options and use required=False

deft kestrel
#

oh ok

carmine minnow
#

how can i create a slash command where one of the parameters has custom options? similar to how you can set the parameter to a channel object and it pops up with channels, i want to be able to make you select from a custom set of options?

#

like this

rugged lodgeBOT
tidal vessel
steep cliff
#

I already provided the answer…

errant oyster
#

I am getting the following whenever I try to use slash commands:

  File "/home/user/Documents/discord-bot/hello.py", line 16, in <module>
    bot.run(os.getenv('TOKEN')) # run the bot with the token
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Documents/discord-bot/.venv/lib/python3.12/site-packages/discord/client.py", line 766, in run
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/user/Documents/discord-bot/.venv/lib/python3.12/site-packages/discord/client.py", line 745, in runner
    await self.start(*args, **kwargs)
  File "/home/user/Documents/discord-bot/.venv/lib/python3.12/site-packages/discord/client.py", line 709, in start
    await self.connect(reconnect=reconnect)
  File "/home/user/Documents/discord-bot/.venv/lib/python3.12/site-packages/discord/client.py", line 601, in connect
    await self.ws.poll_event()
  File "/home/user/Documents/discord-bot/.venv/lib/python3.12/site-packages/discord/gateway.py", line 605, in poll_event
    await self.received_message(msg.data)
  File "/home/user/Documents/discord-bot/.venv/lib/python3.12/site-packages/discord/gateway.py", line 555, in received_message
    func(data)
  File "/home/user/Documents/discord-bot/.venv/lib/python3.12/site-packages/discord/state.py", line 818, in parse_interaction_create
    interaction = Interaction(data=data, state=self)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Documents/discord-bot/.venv/lib/python3.12/site-packages/discord/interactions.py", line 171, in __init__
    self._from_data(data)
  File "/home/user/Documents/discord-bot/.venv/lib/python3.12/site-packages/discord/interactions.py", line 201, in _from_data
    self._guild = Guild(data=self._guild_data, state=self)
                  ^^^^^
NameError: name 'Guild' is not defined. Did you mean: 'guild'?```
#

Here is the code I am using:

import os # default module
from dotenv import load_dotenv

load_dotenv() # load all the variables from the env file
bot = discord.Bot()

@bot.event
async def on_ready():
    print(f"{bot.user} is ready and online!")

@bot.slash_command(name="hello", description="Say hello to the bot")
async def hello(ctx: discord.ApplicationContext):
    await ctx.respond("Hey!")

bot.run(os.getenv('TOKEN')) # run the bot with the token```
sage tendon
#

which pycord version

little cobalt
#

just show the pip list pls

errant oyster
#

Package Version


aiohttp 3.9.5
aiosignal 1.3.1
attrs 23.2.0
Brotli 1.1.0
certifi 2024.2.2
cffi 1.16.0
charset-normalizer 3.3.2
frozenlist 1.4.1
idna 3.7
multidict 6.0.5
mutagen 1.47.0
pip 24.0
py-cord 2.5.0
pycparser 2.22
pycryptodomex 3.20.0
PyNaCl 1.5.0
python-dotenv 1.0.1
requests 2.31.0
urllib3 2.2.1
websockets 12.0
yarl 1.9.4
yt-dlp 2024.4.9

#

Python 3.12.3

little cobalt
#

do you use a venv?

errant oyster
#

Yes

sage tendon
#

I remember seeing this error before but i think it was with bridge, so I'm not sure why this would cause it

errant oyster
#

$ ls -l `which python` lrwxrwxrwx 1 user user 15 Apr 28 00:14 /home/user/Documents/discord-bot/.venv/bin/python -> /usr/bin/python

#
Python 3.12.3```
sage tendon
#

can you print discord.__version__ in your code

errant oyster
#
2.5.0```
sage tendon
#

did you have discord.py installed before by any chance

errant oyster
#

Nope.

Lemme try a fresh venv

sage tendon
#

yea i was gonna say try reinstaling pycord, because i dont understand why your code would cause that error at all

errant oyster
#

Same thing with fresh venv and only pycord + python-dotenv installed

Package       Version
------------- -------
aiohttp       3.9.5
aiosignal     1.3.1
attrs         23.2.0
frozenlist    1.4.1
idna          3.7
multidict     6.0.5
pip           24.0
py-cord       2.5.0
python-dotenv 1.0.1
yarl          1.9.4```
#

I guess I'll try a different interpreter and new venv

#

Same thing with python 3.9.19 from nix :/

sage tendon
#

do you have guild.py in venv > lib > site-packages > discord?

#

If yes then i really dont know, sorry
Maybe the others do, because i have seen this error here before

errant oyster
#

Same thing in docker with no venv :/

#

Do you have an example of a working docker container?

errant oyster
sage tendon
#

yea then I legit don't know

lapis dock
sage tendon
#

but what even causes that?

lapis dock
#

I think it is just a typo in the code

sage tendon
#

No but, why does it work for like 99% of the rest of the user but not for them

#

their code is like as simple as it gets

lapis dock
#

The PR says invalid data sometimes not sure what that means tho

deft kestrel
#
class ConfirmView(discord.ui.View):
    def __init__(self, dealid):
        super().__init__()
        self.dealid = dealid
        self.value = None

    @discord.ui.button(label="Yes", style=discord.ButtonStyle.success)
    async def yes_button(self, button: discord.ui.Button, interaction: discord.Interaction):
        self.value = True
        print("Yes button clicked")

    @discord.ui.button(label="No", style=discord.ButtonStyle.danger)
    async def no_button(self, button: discord.ui.Button, interaction: discord.Interaction):
        self.value = False
        print("No button clicked")

    async def interaction_check(self, interaction: discord.Interaction) -> bool:
        data = getConfig(self.dealid)
        if interaction.user.id == data['reciev']:
            return True
        else:
            await interaction.response.send_message("Only the recipient can interact with this button.", ephemeral=True)
            return False

In a different event:

print("Creating confirmation view...")
confirm_view = ConfirmView(dealid)
confirm_message = await message.channel.send(f"Are you sure `{addy}` is the correct LTC address?", view=confirm_view)
print("Confirmation message sent")
confirmation = await confirm_view.wait()
print(f"Confirmation received: {confirmation}")

After clicking either button, the print statements are shown but I get a "This interaction failed" message and there's no error in console.
Also, the confirmation arrives like 3-4 minutes late and I can't find any reason as to why is that
Hope anyone might have an idea

sage tendon
#

wdym it arrives minutes late

#

also, are you suing prefix commands?

deft kestrel
deft kestrel
#

in other words, the execution is paused at confirmation = await confirm_view.wait() for a while before it's continued

sage tendon
#

yea because it waits for the view to time out lol

lapis dock
#

calling View.stop will make the view stop waiting.
So it will stay on await confirm_view.wait() until the view times out or stop is called

frail ocean
#

Is there a way to go through all the audit log entries and if a user did this then it continues? And can you get the channel name from channel delete?

sage tendon
#

what are you trying to do

edgy nest
frail ocean
#

Thx

frail ocean
sage tendon
open hearth
#

is it possible to put multiple images to embed set_image??

sage tendon
#

no

open hearth
#

damn

#

thanks

edgy nest
open hearth
edgy nest
#

if you send multiple embeds with the same URL they'll merge and the images will be added to a single embed

open hearth
#

damn thanks

edgy nest
#

yeah it's a little weird but it exists

edgy nest
sage tendon
#

oh yea, right

#

but does that mean the entire embed has to be equal if you want to have text etc?

edgy nest
#

no

#

just the url

#

but the first embed has to have all the content

open hearth
edgy nest
#

which I think is 10

open hearth
#

yes

#

10

carmine minnow
deft kestrel
#

help:

Exception has occurred: AttributeError
'Bot' object has no attribute 'remove_command'
  File "Desktop\bot\testing\bot.py", line 20, in <module>
    bot.remove_command("help")
AttributeError: 'Bot' object has no attribute 'remove_command'
sage tendon
#

i mean, read the last line

deft kestrel
#

yh but i need to remove it its showing me this:

Ignoring exception in on_connect
Traceback (most recent call last):
  File "c:\Users\Assaf Cohen\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 400, in _run_event
    await coro(*args, **kwargs)
  File "c:\Users\Assaf Cohen\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\bot.py", line 1178, in on_connect
    await self.sync_commands()
  File "c:\Users\Assaf Cohen\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\bot.py", line 735, in sync_commands
    registered_commands = await self.register_commands(
  File "c:\Users\Assaf Cohen\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\bot.py", line 599, in register_commands
    registered = await register("bulk", data, _log=False)
  File "c:\Users\Assaf Cohen\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\http.py", line 373, in request
    raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In 31: Application command names must be unique
fresh sierra
deft kestrel
#

i dont have help command at all

sage tendon
#

its built into pycord

fresh sierra
deft kestrel
sage tendon
#

show your commands

fresh sierra
#

in ur bot instance

#

even if normally /help doesnt exist at all by default

#

does /help appear on the list of command

sage tendon
#

you dont even know if the issue is the help command

deft kestrel
sage tendon
fresh sierra
#

because you are trying to remove the help comamnd

#

check all the name of ur command

sage tendon
#

luma

fresh sierra
#

to be sure that no one are duplicated

deft kestrel
fresh sierra
#

cos they will not appear there since it failed to register them

deft kestrel
#

i did


print(bot.all_commands)
#

{None: <discord.commands.SlashCommand name=feedback-costumer>}

#

output

sage tendon
#

One of your commands has the same name as another one
check what you changed since your bot last worked

fresh sierra
#

you cant really do that

#

try to check in ur code if there is not 2 times the same func

deft kestrel
#

i think maybe i did this:

#   ---===GiveAway-commands===---
    giveaway_group = discord.SlashCommandGroup(name = "giveaway")

and i have this:

    @subcommand(f"setup")
    @commands.slash_command(name = "giveaway", description=" the giveaway system")
    async def setup_giveaway(self, ctx, role: discord.Role):
sage tendon
#

yea

#

thats why

fresh sierra
pliant tusk
#

why is my bot sending messages in a channel but the channel isn't showing as unread

fresh sierra
sage tendon
deft kestrel
fresh sierra
deft kestrel
#

i have

fresh sierra
#

and then a subgroup giveaway

pliant tusk
deft kestrel
#
    setup_group = discord.SlashCommandGroup(name = "setup", description="Setup")
pliant tusk
#

on mobile it shows up fine

fresh sierra
#

and then you will do
@subcommand(f"setup giveawaty")
@commands.slash_command(name = "start", description=" start the giveaway system")

sage tendon
pliant tusk
#

is there any way to like force discord to reset its cache or smth

sage tendon
#

restarting discord shrug

pliant tusk
#

done that multiple times

#

it happens on web asw

deft kestrel
#

i dont think you got what i wanted to do
i have a group command that his name is setup, I use it to all my setup all my systems
and i want one that his name is giveaway and its like a category in the commands that i could do it for the all giveaway commands i add

fresh sierra
#

like that gary:

    setup_group = discord.SlashCommandGroup(name="setup", guild_only=True)
    giveaway_setup_group = xp_group.create_subgroup(name="giveaway")
little cobalt
#

a group name and command name which has the same name should not create an issue

fresh sierra
#

it will do a duplicate name error

lapis dock
#

you just cant have
/hello
/hello add

This is ok tho
/hello add
/test add

fresh sierra
#

which is not possible

little cobalt
fresh sierra
fresh sierra
#

good thing that u think

deft kestrel
#

thanks

#

ok i fixed it

fresh sierra
#

perfect

deft kestrel
#

how do i have my /echo command not ping the role or anything

sage tendon
#

.rftm allowedmentions

#

welp, could've worked

deft kestrel
#

?

sage tendon
deft kestrel
#

can you give me an example though

#

would i just add roles=False

sage tendon
#

yea im looking for where i used it in my code, 1s

#

here, thats how i used it

#

but if you want no mentions at all you can use discord.AllowedMentions.none()

deft kestrel
#

so where could i add it here?

sage tendon
#

after the content in your send

deft kestrel
#

like this?

sage tendon
#

no

#

.send(message, discord.AllowedMentions.none())

deft kestrel
#

Alright thanks so so much

#

this didnt work @sage tendon

#

await ctx.send(message, discord.AllowedMentions.none())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Messageable.send() takes from 1 to 2 positional arguments but 3 were given

sage tendon
#

oh I forgot allowed_mentions= before it

#

like in my example

deft kestrel
#

ok lemme try that

#

omg thanks so somuch

sage tendon
#

np

idle sluice
#

Can I set an embed footer to be a Discord timestamp?

lapis dock
shadow bear
#

Does bot.check_once apply for slash commands too? it does!

frail ocean
signal trench
#

how do i take eh choices from slash cmd and use it in the func parm
like i want to take the choice and use it as tag

signal trench
#

like when i use slash commands it msut show the items in options

#

and when user selects one it must be used in tag

#

if not tag then i want to use it in the function

#
 @commands.slash_command(
        name="waifu",
        description="Get A Random Waifu Image",
        choices=["waifu", "maid", "oppai", "uniform", "selfies"],
    )
    async def waifu(self, ctx, tag = "waifu" ):
        await ctx.defer()

        try:
            image_url = await swaifu(tag)

            if image_url:
                embed = discord.Embed(
                    title="OniChan Here I Am <3",
                    color=discord.Color.blurple(),
                )
                embed.set_image(url=image_url)

                await ctx.respond(embed=embed)

            else:
                await ctx.respond("No Waifu Image Found For This Tag")

        except Exception as e:
            await ctx.respond(f"An Error Occurred : {e}")
#

here is the usage of tag

rugged lodgeBOT
#

Here's the slash options example.

signal trench
#

thanks

sage tendon
signal trench
#

and it's working thanks

sage tendon
#

np

deft kestrel
#

a bot can change his pfp in a single server?

little cobalt
#

only for all servers

signal trench
#

like using ctx.guild.owner returns the username only when i am the owner of the server

#

rest of the cases it says none

#

any idea why or how to fix

#

?

sage tendon
#

yea you need to fetch the owner

#

it's weird, idk why it is like that

signal trench
sage tendon
#

uhhh 1s I did that somewhere

#

owner = await discord.utils.get_or_fetch(guild, 'member', guild.owner_id)

#

guild being ctx.guild

signal trench
#

ahh thanks again sir

sage tendon
#

idk why its like that

signal trench
#

consider fixing ?

#

possible to get nickname ?

sage tendon
#

it's just the guild owners member object so you can use it like one

signal trench
#

ohh okkay

signal trench
sage tendon
#

yea that happens when you print a member object

lofty parcel
#

Because that's what __str__ returns

signal trench
#

ok i get ti

deft bronze
#

Why sometime loot task dupe?

#

Like if they have to send a msg or smt

#

They do two times

#

Is there a correct way to end a task to avoid that or something?

fresh sierra
fresh sierra
deft bronze
#

No

deft bronze
#

They work more than one time

#

For example a task to send a image at 3 in the morning for example

#

Something the task will work two times

#

And send two images

fresh sierra
deft bronze
#

Idk what that is

fresh sierra
#

and if you are stoping in when cog unload

deft bronze
#

No, just one .start at on_ready

fresh sierra
#

(if you reload the cog maybe it does it 2 times

fresh sierra
deft bronze
#

So probably that

#

What should i do?

fresh sierra
# deft bronze What should i do?

you can do something like that in your cog :

class Loop(commands.Cog):
    def __init__(self, bot):
        self.bot: commands.Bot = bot
        self.loop.start()
    
    def cog_unload(self):
        self.loop.cancel()  
    
    @tasks.loop(seconds=30)
#

(that's what im doing)

deft bronze
#

seeing classes inside a bot hurts me

fresh sierra
#

you are not using cog ?

deft bronze
#

yeah, default tasks loop

fresh sierra
#

directly on the code

deft bronze
#

i'll check

#

Is this necessary?

fresh sierra
deft bronze
#

I add it bc when i search for tasks that was in the tutorial long time ago

deft bronze
fresh sierra
#

with pleasure

ivory beacon
#

what is this ?

#

footer ?

#

got it

#

timestamp

fresh sierra
#

Too fast

#

Does the timestamp show different value for different user ?

#

Like I’m in France it will differ than something in us ?

#

(In the same embed)

sage tendon
#

yes, timestamps are localised

arctic plover
#

Hi guys, i have a strange error: im using async def ban(ctx: discord.ApplicationContext, member: discord.Option(discord.Member, description='Choose a member', required=True), but when im trying to ban, i get error ('User' object has no attribute 'ban')

#

But im using discord.Member class, not discord.User

sage tendon
#

are you sure you selected a member that is in the server?

#

also just fyi, required=True is the default, you don't explicitly need it

deft kestrel
#

how to publish a message via bot?

#

what is the method name

lofty parcel
deft kestrel
#

oh

sage tendon
#

no i was wrong

#

mb

lofty parcel
#

The method name is quite literally explicit

deft kestrel
sage tendon
fresh sierra
sage tendon
#

i already asked a question that will answer that

fresh sierra
#

im more asking if a discord.Member in a slash command also convert into user

fresh sierra
glossy latch
#

It's possible to make slash command hiden only for specific users?

sage tendon
#

users no, permissions yes (by default, without using server settings in discord)

glossy latch
#

I mean whos have administration in server

#

Or role

sage tendon
#

yes

glossy latch
#

How

sage tendon
#

@discord.default_permissions(administrator=True) below the slash command decorator

glossy latch
#

Okeyy thank you

vestal folio
#

i have mor as one button in my slash command

#

how to add to view?

#
await ctx.respond(embed=embed, view=[view_invite, view_sup])```
#

this is not right

sage tendon
vestal folio
#

i have thin in the slash command

sage tendon
#

which is not right

#

read the guide, follow the guide

vestal folio
#

i found this not

sage tendon
#

?

fresh sierra
rugged lodgeBOT
#

Here's the tic tac toe example.

sage tendon
#

i already sent them the guide

fresh sierra
sage tendon
#

What they need is the correct way to make a view, which is described very clearly in the guide

fresh sierra
fresh sierra
sage tendon
#

sigh

sage tendon
#

thats a terrible way to make a view

fresh sierra
#

depends

#

if for example you use disabled button or link button its easier

#

than creating a class

sage tendon
#

not reusable, no easy way to add callbacks from what I can see, every guide about views in pycord does it the definition way, by using a class

#

but i guess just copying any code in chat works better for them than reading a guide so what gives

fresh sierra
sage tendon
#

No, that's just an object instantiation of the default view class, not defining a custom class to handle things better

fresh sierra
#

as i said it depends on the utilisation, there is no better way, it depends only about what you need

sage tendon
#

i can also make a string by making a list of chars
or i could just make a string

fresh sierra
#

    @commands.command(brief=chef_showdown.short_doc)
    @is_owner_or_has_perm()  
    async def chef_showdown(self, ctx: commands.Context, channel: discord.VoiceChannel = None):
        channel = channel or ctx.author.voice.channel

        invite = await channel.create_activity_invite(
            activity=1037680572660727838,
            reason="Launch activity",
            max_age=0,
            max_uses=0,
        )
        
        embed = discord.Embed(title=chef_showdown.embed.title, description=chef_showdown.embed.description.format(channel=channel))
        embed.add_field(name="Channel vocal", value=channel.mention, inline=False)
        embed.set_image(url="https://cdn.discordapp.com/app-assets/1037680572660727838/1107690679750115338.png?size=300")
        
        button = discord.ui.Button(style=discord.ButtonStyle.link, label=chef_showdown.button.label, url=invite.url)
        
        view = discord.ui.View()
        view.add_item(button)
        
        await ctx.reply(embed=embed, view=view)
sage tendon
#

Why do you think every pycord guide handles views by making a subclass of the view class?

fresh sierra
#

here for example, i find it easier to just use the discord.ui.View than creating another class

fresh sierra
#

for example when the button does nothing, like button link

sage tendon
#

that is a very specific example
and if they just read the guide, they'd know how to properly do guides
this way, they probably just copy pasted your code and will be back here sooner or later because of its shortcomings

fresh sierra
#

i agree that class are better for a lot of reason, callback etc etc

#

but there is some case where it can be useful to also do view = discord.ui.View(), even with a class in addition

grizzled loom
#

when you set discord.Member as an option, a slash-command-user types a member, e.g.
@fresh sierra
then You leave the server and finally after you left the command user hits enter

#

you will receive discord.User instead of discord.Member

deft kestrel
#

does anyone have a open source working pycord bot

grizzled loom
weary meteor
#

how do i create like a task that runs infintely? i just need it to make a check every minute but im not sure how id create a task with pycord

weary meteor
lofty parcel
weary meteor
#

i didnt see how to in the docs unless i completely missed it

#

oh i did miss it

#

😭

weary meteor
# lofty parcel Did you start the task?...
    def __init__(self, bot):
        self.bot = bot
        self.check_slot.start()

    def cog_unload(self):
        self.check_slot.cancel()

@tasks.loop(seconds=5.0)
    async def check_slot(self):
        print("Running task!")```

still nothin
lofty parcel
#

Mind showing a screenshot of your code instead?

weary meteor
#

yes just wacky formatting

#

yea fosho

lofty parcel
#

Is the cog getting loaded?

weary meteor
#

yep

lofty parcel
#

Hm

#

No idea

weary meteor
#

well thats not ideal lmao

fresh sierra
little cobalt
#

Can you show how you load the cog?

atomic fern
#

how to create command group in cogs? there is no guide about it in docs

sage tendon
#

use discord.SlashCommandGroup(...)

#

I'm p sure there is a guide about that though

#

and then you use
@groupname.command() instead of the normal slash command decorator

#

so

testgroup = discord.SlashCommandGroup(args)

@testgroup.command()
async def commandname():
...
atomic fern
sage tendon
#

yea it wasn't a guide but an example, linked above, mb

atomic fern
#

tysm

deft kestrel
#

what is the name of this status? it is not offline because i see it on the online members

fresh sierra
#

how do you see the • admin .

deft kestrel
fresh sierra
#

vencord

#

maybe cos of that that you dont see the status

sage tendon
#

Yea, if you use unofficial client mods, expect them to mod your client

sage tendon
#

in what way do you need to read messages @dawn vault

dawn vault
#

for commands that aren't slash commands

sage tendon
#

ah, well then you do

intents = discord.Intents.default()
intents.message_content = True

bot = discord.Bot(intents=intents)
dawn vault
#

how do I add embeds too?

sage tendon
#

that isnt related to intents

#

thats just something you can do no matter what

dawn vault
#

now I get this error:

    bot.run(token)
  File "D:\Python\Lib\site-packages\discord\client.py", line 716, in run
    return future.result()
           ^^^^^^^^^^^^^^^
  File "D:\Python\Lib\site-packages\discord\client.py", line 695, in runner
    await self.start(*args, **kwargs)
  File "D:\Python\Lib\site-packages\discord\client.py", line 659, in start
    await self.connect(reconnect=reconnect)
  File "D:\Python\Lib\site-packages\discord\client.py", line 598, in connect
    raise PrivilegedIntentsRequired(exc.shard_id) from None
discord.errors.PrivilegedIntentsRequired: Shard ID None is requesting privileged intents that have not been explicitly enabled in the developer portal. It is recommended to go to https://discord.com/developers/applications/ and explicitly enable the privileged intents within your application's page. If this is not possible, then consider disabling the privileged intents instead.```
sage tendon
#

read it

dawn vault
#

But I enabled it

sage tendon
#

read the error :)

#

you enabled it in your code

#

but thats 1 of 2 places you need to enable it

dawn vault
#

?

sage tendon
#

just doing it in your code isn't enough
please read the error and do what it says

dawn vault
#

huh?

sage tendon
#

what is unclear

dawn vault
#

why I am getting the error

sage tendon
#

because you didn't do what it asks of you

dawn vault
#

?

sage tendon
#

The last 3 lines of the error. Read them, and do exactly what it says.

dawn vault
#

But I have it enabled

sage tendon
#

Again, just doing it in your code isn't enough

dawn vault
#

Yes

#

I want to the developer portal and enabled it but it still won't work