#Basic Pycord Help (Quick Questions Only)

1 messages · Page 93 of 1

lost lodge
#

it is the same

#

?

smoky forge
#

?tag localfile

obtuse juncoBOT
#
f = discord.File("some_file_path", filename="image.png")
e = discord.Embed()
e.set_image(url="attachment://image.png")
await messagable.send(file=f, embed=e)```
smoky forge
#

the filename cant be a directory

lost lodge
#

ah works

#

thank you so much

mint sphinx
#

How to solve this err ?

smoky forge
#

shouldn't it be len(winners)?

cyan quail
#

guild.self_role

waxen skiff
#
        async with conn.cursor() as cur:```

do i have to do this everytime i want to execute something with my database
#

(connection pool)

smoky forge
#

try using discord.utils.utcnow()

#

instead of datetime.datetime.now()

#

and don't use bare excepts since it's bad practice

quiet tendon
smoky forge
proud mason
#

whats the difference between msg.edit and msg.edit_original_message here?

rare ice
near swan
#

How Do i know the person that used a slash command?

rare ice
near swan
#

thx

rare ice
#

b!rtfm pyc discord.ApplicationContext

rare ice
#

First one

native gorge
#

Yes it is, and it works with commands.Context.send and commands.Context.reply but no with discord.ApplicationContext.respond

errant craneBOT
#

Here's the slash options example.

silver moat
#

@fervent cradle ^

silver moat
#

really depends on preference, but preferably something async

#

It is async

round rivet
#

probably based on the aio prefix

drowsy python
#

is there a way to manually raise a discord.CommandError for my error handler?

#

i can't figure it out in the docs for the life of me

smoky forge
#

except there's no commanderror exception, the closest would be ApplicationCommandError

copper dew
#

depends. i would maybe say asyncmy but it's up to you

drowsy python
#

i'll give it a try thanks

waxen skiff
#
        command=self.bot.get_command('config mode setmode')
        embed.add_field(
            name='🔁 Modify | <> = Required | [] = Optional',
            value=f"/{command} {command.signature}",
            inline=False
        )```

slash command equivalent?
native gorge
#

How much time does the bot have to send a response to a slash command?
My code has to edit an image and whenever I run some Pillow function it doesn't allow me to send the response

#

Basically what was happening to me here

waxen skiff
#

also what are these errors

In options.8: Option name droprate is already used in these options
In options.10: Option name dropchannels is already used in these options
In options.12: Option name roleshop is already used in these options
In options.15: Option name dropamount is already used in these options```
rare ice
waxen skiff
#

new to slash commands

#

stilll confused

rare ice
native gorge
smoky forge
#

so what you do is defer the response, wait until it's processed and then send a followup response

waxen skiff
#

hmm still stuck on my error

waxen skiff
obtuse juncoBOT
waxen skiff
#

?

rare ice
waxen skiff
#

👍🏻

icy sky
#

What permissions do I need to give a bot in the url generator if I want to enable message_content?

full basin
#

That's an intent, no an auth permission

icy sky
#

I see, so I then I'd set it w/
intents = discord.Intents.default()
intents.message_content = True

bot = discord.Bot(intents = intents)

waxen skiff
dreamy raft
#

Does anyone know why the VSCode "restart application" button is suddenly now changing the file being run to the file of the currently tab instead of rerunning the file that was previously run?
I'm running my bot, going to a cog, pressing restart, it use to just restart my bot, now it's trying to run my cog ThisIsFine

waxen skiff
#

i only have one guild set for slash commands but why is my command not showing up

#
    @commands.command(name="config", breif='See the servers configuration')
    async def config(self, ctx):```
torpid wharf
waxen skiff
#

yeah i found it

#

and i was confused bc a website said you can use commands.command

#

i figured out @safe inlet_command works

#

sorry for ping

torpid wharf
#

Yeh

devout anvil
devout anvil
alpine helm
#

Is it compulsory to shard my bot after 2.5k servers?

fallen cove
#

how do you disable a button from a different class

copper dew
solemn spire
#

so i tried printing the status of a user and i got offline even if the user is online
print(user.status)

topaz ginkgo
#

dose anyone know how to make a button look like it has responded without sending a messages

devout anvil
#

is discord.CustomActivity visible to human users

devout anvil
topaz ginkgo
devout anvil
topaz ginkgo
devout anvil
#

then idk sry

#

they should code @errant crane in discordjs

#

just as a joke

torpid wharf
topaz ginkgo
torpid wharf
woeful spindle
#

how do i get the human count and bot count of a server?

crimson sundial
topaz ginkgo
woeful spindle
#

no

#

that’s total member count

topaz ginkgo
#

that should return the count

woeful spindle
#

nvm

stiff wadi
#

Why can't I get the description of my commands in my help command ?

#

I don't use slash commands btw

#

only normal commands

waxen skiff
#

people are saying you can mention slash commands… how?

silver moat
#

e.g.
</hi:12345678>
</hi:12345678>

waxen skiff
#

how do you get the id?

silver moat
waxen skiff
#

thanks!

fervent cradle
#

since yesterday my bot is restarting a few times a day. did anyone had the same problem?

waxen skiff
#

im getting In 4: Application command names must be unique even though there is no other with the same name

severe storm
#

discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In 15: Application command names must be unique

waxen skiff
#

i figured it out i have a group called mode

but why cant i have a command called "mode"?

#

i want to have

#

/mode
/mode subcommand
/mode another subcommand

severe storm
silver moat
waxen skiff
#

got it

#

i figured out something else that works but look at this

severe storm
waxen skiff
#
command=self.bot.get_application_command('mode setmode')``` and for some reason, command is `None`
#

no idea

waxen skiff
#

still cant figure this dumb thing out

silver moat
waxen skiff
#

i tried just 'setmode'

#

and only top level? then how cna i do this

silver moat
#

what do you need to do again?

waxen skiff
# silver moat what do you need to do again?
                command=self.bot.get_application_command('mode setmode')
                embed.add_field(
                    name=':repeat: Modify | <> = Required | [] = Optional',
                    value=f"/{command} {command.signature}",
                    inline=False
                )```
woeful spindle
#

How do I make my commands non-case sensitive?

silver moat
woeful spindle
#

all my commands?

silver moat
#

I meant text commands or application commands

torpid wharf
woeful spindle
#

yeah

woeful spindle
waxen skiff
#

its

#

case_insensitive=True

#

where you make the bot instance

torpid wharf
#

In the client object

silver moat
#

b!rtfm pyc commands.bot

woeful spindle
#

ok I’ll try now ty

waxen skiff
#

yep

#

now, how can i fix my issue

#

lol

woeful spindle
#

works guys ty

torpid wharf
#

okh

waxen skiff
#

ofc

torpid wharf
silver moat
#

why did you need to get them again?

waxen skiff
#

i need to get the command so i can do this value=f"/{command} {command.signature}",

woeful spindle
#

One more thing, how do I make my commands work with my bot as a prefix aswell? For example, both of these should work:

!help 
@MyBot help
torpid wharf
#

make a list of prefix

torpid wharf
waxen skiff
silver moat
#

well, I just type the url :)

torpid wharf
silver moat
#

and hope i got it correct

torpid wharf
#

Lol it is

waxen skiff
#

i did this

#
            print(command.name)```
#

and i saw"mode" but not "mode setmode"

#

wait

#

i saw "setmode"

#

but its still none... what?

silver moat
#

so what do you get again?

waxen skiff
#

None

#

'NoneType' object has no attribute 'signature'

silver moat
#

huh

#

what is command.signature?

waxen skiff
#

<like> [this]

silver moat
#

yeah. but that's for discord.ext.commands.Command

waxen skiff
#

oh shit

silver moat
#

aren't we talking about discord.ApplicationCommand?

waxen skiff
#

yes, we are. then how can i do this

rare ice
#

When using autocomplete, is it possible to access ctx.guild? I am getting an error of discord.ApplicationContext has no attribute guild.

silver moat
silver moat
#

autocomplete with applicationcontext?

rare ice
#

oh jesus wait

#

thats prob why

waxen skiff
#

why doesnt SlashCommand have qualified_name

rare ice
#

i think i accidently type hinted it wrong

silver moat
waxen skiff
#

oh, ok

#

cool

rare ice
#

oh wait no i meant the error was discord.AutocompleteContext has no attribute guild

silver moat
rare ice
#

there is an interaction?

#

i just have this async def get_custom_reasons(self, ctx):

rare ice
#

ohhhhhhhhhh

#

mb

silver moat
#

when helper doesn't read docs

rare ice
#

i forgot there was .interaction with ctx with discord.AutocompleteContext lol

#

but yeah i should have done that first

woeful spindle
#

how would I get my CPU usage / RAM usage for a command?

#

like directly from my host

silver moat
woeful spindle
#

that seems like a longed winded confusing process

#

is there no alternative way?

waxen skiff
#

i wish it wasnt SlashCommandOptionType.integer and it was just integer

silver moat
cyan quail
#

the same goes for all slash options types, you can use the original type instead of SlashCommandOptionType

waxen skiff
#

how?

#

i do in my params

cyan quail
#

hm?

waxen skiff
#

fuck get application command, this is better

    def get_slash_command(self, name: str):
        command=None
        for cmd in self.bot.walk_application_commands():
            if cmd.name == name:
                command=cmd
        options = f"{'| ' if len(command.options) >= 1 else ''}"
        def refine_type(_type):
            if _type == 'SlashCommandOptionType.integer': return 'int' 
            if _type == 'SlashCommandOptionType.string': return 'string' 
            if _type == 'SlashCommandOptionType.bool': return 'bool' 
            if _type == 'SlashCommandOptionType.float': return 'float' 
            if _type == 'SlashCommandOptionType.channel': return 'channel' 
            if _type == 'SlashCommandOptionType.thread': return 'thread' 
            if _type == 'SlashCommandOptionType.member': return 'member' 
            if _type == 'SlashCommandOptionType.user': return 'user' 
            if _type == 'SlashCommandOptionType.attachment': return 'attachment' 
            if _type == 'SlashCommandOptionType.role': return 'role' 
            if _type == 'SlashCommandOptionType.abc.Mentionable': return 'mentionable user or role' 
        for option in command.options:
            optionName = ''
            if option.required: optionName = f'__{option.name}__'
            else: optionName = str(option.name)
            options += f'{optionName} ({refine_type(str(option.input_type))}) {"" if option == command.options[-1] else "| "} '
        return f"/{command.qualified_name} {options}"```
#

i just made this and it works so well

cyan quail
#

bruh

waxen skiff
#

anyone can use it if they want btw

cyan quail
#

but like

#

why

waxen skiff
#

idk

smoky forge
#

what is this

cyan quail
#

hell just

#

return _type.split(".")[-1]

#

or something idk

fervent cradle
#

how do i make choices like

errant craneBOT
#

Here's the slash options example.

fervent cradle
#

thx

#

hi, my bot does nothing in cogs but works in main file (it says it loads the cogs but doesnt respond to text commands, doesnt register slash commands or events)

#

all of these work in my main file though

rare ice
#

What version are you using?

fervent cradle
#

2.0.0

#
for file in os.listdir("modules/commands"):
    if file.endswith(".py"):
        client.load_extension(f"modules.commands.{file[:-3]}")
        CommandLoaded(file)
        
for file in os.listdir("modules/events"):
    if file.endswith(".py"):
        client.load_extension(f"modules.commands.{file[:-3]}")
        EventLoaded(file)
``` my code for loading cogs if this is needed
rare ice
#

Pretty sure this is a known bug

#

But since you’re using a different way, try loading cogs normally with client.load_extension(…) instead of iterating through the files and see if that works.

fervent cradle
#

ah it works if i do it like that

#

would adding a try except work if i iterate through the files?

fervent cradle
#

alright so now my commands are loading right but my events arent

#
for file in os.listdir("modules/commands"):
    if file.endswith(".py"):
        try:
            client.load_extension(f"modules.commands.{file[:-3]}")
            CommandLoaded(file)
        except Exception as e:
            Error(f"Failed to load command {file}\nError:{e}")
        
for file in os.listdir("modules/events"):
    if file.endswith(".py"):
        try:
            client.load_extension(f"modules.events.{file[:-3]}")
            EventLoaded(file)
        except Exception as e:
            Error(f"Failed to load event {file}\nError:{e}")
#

its literally the same code

#

So now, one cog loads but my other doesntr

dim blade
#

so i'm trying to split up my code a bit and trying to create the OptionChoice Objects in one file and than use it in another file, but this stops my COG from working and loading. anyone experienced something like this and knows a solution to this? maybe the code from the optionchoice isnt getting executed before the commands try to be loaded, i dont really know whats hapening and dont know how to fix it.

#

is it possible to just have the code in the py file and import it to another file or do i need to put it in a class?

fervent cradle
#

I am unable to fetch a guild in a cog:

TypeError: Client.get_guild() missing 1 required positional argument: 'id'

My code:

    guild = commands.Bot.get_guild(guild)
dim blade
fervent cradle
dim blade
#

it requires the ID to be integer, are you sure you saved it as an integer?

fervent cradle
#

yes, i'm passing it directly through

#
await OpenTicket(commands.Bot, interaction.user, interaction.guild_id)
#

i updated my code

#
   guild = self.get_guild(guild)
#

it also doesnt work when i put it in directly

full basin
full basin
#

self.get_guild(guild)

#

What's the guild variable

fervent cradle
#

its a guild id

fervent cradle
#
class ticketButton(discord.ui.View):
        @discord.ui.button(label=" | Open Ticket", style=discord.ButtonStyle.green, emoji="✉️")
        async def tickets(self, button: discord.ui.Button, interaction: discord.Interaction):
            await OpenTicket(commands.Bot, interaction.user, interaction.guild_id)
full basin
#

And your OpenTicket function is?...

fervent cradle
#
async def OpenTicket(self, user, guild):
    text_channel_list = []
    guild = self.get_guild(guild)
    for channel in guild.text_channels:
        if "ticket" in channel.name:
            text_channel_list.append(channel.name)
    tcl = str(text_channel_list)
    if str(interaction.user.id) in tcl:
        return await user.send("You already have a ticket open")
    #open ticket here
#

theres nucg vetter ways of checking if the user already has a ticket but thats what im using right now

full basin
#

self, user, guild

#

And when calling the function

#

You're passing commands.Bot, user, guild id

fervent cradle
#

yes

full basin
#

Not how it works?

fervent cradle
#

oh

full basin
#

self is provided by python itself

#

Unless you're not in a class?

fervent cradle
#

yeah

#

this func is not in the class

full basin
#

I have no idea

#

Why are you using self then

fervent cradle
#

uh i dont actually know

#

i was just using it before

full basin
#

And why are you passing a class? commands.Bot?

#

That'll literally do nothing

#

It'd make sense if you actually passed the bot instance

fervent cradle
#

wait am i actualy that dumb

#

but the issue is im not passing the bot instance through to the ticket shit

full basin
#

Indeed you're not

#

So I assume that's why it fails

fervent cradle
#

i tried to pass through the bot instance but itwont work

#

maybe im just dumb actually

#
class tickets(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    class ticketButton(discord.ui.View):
        @discord.ui.button(label=" | Open Ticket", style=discord.ButtonStyle.green, emoji=":envelope:")
        async def tickets(self, button: discord.ui.Button, interaction: discord.Interaction):
            await OpenTicket(bot, interaction.user, interaction.guild_id)
#

yeah im dumb somewhere

#

maybe i need to get some dinner and come back to it

full basin
#

self.bot

#

Learn python then come back

fervent cradle
#

i learned python 2 years ago

full basin
#

Refresh your python then?

fervent cradle
full basin
#

self**.bot**

#

Of course self is the whole ticket class

#

Google how classes work

fervent cradle
#

nono i mean

bleak goblet
#

how do I get the nickname of the server creator?

#

ctx.guild.owner.nick does not work

torpid wharf
bleak goblet
#

thx

torpid wharf
grizzled scarab
#

Can someine help me in #999907830243012688

#

Its been over an hour

proud mason
alpine helm
#

Items are not cleared even when "Disabled" is getting logged in console

slow halo
#

#general message

so


image = Image.open(io.BytesIO(requests.get(url).content))
image.save(Path + sep + fileN + "." + format)

would still work, even if its a spoiler

pallid trench
#

you need to edit the message with the updated view for the new changes to appear

alpine helm
#

oh

#

one sec