#Basic Pycord Help

1 messages · Page 4 of 1

tight holly
#

ooooh ok thank u

bitter meteor
#

error with view: AttributeError: '_EnumValue_ButtonStyle' object has no attribute 'disabled'

#

code:

#

(there are also more same buttons bellow)

#
P1 = "\N{Regional Indicator Symbol Letter X}"
P2 = "\N{Regional Indicator Symbol Letter O}"
EMPTY ="\N{white large square}"```
also this if you nead
#

lmk if i nead to send more info/code

shell radish
#
        if not player1:
            self.button1 = discord.ButtonStyle.green
            self.button2 = discord.ButtonStyle.green
            self.button3 = discord.ButtonStyle.green
            self.button4 = discord.ButtonStyle.green
            self.button5 = discord.ButtonStyle.green
            self.button6 = discord.ButtonStyle.green
            self.button7 = discord.ButtonStyle.green
            self.button8 = discord.ButtonStyle.green
            self.button9 = discord.ButtonStyle.green

        self.button1.disabled = toggles[0]
        self.button2.disabled = toggles[1]
        self.button3.disabled = toggles[2]
        self.button4.disabled = toggles[3]
        self.button5.disabled = toggles[4]
        self.button6.disabled = toggles[5]
        self.button7.disabled = toggles[6]
        self.button8.disabled = toggles[7]
        self.button9.disabled = toggles[8]
        
        self.button1.emoji = emojify[0]
        self.button2.emoji = emojify[1]
        self.button3.emoji = emojify[2]
        self.button4.emoji = emojify[3]
        self.button5.emoji = emojify[4]
        self.button6.emoji = emojify[5]
        self.button7.emoji = emojify[6]
        self.button8.emoji = emojify[7]
        self.button9.emoji = emojify[8]

button1 is a ButtonStyle not a button

bitter meteor
#

so what do i do?

grim estuary
#

Unfortunately, I could not convert the image normally into bytes so that discord.File can read it later. How can you store an image in RAM without resorting to saving to disk?

torpid ivy
#

any decent guides floating around about how to make embeds prettier? still learning what you can do in them

#

wanna make this embed a lil prettier looking lol

grim estuary
grim estuary
torpid ivy
#

(ignore the spacing issues, that's just me not paying attention in my f strings lol)

royal monolith
#

anyone know you can get the bot object from an interaction object without setting an attribute called "bot" with __setattr__?

torpid ivy
#

actually i really want to use tab-spacing/alignment or something similar in my embed

#

but I dont know if discord uses tabs

royal monolith
#

thats the same as ctx.bot?

lofty parcel
torpid ivy
#

like just lining up all the guesses/points/accuracies/etc from user to user

#

like if I could make a table or something

royal monolith
lofty parcel
#

Tias

grim estuary
#

Also you can use selection which equalizes the size of all characters

torpid ivy
#

yeah, can do monospaced but thats also a lil ugly

#

I just want something prettier than
flappity: Guess: 75 Points Earned: 1 | Accuracy: 5.0%
New Score Total: 10 (56.0% accuracy)

#

but i dont know if I have a lot of options

fickle salmon
grim estuary
#

You can use images?

#

It's a good way out

torpid ivy
#

in theory but then I'd have to generate images on the fly too lol

#

but like, that's also not a bad idea

#

i'm sure python could do that pretty easily. maybe latex? :D

grim estuary
#

Teach me how to upload images edited by the Pillow library 😉

lofty parcel
torpid ivy
#

generating scorecard images sounds kinda goofy but it would also mean i could get it as pretty as i wanted lol

grim estuary
grim estuary
torpid ivy
#

well this is round-end stuff, so at the end of a game round it calculates the scores, updates the score database, and then spits out the round-end scorecard

#

so they'd never change

grim estuary
#

On the Internet, people either convert to bytes if they do not want to save, or save the image

lofty parcel
#

Have you even tried to Google all your questions

#

You can pretty much find an answer online

fickle salmon
#

Or /var/run

grim estuary
#

Yes

fickle salmon
#

Then use that

torpid ivy
#

so with groups, does the /command just inherit the group name?
like if I made a group named "dat" and then created commands as part of that group like "start", would the command then be /dat start

#

actually, nm. i just tried and it does

#

i'm not used to things being intuitive >_>

little cobalt
#

like /dat start name

rugged lodgeBOT
#

Here's the slash cog groups example.

torpid ivy
#

hmm, so with these bottom three fields, is there any way to get them to take up the full 3 columns for each field?

#

where they'd be displayed above each other instead of side by side like that

#

I'm running into a problem where my embed field value was exceeding a length of 1024 so I gotta figure out some alternative

upper hearth
torpid ivy
#

oo

pseudo osprey
ancient rose
#

Hello. Quick question. Interaction doesn’t have an attribute to add_reaction. So what should I use

shell radish
#

what do you want add a reaction to?

ancient rose
#

An embed

#

But is an interaction

#

Not ctx

shell radish
#

Is the message with the embed sent as a response/followup?

ancient rose
#

Response

shell radish
#

you can get that message with await interaction.original_response()

ancient rose
#

Oh damn

#

Thanks

shell radish
#

and let's say you store it to a variable called response, you would use await response.add_reaction(...)

ancient rose
#

Yeah

#

But I’m not gonna store it

#

So it would just be interaction.original_response.add_reaction

shell radish
#

sorry, I don't think that's how coros work

ancient rose
#

#

Then why did u tell me that

shell radish
#

you would await for the original_response

ancient rose
#

Oh

#

Wait what

#

But u just told me

shell radish
#

what?

ancient rose
#

Interaction has no attribute to original_response

#

:/

shell radish
#

what version are you on

#

in older versions, it could also be interaction.original_message()

torpid ivy
#

hmm. so I know there's available ways to find a username based off a userid, but I'm having trouble figuring out how I might do that in secondary libraries that aren't part of my main bot file or my commands file. would I just have to pass the bot object to the function directly so it can use bot.get_user() maybe?

#

I"m so not used to structuring stuff like this lol

torpid ivy
#

that sounded more complicated at first but i guess that is pretty simple

#

usually dont have to use the bot object for stuff, mostly just pass ctx around from function to function lol

shell radish
#

ctx has bot tho

#

ctx.bot

lofty parcel
#

And interaction has interaction.client

torpid ivy
#

oh heck it does?

#

well that's easier too then

ancient rose
#

@bot.tree.command(name="appraise")
async def appraise(interaction: discord.Interaction, *, item_name: str, set_price: str):
  item_name = item_name.title()
  response = await interaction.original_response()
  down_arrow="⏬"
  left_right_arrow="↔️"
  up_arrow="⏫"
  embed = discord.Embed(title=f"{interaction.user}'s Appraisal: {item_name}", description="Please React with the Following Reactions to help appraise this Item!")
  
  await interaction.response.send_message(embed=embed)
  await response.add_reaction(down_arrow, left_right_arrow, up_arrow)
#

My error is: 404 unknown webhook

#

For await interaction.original_response()

ancient rose
#

Yeah I did

#

Oh I define response after?

lofty parcel
#

You're doing original_response and then send_message

shell radish
#
@bot.tree.command(name="appraise")
async def appraise(interaction: discord.Interaction, *, item_name: str, set_price: str):
  item_name = item_name.title()
- response = await interaction.original_response()
  down_arrow="⏬"
  left_right_arrow="↔️"
  up_arrow="⏫"
  embed = discord.Embed(title=f"{interaction.user}'s Appraisal: {item_name}", description="Please React with the Following Reactions to help appraise this Item!")
  
  await interaction.response.send_message(embed=embed)
+ response = await interaction.original_response()
  await response.add_reaction(down_arrow, left_right_arrow, up_arrow)
ancient rose
#

Yeah

shell radish
#

add

#

and remove

torpid ivy
#

well, i THOUGHT it'd be easy

ancient rose
#

Oh

torpid ivy
#

ctx.bot.get_user just gives me None when passed an ID. maybe one of these other methods work lol

shell radish
torpid ivy
#

oo will try

lofty parcel
#

For future reference, get_user returns None if the user isn't in the bot cache

shell radish
lofty parcel
#

Isn't that what I said

shell radish
#

no?

#

you're assuming that the ID corresponds to a user

lofty parcel
#

Well

torpid ivy
#

ahh ok, get_or_fetch user worked, though now i have to figure out how to get from there to whatever nickname they're using on the server

lofty parcel
#

same thing SQUID

shell radish
shell radish
shell radish
torpid ivy
#

cuz i'm still looking through the docs and trying to figure out what i'm doing D:

#

i dont think ive looked at member objects at all even lol

rich sigil
#

What the fuck is await (file=image)

torpid ivy
#

aha, fetch_member is probably where i need to be looking

#

or rather guild.fetch_member()

rich sigil
#

yep guild

torpid ivy
#

urgh. one of my things is timing out somewhere along the line

#

well, maybe. it's almost like it's losing the interaction when doing ctx.respond()?

#

never mind, it's just my internet crapping out lol

little cobalt
grim estuary
void moat
#

sorry of stiped question but i can use localization text from crowdin?

bitter meteor
hybrid tinsel
#

how do i get the list of all roles in a server for the autocomplete thing? just getting the list of all role ids is also fine (i would just need the logic for turning role ids into their role names LOL)

torpid ivy
#

so that error should happen much less

#

i need to add some error handling for it though

#

which probably just means wrapping my respond command in some if statement and then failing gracefully if the error pops up

#

right now if it fails it leaves a flag set lol

#

or alternatively it sounds like if you get a response in right away you dont have to worry about the timer. so maybe I could add a .respond() at the start of the command to make the 3 second thing a non-issue?

void moat
#

how i can make Localizations?

daring valve
void moat
daring valve
void moat
# daring valve yup

its possible import localize from file? like Eng_GB
%join_welcome_pm% = Hello pls read rules etc

?

daring valve
void moat
daring valve
#

.tias

sly karmaBOT
sweet gale
#

anyone here familiar with using wavelink with py-cord?

hybrid tinsel
#

is there a way to get the id of the person typing out a slash command?

#

like some way to do the thing in the image

#

that actually works

daring grove
#
    positions = (
    ("gk", 95, 325), 
    ("rb", 235, 380), 
    ("lb", 235, 255), 
    ("cm", 385, 318), 
    ("rf", 455, 520), 
    ("lf", 463, 110), 
    ("cf", 525, 318)
    )
        if position in positions:
            data[teamroster][position].append(player.display_name)
            for position1 in positions:
                with open("rosters.json", "r") as json_file:
                    data = json.load(json_file)
                text, width = function(position1[0], team, font, data)
                Im.text((position1[1]-(width/2), position1[2]), text, (0,0,0), font=font)
                image.save(f"picture{team}.png")

why is this not saving the file?

hybrid tinsel
deft kestrel
#

How would I get commands from a diffrent file. example
bot.py in main directory
commands folder
--> test.py
test.py contents

@bot.slash_command(description="Add a suggestion")
async def hello(ctx):
    await ctx.respond(f'Hello {ctx.author.display_name}.')

how would I do this?

deft kestrel
hybrid tinsel
#

thats at least how i went about it

torpid ivy
#

Yeah cogs are nice and easy

deft kestrel
# hybrid tinsel thats at least how i went about it

Is there anyway that I dont have to add this to each file

import discord
from discord.ext import commands

class Greetings(commands.Cog): # create a class for our cog that inherits from commands.Cog
    # this class is used to create a cog, which is a module that can be added to the bot

    def __init__(self, bot): # this is a special method that is called when the cog is loaded
        self.bot = bot

    @commands.command() # creates a prefixed command
    async def hello(self, ctx): # all methods now must have both self and ctx parameters
        await ctx.send('Hello!')

    @discord.slash_command() # we can also add application commands
    async def goodbye(self, ctx):
        await ctx.respond('Goodbye!')

    @discord.user_command()
    async def greet(self, ctx, member: discord.Member):
        await ctx.respond(f'{ctx.author.mention} says hello to {member.mention}!')

    @commands.Cog.listener() # we can add event listeners to our cog
    async def on_member_join(self, member): # this is called when a member joins the server
    # you must enable the proper intents
    # to access this event.
    # See the Popular-Topics/Intents page for more info
        await member.send('Welcome to the server!')

def setup(bot): # this is called by Pycord to setup the cog
    bot.add_cog(Greetings(bot)) # add the cog to the bot

just

@bot.slash_command(description="Add a suggestion")
async def hello(ctx):
    await ctx.respond(f'Hello {ctx.author.display_name}.')
#

I was thinking about using temp files

#

but idk

little cobalt
hybrid tinsel
#

you dont really need to copy everything, its just there for reference purpose

deft kestrel
#

its way simpler if you have it without setup etc..

hybrid tinsel
# deft kestrel Is there anyway that I dont have to add this to each file ```python import disco...

you can just do this
cogs/greetings.py

import discord
from discord.ext import commands

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

  Greetings = SlashCommandGroup(name="Stuff", description="Stuffs")

@Greetings.command(description="Add a suggestion")
async def hello(ctx):
    await ctx.respond(f'Hello {ctx.author.display_name}.')

main.py

imports

bot = blah blah blah

bot.load_extension(cogs.greetings)

bot.run(token)
#

havent tested though

deft kestrel
#

I think it would work

fiery stratus
#

How do I add a view using discord.Bot.add_view() when the View I have requires parameters that are only given when running a slash command (i want to make it persistent)?

#

I have this command that lets an admin make a Select view to allow for users to select a role in the list

#

however in creating the Select view i pass in the options (the roles that the user can select) that are given from the slash command

#

so when i want to make it persistent by adding it to the bot I don't have that data anymore

#

do i need to serialize the options list or is there a better way to go about it?

little cobalt
# fiery stratus

you could create a select class and add it to a view class for it

fickle salmon
fiery stratus
fiery stratus
#

and if None is passed just do nothing?

fickle salmon
#

yep

fiery stratus
#

alr ill try that

fiery stratus
#

Also can multiple persistent views use the same id?

upper hearth
#

is there a way i can get around discord on mobile only allowing photo uploads in slash command attachment optoins

lofty parcel
#

Do internal checks.

stray pasture
#

it says in the docs that discord id are 18 digits long, what UNSIGNED INT() length would I need in a database ?

shell radish
#

because they aren't

stray pasture
#

I think it was a other type, I just saw they are snowflake yes

#

so it would be UNSIGNED INT(64) ?

shell radish
#

I would suggest uisng strings

stray pasture
#

why use strings ? I would take more memory for no benefits

fiery stratus
#

Hey for some reason roleInteraction.message is None. Does anyone know why that is?

#

something to do with the cache?

shell radish
fiery stratus
#

that makes sense. how can i get the message ID of the response? roleInteraction.id?

shell radish
fiery stratus
#

thanks! you're a big help

shell radish
#

yw

bitter meteor
modern prairie
#

What are these commands called?

heavy sky
#

Message commands

fleet cedar
#

To be precise, Context menu commands

quick grail
#

how can i turn of mention author on reply edit

#

initial reply doesn't have mention author, the edit does though, putting ", mention_author = False" after it doesn't work

quick grail
#

Why not

shell radish
quick grail
#

That's sad

dusky axle
#

gravitational pull of the sun

bitter meteor
#

i have code: (bellow) and i get an error :
AttributeError: '_EnumValue_ButtonStyle' object has no attribute 'disabled'

#

what do i change?

dusky axle
#

gravitational pull of the sun

lofty parcel
bitter meteor
#

no?

lofty parcel
#

Yes you were lmao

#

#1132206148309749830 message

bitter meteor
#

oh sorry

bitter meteor
lofty parcel
#

Use the correct variables

#

You're not disabling a button

bitter meteor
#

but how do i disable it then in the code?

little cobalt
bitter meteor
#

only the selected

lofty parcel
#

Get the proper buttons

#

With self.children

#

Or with their callbacks

#

Idk how you're creating them

bitter meteor
#

so self.children[0] and then disabled?

lofty parcel
#

Tias

deft kestrel
bitter meteor
#

sure

upper hearth
#

in a button callback, does interaction.message.id not give the id of the button that the message is in?

#

its giving some different id

#

actually

msg = await ctx.respond("abc")
print(msg.id)``` this is giving the wrong id
upper hearth
#

oh how do i get the msg id then

little cobalt
#

msg = await interaction.original_response()
If Im not wrong

upper hearth
#

huh

#

in the command?

#

but interaction isnt defined

little cobalt
#

sry, ctx.interaction.original_response()

upper hearth
#

ah ty

sweet gale
#

anyone here familiar with using wavelink with py-cord?

tawny ether
#

how do i subscribe for only specific intents

lapis dock
#
import discord

bot = discord.Bot(intents=discord.intents.members(bans=True, guilds=True))
tawny ether
#

what if i need messages.Content + Embeds + Attachments

lapis dock
#

Embeds and attachments are not an intent

#

You might be mixing up permissions with intents.

tawny ether
#

yea 🤦

fleet cedar
#

You can use a one-time listener for on_ready (one-time listeners are only available on master branch rn)

Or you can inject the setup in bot.start by subclassing

fleet cedar
#

Oh hmm

rapid jackal
#

when I have a message with an attachment and I want to edit this message and remove the attachment, how can I do this?

fleet cedar
fast glade
#

can my global on_command_error listener catch an error from within a with statement? The error seems to just be getting ignored atm

#

(Using a bridge command if that's relevant)

little cobalt
fast glade
#

Haven't used regular prefix commands before

#

ah this was a problem with my context manager object's __exit__ not the command

little cobalt
#

You have to Check with if else

#

Or send the message as hidden

#

But it would get auto deleted after some time

fast glade
#

My bot's code is organized into many extension files with cogs; is it possible for me to create a command group in one cog and add subcommands to that command in another file's cog?

#

I tried simply importing the command group from the other cog's class and it works very confusingly - it's as if it recognizes that the command has been created (I loop through cmdGroup.walk_commands() to show the user a list of available subcommands) but i can't actually run the subcommand

fast glade
#

does that apply to my use case?

#

since there's only one cog in that file and it doesn't import any of the other modules

upper hearth
#

if i have a slash command that runs itself/another slash command, how can i use await ctx.defer() without it saying the interaction has already been responded to

little cobalt
upper hearth
#

i meant the function of a slash command

#
@bot.slash_command(name="test")
async def test(ctx, abc:str=None):
  if test == None:
    await test(ctx, "abc")``` like that or something
lofty parcel
upper hearth
#

tbh i could just

@bot.slash_command(name="test")
async def test(ctx, abc:str=None):
  if test == None:
    abc = "abc"``` instead
#

but if i want the closest thing to a command alias then i'd need to run it

halcyon zinc
#

guys how they did this?

fast glade
deft kestrel
#
@commands.command()
@commands.has_permissions(administrator=True)
async def kickall(self, ctx):
    guild = self.bot.get_guild(1053331335005098044) 
    members = guild.members
    channel = guild.get_channel(1053331335005098047)
    KickedMembers = []
    for member in members:
        if not member.bot and member != guild.owner:  
            try:
                CurrentTime = datetime.datetime.utcnow() - member.joined_at
                if len(member.roles) == 1 and CurrentTime.days > 1:
                    await member.send(" ")
                    await member.kick(reason="Did not verify in 3 day duration, or was denied.")
                    KickedMembers.append(member.name)
            except discord.Forbidden:
                pass

    print("Running kickall command...")  # Print statement for debugging

    if KickedMembers:
        await channel.send(embed=KickedMember)
    else:
        await channel.send(embed=NoKickedMember)```
The else statment does not run at all, this only started after i added the check for current time etc to the if statment, I think this may be a indentation error but could use a little help
lofty parcel
#

You cannot send an empty message

deft kestrel
lofty parcel
#

So no errors?

deft kestrel
#

No errors at all no

lofty parcel
#

And what does it send

deft kestrel
#

Nothing

#

I run the command, it does not kick or respond (It shouldnt kick as it does not meet the criteria)

#

But it should respond with

NoKickedMember = discord.Embed(title="No un-verified members found", description="No members were found unverified or denied to the server so i have not kicked anyone.", color=0x10BDF6)
#

Want the full file?

lofty parcel
#

But it does work when you kick members?

#

It sends the success message I mean

deft kestrel
#

Yeah it did before i added the and CurrentTime.days > 1: part, to check if they've been in the server over a day

#

but now nothing happens at all (As said, the not kicking is okay)

#

I have a task for this too, plus the command i've shown, The task code isnt yet updated & still works fine

#

but isnt updated with the and CurrentTime.days > 1: check

deft kestrel
#

Sorry if i went into detail a bit

lofty parcel
#

So it just doesn't work at all

#

Not just the else statement

deft kestrel
# lofty parcel So it just doesn't work at all

Thats correct,

 @tasks.loop(hours=168)  
    async def kickall_task(self):
        guild = self.bot.get_guild(1053331335005098044) 
        members = guild.members
        channel = guild.get_channel(1053331335005098047)
        KickedMembers = []
        for member in members:
            if not member.bot and member != guild.owner:  
                try:
                    if len(member.roles) == 1:
                        await member.send("")
                        await member.kick(reason="Did not verify in 3 day duration, or was denied.")
                        KickedMembers.append(member.name)
                except discord.Forbidden:
                    pass
        if KickedMembers:
            await channel.send(embed=KickedMember)
        else:
            await channel.send(embed=NoKickedMember)```
#

That is my task code

#

It has no extra check, and works fine

#

I've tried coparing them but cannot find an issue

#

(Is slighly outdated to what i've used to fix it, but didnt work)

lofty parcel
#

Print CurrentTime.days

#

And remove the try/except to let it error

deft kestrel
#

alr

#
@commands.has_permissions(administrator=True)
async def kickall(self, ctx):
    guild = self.bot.get_guild(1053331335005098044) 
    members = guild.members
    channel = guild.get_channel(1053331335005098047)
    KickedMembers = []
    for member in members:
        if not member.bot and member != guild.owner:
            CurrentTime = datetime.datetime.utcnow() - member.joined_at
            print(CurrentTime.days)
            if len(member.roles) == 1 and CurrentTime.days > 1:
                await member.send("")
                await member.kick(reason="Did not verify in 3 day duration, or was denied.")
                KickedMembers.append(member.name)
        else:
            await ctx.send("test")``` My updated code, still no response & didnt print
lofty parcel
#

And print kickedmembers

#

And also, you don't capitalise variables names

deft kestrel
#

Ill go fix my variable names once i fix this then ty

deft kestrel
#

Put it below the append

#

@lofty parcel

lofty parcel
#

Doesn't print anything?

deft kestrel
#

Yeah

lofty parcel
#

Then your code is stopping somewhere else

#

Debug it with prints

deft kestrel
#
@commands.command()
@commands.has_permissions(administrator=True)
async def kickall(self, ctx):
    print("e")

    guild = self.bot.get_guild(1053331335005098044) 
    members = guild.members
    channel = guild.get_channel(1053331335005098047)
    KickedMembers = []
    print("e")
    for member in members:
        print("e")
        if not member.bot and member != guild.owner:
            CurrentTime = datetime.datetime.utcnow() - member.joined_at
            print(CurrentTime.days)
            if len(member.roles) == 1 and CurrentTime.days > 1:
                await member.send("")
                await member.kick(reason="Did not verify in 3 day duration, or was denied.")
                KickedMembers.append(member.name)
                print(KickedMembers)
        else:
            await ctx.send("test")``` Quite a few prints, nothing printed though.
deft kestrel
#

None

#

I am suprised not even the top one

lofty parcel
#

Then your command isn't registered?

#

I uh, don't really know

#

Is it a cog?

#

Are you loading the cog?

deft kestrel
#

Yeah it loads, it worked earlier

#

Got a response

#

I removed the permission check for admin?

lofty parcel
#

That's

#

Lol

#

Well

deft kestrel
#

yeah but im the owner

#

its my test discord

lofty parcel
#

I mean, the check should throw the error

#

After all

#

In console or sending a msg if you're catching it

deft kestrel
#

Yeah should for sure send in console, plus i have a check for it

 @commands.Cog.listener()
    async def on_command_error(self, ctx, error):
        if isinstance(error, commands.MissingPermissions):
            await ctx.send(embed=NoPermissions)```
lofty parcel
#

That's weird

#

.rtfm commands.has_permission

sly karmaBOT
timber rampart
red mist
#

I recommend checking indeed, if it's a debug guild command or public command

#

Public commands take some time to update

#

It's weird as fuck

next dagger
#

Does anyone know why my slash commands arent working?

lofty parcel
#

no

#

we cant telepathically ask your computer why its not working

next dagger
#

well sorry

#

im just using an example from the documentation,

@bot.slash_command(description="Sends the bot's latency.") # this decorator makes a slash command
async def ping(ctx): # a slash command will be created with the name "ping"
    await ctx.respond(f"Pong! Latency is {bot.latency}")

it's just not showing up for some reason? ive had the bot running for like a day now and still

lofty parcel
#

show the full file

next dagger
#
import discord
from dotenv import load_dotenv
import os

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

client = discord.Client(intents=intents)
bot = discord.Bot()

@bot.slash_command(description="Sends the bot's latency.") # this decorator makes a slash command
async def ping(ctx): # a slash command will be created with the name "ping"
    await ctx.respond(f"Pong! Latency is {bot.latency}")
    
# run is in run.py
lofty parcel
#

remove that

next dagger
#

thx

rose roost
#

how to make some commands shown in this list only to certain roles?

little cobalt
rose roost
#

what are permissions

deft kestrel
#

How to add slash commands in Discord BOT with Python?

#

I want to add /custom commands.

little cobalt
little cobalt
lofty parcel
#

lmao, saw you typin but then it just went away

rose roost
deft kestrel
little cobalt
lofty parcel
#

.rtfm default_permissions

sly karmaBOT
lofty parcel
#

The docs explain it

little cobalt
lofty parcel
deft kestrel
deft kestrel
deft kestrel
#

I hosted it with my public ip in my private server

little cobalt
#

@lofty parcel Do you know any VS Code extension showing something like this?

little cobalt
deft kestrel
lofty parcel
#

I don't see 😭

little cobalt
lofty parcel
#

I hate pycharm

little cobalt
limber wagonBOT
#
  1. Uninstall discord.py or any other forks of discord.py you might have with the namespace discord.
    python -m pip uninstall discord.py discord -y

2a. Install py-cord
python -m pip install py-cord

2b. Update py-cord
python pip install -U py-cord

Installing other builds:
Note: You need to have git installed. Use ?tag git to find out how to install git.

Updating the module to master branch (unstable):
pip install -U git+https://github.com/Pycord-Development/pycord

shell radish
little cobalt
#

I use now VS Code for C# because it got so many crazy updates for it

lofty parcel
#

Tried to migrate my bot code to pycharm and it started yelling at me. Not happening again. I only use it for uni

shell radish
deft kestrel
#

GIT is installed.

lofty parcel
deft kestrel
#

Now, discord Bot error has been resolved but this coming.

lofty parcel
#

Are you sure you're on the latest version of the library?

deft kestrel
lofty parcel
#

Show pip list

#

@deft kestrel

deft kestrel
little cobalt
#

lol

#

uninstall that one or update it

lofty parcel
deft kestrel
lofty parcel
#

Update the library

deft kestrel
lofty parcel
#

python3

#

Or just pip

deft kestrel
#

just pip and python

#

Done.

little cobalt
#

||sudo pip install||

deft kestrel
#

I executed pip install -U py-cord. And worked.

#

Thanks, but Window sucks.

little cobalt
#

?

deft kestrel
blissful dew
#

how can i go about pinging a certain user in pycord

lofty parcel
#

.rtfm Member.mention

lofty parcel
#

.rtfm get_member

sly karmaBOT
deft kestrel
#
async def bot_calc(Crazy, first: discord.Option(int), second: discord.Option(int)):```

How to add description to parameters of command in discord.py?
rugged lodgeBOT
#

Here's the slash options example.

deft kestrel
#

Thanks @shell radish .

shell radish
#

yw

deft kestrel
deft kestrel
#

how to use stable diffusion with discord bot? @shell radish Please if you know reply.

shell radish
deft kestrel
shell radish
#
- Don't just ask for code. You need to understand the language if you are coding instead of blindly copying someone's code. When asking for help, do not insist on getting just the code; we are here to help you learn, not copy.
deft kestrel
#

No code, but to understand.

late slate
#

Is there a way to detect when the bot gets temporarily disconnected from Discord (because of something on Discord's end I guess) and, like, print something to the console when it does?

shell radish
#

.rtfm on_disc

sly karmaBOT
late slate
#

tyvm

#

Yeh sry, I really need to explore all the discord. functions. Haven't played with them much.

hybrid tinsel
#

why's this happening?

#

its just
role_id: int

#

do i have to specify long?

shell radish
#

yeah, you should use a string instead

hybrid tinsel
#

i really needed the integer value and using a string feels very

#

janky

shell radish
#

I assumed there was something that wouldn't work with discord.Role

hybrid tinsel
#

yeah im just dumb LOL

#

i forgot discord.Role existed when i was doing it initially

shell radish
#

Like I assumed that solution already crossed your mind.

arctic plover
#

I want to check if the user has admin permissions.

Here's my try:

def check_is_admin(user, guild):
    roles = guild.roles
    adm_roles = []
    for role in roles:
        if role.permissions.administrator:
            adm_roles.append(role)
    flag = False
    for role in adm_roles:
        if user.has_role(role):
            flag = True
            break
    return flag

But here's error "User object doesn't have has_role attribute".
I also tried to make it via user.roles, but it falls with error "User object doesn't have roles attribute"

timber rampart
#

you can just use user.guild_permissions.administrator

austere moth
#

is it possible to enter multiple roles in SlashCommand option, either with discord.Option or discord.SlashCommandType?
I know it's possible using discord.Converter but I'd rather prefer using Slash Command

timber rampart
#

I don't think you can have a list of roles within one command option, you could of course do something like option1, option2, option3 ...

austere moth
#

ah yeah, thanks for the answer

sly karmaBOT
fleet cedar
#

thats much easier to use

#

also, how are you using the function?

void moat
#

i trying make multi lang like
msg/responses save ing lang.json and import msg like welcome_info it will send of preferred language of discord, how i can real to implement language checking?

void moat
#

hey?

dusk flume
#

how can i pass the context of the autocomplete to a function:

async def banned_member_autocomplete(self, guild):
        banned_users = [entry async for entry in guild.bans(limit=1000000)]

        return [f"{entry.user.name} ({entry.user.id})" for entry in banned_users]

    @commands.slash_command(name="banned_users_example")
    @option("user", description="Pick a banned user from this list", autocomplete=banned_member_autocomplete)
    async def autocomplete_banned_users_example(self, ctx, user: str):
        # Your logic to unban the selected user goes here
        # Replace the following line with the code to unban the user
        # Example: await ctx.guild.unban(user)

        await ctx.respond(f"You have successfully unbanned the user: {user}!")

I want the autocomplete thing to be a list of banned users. I keep getting: AttributeError: 'AutocompleteContext' object has no attribute 'bans'

atomic fern
#

how to create a timestamp like this? 5 minutes ago? the time is changed without editing the message

deft kestrel
#

So is it possible to set a custom status?

daring valve
halcyon zinc
lofty parcel
halcyon zinc
#

hey guys I want to ask something how can I add my avatar to a photo via pillow?

grim estuary
#

Hello. How can I create a function in a bot that will periodically fire when the time expires?

timber rampart
#

.rtfm tasks

sly karmaBOT
grim estuary
#

Thank you

fleet cedar
#

.rtfm autocompletecontext

modern prairie
#

How do we make a command that can only be used by server owner... Without the Members Intent

modern prairie
#

Isn't that for bot owner?

little cobalt
#

yea I was reading bot owner xd

modern prairie
#

I don't want any Member Object data just want to limit the usage to the owner only

little cobalt
#

You could use @commands.has_permissions(administrator=True)

#

There is not really a thing for the server owner

modern prairie
#

I don't want admins to use the command

little cobalt
#

or you do a if else

modern prairie
little cobalt
#
if ctx.author.id == ctx.guild.owner_id:
...
else
"Error"
modern prairie
#

That requires Members Intent ig

#

I don't have that

#

I applied but got rejected twice

little cobalt
#

you dont need intents for a slash command

modern prairie
#

cz no intent

little cobalt
#

try owner_id

modern prairie
#

One sec

little cobalt
#

but you only get the id

modern prairie
#

Only id works

#

Wait one sec

grim estuary
#

How can I find out the number of members in voices?

modern prairie
#

owner_id works and it doesn't require intent

#

Thanks

red mist
# deft kestrel

Tipp for the future : consider putting your token in an .env file :P

little cobalt
shell radish
#

yml ftw

red mist
#

.txt pls

deft kestrel
tawny ether
#

is there any difference between discord.Bot and discord.exts.commands.Bot?
i didnt found any

limber wagonBOT
#

dynoError No tag clients found.

little cobalt
#

?tag client

limber wagonBOT
#
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)
arctic plover
fickle salmon
#

yes you can

#

you just give it a url

#

.rtfm button.url

grim estuary
#

Hello. How can I change the guild banner?

#

I can't find this method anywhere

fickle salmon
#

take out the style

#

oh nvm

#

that should work

#

is that your whole class?

#

uh that's not how you write a view class

rugged lodgeBOT
#

Here's the link example.

fickle salmon
#

@deft kestrel try this example ^

#

no, that's not right at all

#

you need to add the button to the view

grim estuary
#

Excuse me. How can I change the guild banner?

sly karmaBOT
red mist
#

.rtfm button

lofty parcel
#

No

grim estuary
#

I solved the problem, I'm sorry

red mist
#

oh overread "link" buttons

#

link buttons have a default color iirc.

#

can't change indeed

cobalt bone
#

Where can we report bugs on the py-cord library ?

little cobalt
cobalt bone
#

The on_reaction_add event (if that's what it's called I'm not sure) is failing and not firing on some added reactions

little cobalt
#

Do you have reaction intents?

cobalt bone
#

Yes

#

It works from time to time but on some messages it does not react

little cobalt
#

is the same happening if you use on_raw_reaction_add?

cobalt bone
timber rampart
#

on_reaction_add only works on cached messages

cobalt bone
little cobalt
#

oh yea, its like get_channel

#

if the message is not found in the internal message cache, then this event will not be called

#

that is why I use only on_raw_reaction_add

cobalt bone
#

It's very likely that it comes from there 👀 I'll try then and I'll let you know

unborn spear
#

Is there a way to use the regular client.wait_for() after a buttom is pressed?

upper hearth
#

on_presence_update is still saying idle instead of offline and discord are saying its not their fault

cerulean lake
#

There a way to use the default permissions decortator with slash command groups? I want the behavior that the default_permisions gives of hiding commands from people who don't have the proper perms but on an indivual command basis with my slash command group.

lofty parcel
#

Add the decorator to each command?

cerulean lake
#

Tried that, doesn't work for some reason, works fine with normal slash commands

shell radish
cerulean lake
#

I guess I can just switch to non grouped commands, it's only bot config commands anyways

shell radish
#

maybe consider using a UI-based approach?

cerulean lake
lofty parcel
#

Wdym choosing channels?

shell radish
sweet gale
#

how can I add a description here?

fleet cedar
deep blaze
#

how do i get the current shard the bot is serving in ?

halcyon zinc
#

.rtfm Option

sweet gale
#

can we set custom status of bots using py-cord?

halcyon zinc
#

.rtfm activity

lusty mountain
#

.rtfm presence

sour atlas
#

Is there a way to detect when a Persons starts speaking in a Voice channel? (I want it to then start recording)
And if yes is there a way to detect silence time base example 0.5 sec so that i can use that to stop the recording?

upper hearth
#

on_presence_update is still saying idle instead of offline and discord are saying its not their fault

fickle salmon
#

I had a similar problem a while ago, when checking is_on_mobile

upper hearth
#

fetching user always gives offline

fickle salmon
#

huh, I do a get, not a fetch apparently 🤷

upper hearth
#

wait i forgot what i did

fickle salmon
#

sorry, fetch_member

upper hearth
#

i did fetch_member and it said offline always

#
@bot.event
async def on_presence_update(before, after):
     print(f"{after.display_name} - {after.activity} - {after.status}") # idle instead of offline
     member = await after.guild.fetch_member(after.id)
     print(member.status) # always offline```
#

idk how i could be doing something to break it

fickle salmon
#

yeah, I get offline when I fetch too

shell radish
#

The API doesn't return privileged information regardless of intents iirc

fickle salmon
#

but get_member works correctly, shows dnd, idle, online, and offline

upper hearth
#

okay ill try

#

maybe discord fixed something

#

i just restarted bot and it works fine

#

with normal after.status

upper hearth
#

wait how do i set a button label to a variable if i can't use self.variable because its not in the function

lofty parcel
#

Wdym it's not in the function

upper hearth
#
class buttons(discord.ui.View):
    def __init__(self, variable):
        super().__init__()
        self.variable = variable
    @discord.ui.button(label=self.variable, style=discord.ButtonStyle.grey)
    async def callback(self, button, interaction):
      dshfujisdjhiuo```
#

like i cant do that

shell radish
#

?

upper hearth
#

what

#

ok pretend that was right

shell radish
#

just subclass button

lofty parcel
#

Or self.callback.label = self.variable

torpid ivy
#

i feel like i saw somewhere that you can use duration in an ephemeral=True ctx.respond() and it'll only last that long? I was trying to find it again but i could not

#

like ctx.respond("asdfb", ephemeral=True, duration=15)

little cobalt
torpid ivy
#

oh is it delete_after

shell radish
lofty parcel
#

I take it back

torpid ivy
#

now I need to figure out buttons

little cobalt
#

and you use interaction instead of ctx

torpid ivy
#

ahh gotcha

#

i have a /dat scale command and I sorta wanna just add a button to the embed that triggers the same function

sweet gale
#

does pycord support that new feature where you can add a custom status of bot?

sweet gale
shell radish
#

?tag install

limber wagonBOT
#
  1. Uninstall discord.py or any other forks of discord.py you might have with the namespace discord.
    python -m pip uninstall discord.py discord -y

2a. Install py-cord
python -m pip install py-cord

2b. Update py-cord
python pip install -U py-cord

Installing other builds:
Note: You need to have git installed. Use ?tag git to find out how to install git.

Updating the module to master branch (unstable):
pip install -U git+https://github.com/Pycord-Development/pycord

sweet gale
#

no, I mean is it available on pypi yet?

shell radish
#

no

sweet gale
#

ohhk

#

I would better wait for it coz uk the master branch is unstable and I don't want to break anything in my bot

#

:)

lofty parcel
#

It's very stable lol

fleet cedar
#

But yea it's pretty stable... until I commit

#

🤣

slender cloak
#

How would I get the message id of the message that my views are on?

shell radish
slender cloak
#

ok thank you

slender cloak
shell radish
slender cloak
#

Im getting an error, AttributeError: 'buttons' object has no attribute 'view'

#

sorry im relatively new to pycords views

shell radish
#

do you have a super().__init__()?

slender cloak
#

yes

#

super().init(timeout=None)

shell radish
#

could you show your code?

slender cloak
#

yes

#
class buttons(discord.ui.View):

    def __init__(self, client, ctx):
        self.client = client
        self.ctx = ctx
        super().__init__(timeout=None)

    @discord.ui.button(label='Ban', style=discord.ButtonStyle.danger)
    async def ban_button_callback(self, button, interaction):
        msg_id = self.view.message.id
#

basically that

#

im just trying to get the message id of the message the buttons are on

slender cloak
shell radish
sweet gale
#

how can I disable dm commands for my bot? 👀

#

like it doesn't listen to msg cmds and no slash cmds appear there too

shell radish
shell radish
sweet gale
#

how do u add that - and + thing? with color highlight 👀

sweet gale
slender cloak
shell radish
# sweet gale in discord?

```diff
class buttons(discord.ui.View):

def __init__(self, client, ctx):
    self.client = client
    self.ctx = ctx
    super().__init__(timeout=None)

@discord.ui.button(label='Ban', style=discord.ButtonStyle.danger)
async def ban_button_callback(self, button, interaction):
  •   msg_id = self.view.message.id
    
  •   msg_id = self.message.id
    

```

#

yes

slender cloak
#

ok thx

torpid vine
#

am I guaranteed to have all channel IDs for a guild? I dont want to make an api call to fetch_channel just to check id.

meager fulcrum
heavy sky
#

Are you using bridge commands, application commands or prefixed commands?

lapis dock
sweet gale
#

can I add a description to a choice of discord.Option's choices list?

heavy sky
torpid ivy
#

curious if there's any other real time game bots like mine (where you start a round, accept submissions, and then process em), i'm sorta curious to see how other people handled things, figure out if I'm doing things weird af or if they're normal

halcyon zinc
#

Hello, how would creating a separate cog for each command affect performance and is it reasonable?

lofty parcel
#

You should create cogs for commands categories

lofty parcel
#

Group commands with the same purpose in the same cog

torpid ivy
#

like in my case I have my guessing game in one cog, will have another game in a different cog, will have another cog that will look up data (unrelated to the game)

torpid ivy
#

at least that's how I'm using cogs

#

structuring my bot with the main .py file to run the bot in the base folder, and then subfolders for each cog that will contain all the files that that specific cog uses

halcyon zinc
#

thanks

frail ocean
#

How can i defer the button?

little cobalt
#

?

frail ocean
#

channel = bot.get_channel(id)
await channel.send

frail ocean
little cobalt
grim estuary
#

Hello. Is it possible to change the value of options?

class Name(discord.ui.View):
    def __init__(self, name_list):
    super().__init__(timeout=None)
    self.options = name_list

    @discord.ui.Select(
        placeholder="title",
        min_values=1,
        max_values=1,
        options=self.options # doesn't see it
    )
async def select_callback(self, select, interaction):
        ...
halcyon zinc
#

I never used I don't know

grim estuary
#

I will try it, thank you

fierce elk
#

Hi, I'm trying to check whether a member has a role by using member.get_role(id) with the id of the role. This always returns None even though I know the user has that role. What gives?

#

My code looks like this. First I fetch the role id and it is found. Then I try to find all members with that role, but nothing is printed.

#

user.roles is also an empty list

shell radish
fierce elk
#

I have that enabled in the developer page for the bot, but guild.members returns an empty list

#

I was also wondering about that

shell radish
#

Do you have it enabled in code?

#

?tag intents

limber wagonBOT
#

https://docs.pycord.dev/en/master/intents.html
https://discord.com/developers/docs/topics/gateway#gateway-intents

import discord
from discord.ext import commands

# Get specific intents for fine control
intents = discord.Intents()
intents.emojis = True
intents.guilds = True
intents.messages = True  # Required for prefix commands!
...
# Get all non-priveliged intents; this excludes presences, members and message_content 
intents = discord.Intents.default()

# Set priveliged intents: these must be enabled on dev portal
intents.members = True
intents.presences = True
intents.message_content = True  # Required for prefix commands >= 2.0.0b5

# Get all intents; all intents must be enabled on dev portal.
intents = discord.Intents.all()

# Apply intents when creating your bot
bot = commands.bot(prefix="?", intents=intents)
Discord Developer Portal

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

fierce elk
shell radish
#

I doubt you’re using discord.Client. Do you have a bot instance?

fierce elk
#

I do not. I am actually using this client created here.

#

Is that wrong?

#

what is the difference between a client and a bot?

shell radish
#

you’re telling me that you don’t have any commands?

fierce elk
#

Not slash commands at least. This is an old bot

#

It does cleanup of the server by deleting old messages

shell radish
#

No text-based commands either?

fierce elk
#

It does have some text commands that are prefixed by !

#

But I have implemented those myself. I'm not using any API for them

shell radish
#

💀 ok

fierce elk
#

I'm parsing messages in a designated bot commands channel and if they start with "!" I do things

#

But you're saying I should change from a client to a bot?

fierce elk
#

client.fetch_guilds

shell radish
#

yeah that’s why

fierce elk
#

that's why what?

shell radish
#

try using client.guilds

fierce elk
#

oh

shell radish
fierce elk
#

Ahhh ok I see

#

thanks!

torpid ivy
#

my brain is not comprehending how to do buttons lol

frail ocean
halcyon zinc
lofty parcel
frail ocean
halcyon zinc
#

hey guys
Option(min_value=50, max_value=99999, required=True, input_type=discord.SlashCommandOptionType.integer)
what did i do wrong here?

#

oh okay I fixed

muted vapor
fiery stratus
#

Is there some way that I can unload all my extensions when the bot crashes?

#

Like i have a list of cogs, some of which have data that needs to be dumped on exit

#

is there a built in way to do this in pycord or does python have something for this?

torpid ivy
#

?tag localfile

limber wagonBOT
#
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)```
torpid ivy
#

hmm. I can't do await ctx.respond(embed=e) I'm guessing? or maybe ctx.respond has a file option too

#

OH you can

hybrid fossil
#

Hi, I'm a selector but I don't understand, I have this error, any ideas?
TypeError: function() argument 'code' must be code, not str

torpid ivy
#

HA it worked. i'm stoked

#

matplotlib in embeds lol

torpid ivy
#

whats the "proper" way to handle server/channel permissions? Right now I just have a hardcoded dictionary
server_permissions['serverid'] = ['channel1', 'channel2'], etc and it just checks if the source of the command is in that dict lol

#

doesn't seem like the cleanest way

fickle salmon
#

wdym "handle"

fleet cedar
torpid ivy
#

bot tracks all their guesses and calculates the average after each round, plots it

#

kinda neat :D

#

so I have a question

i have a command /dat graph

This displays aforementioned graph. Is there a way I can make an optional parameter /dat graph [user] so they can look up other users, or simply use it without the parameter to get their own?

#

I tried adding it to the command but it wasn't optional

#

I"m sure there's probably a rtfm for this already

little cobalt
torpid ivy
#

will try it. i wanna see what the autocomplete behavior is

shell radish
hybrid fossil
#
class SRewards(discord.ui.select):
    def __init__(self):
        super().__init__(
            placeholder="List",
            select_type=discord.ComponentType.string_select,
            min_values=1,
            max_values=1,
            custom_id="rewardSelector",
            options=[

                discord.SelectOption(
                    label="1 | 3 votes",
                    description="-",
                    emoji="🔘",
                    value="-"
                )
            ]
        )

    async def callback(self, interaction):
        select_description = self.description[0]

        await interaction.response.send_message(f"{select_description}")
shell radish
#

and what is the full traceback?

hybrid fossil
#

The problem appears when I create my class

class SRewards(discord.ui.select):```
shell radish
hybrid fossil
torpid ivy
#

thats always fun

#

i had an error where i had something divided by i + 1 and could not figure out why it kept throwing divide by zero errors

#

i was sitting too far from my laptop, because it was actually i + i

little cobalt
#

lul

red mist
#

LOL

upper hearth
#

bc i thought it was an i

inland trout
#

heya, since the username change, I've needed to change how I display usernames in command responses (through slash commands) - ctx.author.display_name is returning my normal Discord username (lowercase: angry_pineapple) when my actual display name has uppercase letters - is there a workaround for this?

little cobalt
inland trout
#

I didn't even think to check that lol

little cobalt
#

?tag install

limber wagonBOT
#

1. Uninstall discord.py or any other forks of discord.py you might have with the namespace discord.
python -m pip uninstall discord.py discord -y

2a. Install py-cord
python -m pip install py-cord

2b. Update py-cord
python pip install -U py-cord

Installing other builds:
Note: You need to have git installed. Use ?tag git to find out how to install git.

Updating the module to master branch (unstable):
pip install -U git+https://github.com/Pycord-Development/pycord

little cobalt
#

the last line ^

inland trout
#

aha, that fixed it -- thank you!

#

here, take a cookie 🍪

edgy nest
inland trout
edgy nest
#

:(

crimson turtle
#

Hi, what could this be related to?
I am sending a model with 2 textinput: (modal.to_dict())

{
'title': 'Translation', 
'custom_id': 'b8feae83fedc6c68513030239f321a7c', 
'components': [
  {'type': 1, 'components': [{'type': 4, 'style': 1, 'label': 'Enter the transfer amount (RUP)', 'custom_id': 'e851de9759cc77c8d2eda54abd93dd42', 'placeholder': '8264.76', 'min_length': 1, 'max_length': 7}]}, 
  {'type': 1, 'components': [{'type': 4, 'style': 2, 'label': 'Comment', 'custom_id': 'a6cf017d28b9e2d3af16074f6198aa6e', 'placeholder': 'Input may be empty', 'max_length': 128, 'required': False}]}
]
}

I get the error:

discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In type: Value must be one of {4, 5, 6, 7, 10}.
fleet cedar
#

Can you show your modal class

crimson turtle
# fleet cedar Can you show your modal class

Do I need to replace a list[tuple] with a list[inputText]?

class TextModal(Modal):
    def __init__(self, title: str, inputs: list[tuple]) -> None:
        self.data: tuple = None
        super().__init__(
            *tuple(
                InputText(
                    label = text_input[0], 
                    placeholder = text_input[1], 
                    min_length = text_input[2], 
                    max_length = text_input[3], 
                    required = text_input[4],
                    style = text_input[5]
                ) for text_input in inputs
            ),

            title = title,
            timeout = 360
        )

    async def on_timeout() -> None: 
        raise Exception("Timeout")

    async def callback(self, interaction: Interaction) -> None:
        self.data = (interaction,) + tuple(children.value for children in self.children)
async def text(interaction: Interaction, ...) -> tuple[Interaction, str]:
    modal = TextModal(
        title, 
        [(label, placeholder, min_length, max_length, required, style)]
    )

    await interaction.response.send_modal(modal)

    await modal.wait()
    return modal.data
fleet cedar
#

What's the full error and traceback?

crimson turtle
#
Ignoring exception in view <MenuPage timeout=900.0 children=6> for item <Button style=<ButtonStyle.secondary: 2> url=None disabled=False label='Translation' emoji=None row=1>:
Traceback (most recent call last):
  File "....AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\discord\ui\view.py", line 421, in _scheduled_task
    await item.callback(interaction)
  File "....Bot\ext\bank\views.py", line 207, in transfer
    i, _ = await global_transaction(interaction)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "....Bot\ext\bank\interactions.py", line 405, in global_transaction
    interaction, _value, _comment = await texts(
                                    ^^^^^^^^^^^^
  File "....Bot\ext\bank\interactions.py", line 105, in texts
    await interaction.response.send_modal(modal)
  File "....AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\discord\interactions.py", line 1164, in send_modal
    await self._locked_response(
  File "....AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\discord\interactions.py", line 1198, in _locked_response
    await coro
  File "....AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\discord\webhook\async_.py", line 222, in request
    raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In type: Value must be one of {4, 5, 6, 7, 10}.
#

I use 2.4.1.dev160+g017e4adb, and also tested the latest stable release
A modal is sent to global_transaction (receives the card number for transfer) and a call to texts (which also sends a modal), it turns out that it is impossible to send a modal in an interaction that returns from another modal

halcyon zinc
#

I want to add language support for my Discord bot, what do I need to do for this?

little cobalt
#

Or interactions

halcyon zinc
#

I already know that

#

which system should i use

torpid ivy
#

are there any sort of easy options for putting some sort of divider here? like some sort of horizontal line or maybe even splitting it into a separate box within the embed? i don't wanna do something ugly like just write "------------"

#

I don't suppose you can actually send two embeds in one message?

heavy sky
torpid ivy
#

oooh

#

that's the easy fix then

#

could just have my function return the stats embed and a scorecard embed and then pass those along to respond. that seems the right way to do it

torpid ivy
#

I guess there's no way to get the header formatting (###) into an embed? Tried it in an embed field name but it just put the characters ### lol

fleet cedar
torpid ivy
#

laame

#

I suppose I could just... not give the field a title and only give it a description

#

pseudo-title

#

eh, works for me, i'm happy enough with this lol

#

What about functionality for like.. if I have a list of users, highlighting the reader's name only (like displaying it as @user like a ping would look)? I can see how i'd make ALL of the names user links, but i feel like its a stretch to only display the reader's name in that way

deep blaze
#

when i try installing on vps py-cord dev version it cannot be installed

little cobalt
#

and what is your python vresion?

deep blaze
#

still same error

torpid ivy
#

is there a solution for some (but not all) users getting "This command is outdated"? Or do they just have to wait

little cobalt
fleet cedar
#

And setuptools

deep blaze
#

done

deep blaze
fleet cedar
deep blaze
torpid ivy
#

now that i have a relatively stable bot I need to start looking into the PROPER way to do server permissions, command permissions, web ui integration, etc

fleet cedar
#

also do you use venv or conda or smth

deep blaze
#

not working

deep blaze
fleet cedar
#

only master branch or stable version too?

deep blaze
#

only dev

fleet cedar
deep blaze
#

no wont work either

fleet cedar
#

then try creating a venv 💀

#

oh also update wheel

#

pip install -U pip setuptools wheel

deep blaze
#

how to make a venv and install stuff in it

fleet cedar
#

google might be the best resource for that

torpid ivy
#

or chatgpt

#

chatgpt has been my best friend while writing this crap lol

#

i love giving it a function and being like "is there a better way to do this?"

deep blaze
torpid ivy
#

Does there exist any functionality to highlight a user's name within a message containing multiple names?
like if it's showing a list that's:

user1, user2, user3

if user2 is viewing the message, it will have their name highlighted, but not user1 or user3. And same situation if user1 or user3 views it. if user4 views it, none will be highlighted

fleet cedar
fleet cedar
#

message content it meant to be static yk

cursive leaf
#

How long does a discord attachment get stored by discord for? Is it forever? I want to store evidence images on a moderation bot and am wondering if I can just store the discord attachment link

fleet cedar
torpid ivy
fleet cedar
#

if you really want to make sure the attachments dont get deleted, you can download them on your local computer ||or simply reupload to a a private channel in your own guild||

autumn finch
#

Anyone have any idea why get_member_named, and get_member are only returning None even though I know for a fact the member is present in the guild?

        print(mrpguild)
        invitechannel = guild.get_channel(443614533815369728)
        print(invitechannel)
        invite = await invitechannel.create_invite(max_uses=1)
        print(invite.url)
        row = sheet.find(appnumber).row

        #get values from sheet
        userid = sheet.cell(row, 2).value
        print(userid)
        user = mrpguild.get_member_named(userid)
        if user is None:
            userlongid = sheet.cell(row, 4).value
            print(userlongid)
            user = mrpguild.get_member(userlongid)
            if user is None:
                usernick = sheet.cell(row, 3).value
                print(usernick)
                user = mrpguild.get_member_named(usernick)
        print(user)

little cobalt
#

you should do a check if get_member is None use fetch_member

#

same for get_channel

autumn finch
#

is this new with discords username changes? This use to work perfect

autumn finch
little cobalt
#

basic if else with python

frail ocean
little cobalt
frail ocean
#

Thanks

little cobalt
#

xd

autumn finch
#

The fetch ended up working

fleet cedar
#

but your choice

autumn finch
#

It all started when discord started rolling out the new naming system

fleet cedar
#

it has the username updates n stuff

#

pretty stable rn too

late slate
#

I just noticed @discord.default_permissions(manage_channels=True) decorator does not work for slash commands in cogs (as in, anyone can use the command). What absolutely n00b mistake am I making?

#

Oh... The command is in a slash command group. Can default_permissions only be used for the whole group, or can I use it with a specific command in the group?

late slate
# shell radish only for the entire group

Just stumbled upon that conclusion as well. tyvm 🙂 Looks like I can possibly still check within the function and manually handle it with the following code?

if ctx.author.guild_permissions.manage_channels:
    await ctx.respond("You have the required permission to use this subcommand.")
else:
    await ctx.respond("You do not have the required permission to use this subcommand.")

Only downside is the command would still show in Discord's context menu for commands...

atomic fern
#

how to check if command is used from prefixed command or slash command?

shell radish
atomic fern
#

yes

shell radish
#

.rtfm bridgecontext.is_app

sly karmaBOT
remote meteor
#

Is there some sort of decorator that lets me run checks (for example on_message to see if its a bot) to make it so i don't have to add```if message.author.bot:
return

#

I belive i checked for this before and the only thing i saw was before a task

shell radish
#

why do you have multiple on_messages to begin with

remote meteor
#

Because of different features i don't want in the same cog i guess?

#

Fair enough though tbh

shell radish
#

I would just make one on_message and call different functions/methods

remote meteor
#

Hm didn't think about that 🤔

obsidian stratus
#

What are these intents attributed as

#

Like intents.message_content

shell radish
#

.rtfm intents.pre

sly karmaBOT
shell radish
#

.rtfm intents.memb

sly karmaBOT
shell radish
#

I can spell

obsidian stratus
#

Will on_message detect new messages if intents.members is False ?

obsidian stratus
#

Alright

shell radish
#

literally 3rd line of documentation comment 💀

obsidian stratus
#

Mb, I read that and then deleted my message asap

#

Does discord freely approve for intent.members compared to message content intents?
My use case is only for syncing level roles for members who rejoin

shell radish
obsidian stratus
#

Oh

obsidian stratus
#

Why could the order of the reactions be incorrect

#

I tried adding a 1 second wait but that didn't fix it

shell radish
#

just use buttons

obsidian stratus
#

It's actually a user-message autoreaction

fickle salmon
#

my poll command doesn't have a wait and they're in order

obsidian stratus
#

Hmm, strange

fickle salmon
#
        for i, option in enumerate(new_options):
            ...
            await response.edit_original_message(content=message)
            m = await response.original_response()
            await m.add_reaction(emoji)```
#

although I guess I do edit the message as well, that will add a delay

obsidian stratus
fickle salmon
#

but no artifical sleeps

#

are you doing async sleep?

#

await asyncio.sleep(1)

#

oh yeah you are in your screenshot

#

idk 🤷

shell radish
#

maybe ratelimits

#

can't think of any other reasons atm

#

Other than skill issue

obsidian stratus
#

Using enum fixed it for me, thanks!

shell radish
#

enum ≠ enumerate.

upper hearth
#

using the tasks loop thing if there’s an error does the loop stop?

#

my loop keeps stopping and idk why

#

and i can’t see if it errors bc im sleeping when it happens

deft kestrel
#

what is the best database for a bot?

cyan violet
#

Hey. How can i do an list of members with an specific role? I want to make an uprank system and all members with an specific role (my team members) should be shown in an Option field in the slash command+

remote meteor
#

.database

#

?tag db

limber wagonBOT
#

dynoError No tag db found.

remote meteor
#

?tag database

limber wagonBOT
#

dynoError No tag database found.

remote meteor
#

what

shell radish
lofty parcel
cyan violet
#

how?

lofty parcel
#

How what exactly

cyan violet
#

autocomplete

deft kestrel
rugged lodgeBOT
#

Here's the slash autocomplete example.

cyan violet
#

do you have an example for me?

lofty parcel
#

The repo does

lofty parcel
deft kestrel
# shell radish yes

and what happens if the bot starts recording 2 data at the same time? this seems unacceptable in SQLite

cyan violet
#

idk how

#

i want that only members with a specific role shows up

lofty parcel
#

You need to get the role in the autocomplete

#

Then return the members names

#

And then internally in your command you'll need to get them by name

shell radish
cyan violet
lofty parcel
#

No

#

Not really

#

Understand the example

#

And then work from that

#

.rtfm AutocompleteContext