#Basic Pycord Help (Quick Questions Only)
1 messages · Page 93 of 1
?tag localfile
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)```
the filename cant be a directory
How to solve this err ?
shouldn't it be len(winners)?
guild.self_role
async with conn.cursor() as cur:```
do i have to do this everytime i want to execute something with my database
(connection pool)
try using discord.utils.utcnow()
instead of datetime.datetime.now()
and don't use bare excepts since it's bad practice
Is there any way i can get the result back(self.raffle) to this class i created the modal object
https://i.imgur.com/uMlSEIu.png
you'll have to do the print in the modals callback
Probably wait method
whats the difference between msg.edit and msg.edit_original_message here?
You should use await ctx.interaction.edit_original_message
How Do i know the person that used a slash command?
ctx.author
thx
b!rtfm pyc discord.ApplicationContext
discord.ApplicationContext
discord.ApplicationContext.bot
discord.ApplicationContext.cog
discord.ApplicationContext.command
discord.ApplicationContext.delete
discord.ApplicationContext.interaction
discord.ApplicationContext.invoke
discord.ApplicationContext.respond
discord.ApplicationContext.selected_options
discord.ApplicationContext.send_modal
First one
hmm ok
Yes it is, and it works with commands.Context.send and commands.Context.reply but no with discord.ApplicationContext.respond
Here's the slash options example.
@fervent cradle ^
probably based on the aio prefix
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
raise discord.CommandError("the error")```
except there's no commanderror exception, the closest would be ApplicationCommandError
depends. i would maybe say asyncmy but it's up to you
oh bruh discord didn't show me this until i reopened entirely 💀
i'll give it a try thanks
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?
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
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```
Those are pretty self explanatory. But it means one or more the option names are already used in the options set.
3 seconds
All good :)
Is there a way to lengthen that period of time?
interaction responses have 3 seconds but followups have ups to 15 minutes
so what you do is defer the response, wait until it's processed and then send a followup response
Thank you
hmm still stuck on my error
thanks, i have 4 verified bots but im more old school im not used to all this new stuff
?
The guide mainly explains the new stuff I think.
👍🏻
What permissions do I need to give a bot in the url generator if I want to enable message_content?
That's an intent, no an auth permission
I see, so I then I'd set it w/
intents = discord.Intents.default()
intents.message_content = True
bot = discord.Bot(intents = intents)
In options.4: Option name mode is already used in these options
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 
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):```
The decorator is for a prefixed command

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
Yeh
imo its his fault
you might also wanna use guild_ids = []
Is it compulsory to shard my bot after 2.5k servers?
how do you disable a button from a different class
i would say that above 1K servers is when you should start sharding your bot. so probably u should imo
so i tried printing the status of a user and i got offline even if the user is online
print(user.status)
dose anyone know how to make a button look like it has responded without sending a messages
Aight Gotcha
is discord.CustomActivity visible to human users
await interaction.respond()```i think
dose a message need to be parsed
i dont think so
didnt work 
U can disable it or edit the label
thats not a bad idea

how do i get the human count and bot count of a server?
I would get the guild then loop for each member to check if they are a bot and add a counter
guild.member_count
Members:
len(list(filter(lambda m: not m.bot, interaction.guild.members)))
Bots
len(list(filter(lambda m: m.bot, interaction.guild.members)))
that should return the count
nvm
thank youu
Why can't I get the description of my commands in my help command ?
I don't use slash commands btw
only normal commands
people are saying you can mention slash commands… how?
</name:id>
e.g.
</hi:12345678>
</hi:12345678>
how do you get the id?
thanks!
since yesterday my bot is restarting a few times a day. did anyone had the same problem?
im getting In 4: Application command names must be unique even though there is no other with the same name
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In 15: Application command names must be unique
yeah same here
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
i dont have a group, yet i still get the error
discord limitation pretty sure
when i remove the last command i added its fine?
command=self.bot.get_application_command('mode setmode')``` and for some reason, command is `None`
no idea
still cant figure this dumb thing out
well I think that it fetches a top level command
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
)```
How do I make my commands non-case sensitive?
which commands
all my commands?
I meant text commands or application commands
do you mean case insensitive?
yeah
text
In the client object
b!rtfm pyc commands.bot
discord.ext.commands.Bot
discord.ext.commands.Bot.activity
discord.ext.commands.Bot.add_application_command
discord.ext.commands.Bot.add_check
discord.ext.commands.Bot.add_cog
discord.ext.commands.Bot.add_command
discord.ext.commands.Bot.add_listener
discord.ext.commands.Bot.add_view
discord.ext.commands.Bot.after_invoke
discord.ext.commands.Bot.allowed_mentions
ok I’ll try now ty
works guys ty
okh
ofc

why did you need to get them again?
i need to get the command so i can do this value=f"/{command} {command.signature}",
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
make a list of prefix
please read the docs
Or maybe it's the when mentioned_or
this pretty much
Dude u fast af
i haven't clicked

and hope i got it correct
Lol it is
i did this
print(command.name)```
and i saw"mode" but not "mode setmode"
wait
i saw "setmode"
but its still none... what?
Ty
so what do you get again?
yeah. but that's for discord.ext.commands.Command
oh shit
aren't we talking about discord.ApplicationCommand?
yes, we are. then how can i do this
When using autocomplete, is it possible to access ctx.guild? I am getting an error of discord.ApplicationContext has no attribute guild.
you have https://docs.pycord.dev/en/master/api.html#discord.SlashCommand.options and probably just do it manually, ig
discord.ApplicationContext
wait what
autocomplete with applicationcontext?
why doesnt SlashCommand have qualified_name
i think i accidently type hinted it wrong
it inherits from ApplicationCommand so it does have it ref: https://github.com/Pycord-Development/pycord/blob/master/discord/commands/core.py#L566
Pycord, a maintained fork of discord.py, is a python wrapper for the Discord API - pycord/core.py at master · Pycord-Development/pycord
oh wait no i meant the error was discord.AutocompleteContext has no attribute guild
what about acctx.interaction.guild
when helper doesn't read docs
i forgot there was .interaction with ctx with discord.AutocompleteContext lol
but yeah i should have done that first
how would I get my CPU usage / RAM usage for a command?
like directly from my host
i wish it wasnt SlashCommandOptionType.integer and it was just integer
bruh it's literally just mem_per = round(psutil.virtual_memory().percent,1) for RAM % and round(psutil.cpu_percent(),1) for CPU %
you can just input int
the same goes for all slash options types, you can use the original type instead of SlashCommandOptionType
hm?
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
bruh
anyone can use it if they want btw
idk
ty btw ^
mother of iseven
what is this
how do i make choices like
Here's the slash options example.
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
What version are you using?
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
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.
ah it works if i do it like that
would adding a try except work if i iterate through the files?
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
TestEvent.py works but Tickets.py doesnt
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?
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)
is guild a placeholder here and you removed the guild ID or you didnt put an ID in there? the function requires an Guild ID to be passed as an argument
the guild ID is passed through
it requires the ID to be integer, are you sure you saved it as an integer?
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
Where does the guild inside the get function points to
wdym?
its a guild id
.
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)
And your OpenTicket function is?...
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
self, user, guild
And when calling the function
You're passing commands.Bot, user, guild id
yes
Not how it works?
oh
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
wait am i actualy that dumb
but the issue is im not passing the bot instance through to the ticket shit
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
i learned python 2 years ago
Refresh your python then?
issuse, when i do that, it gets the ticketbutton class
nono i mean
how do I get the nickname of the server creator?
ctx.guild.owner.nick does not work
ctx.guild.owner.display_name
thx

ayo pog
Items are not cleared even when "Disabled" is getting logged in console
#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
youre not editing the message
you need to edit the message with the updated view for the new changes to appear