#Basic Pycord Help
1 messages · Page 49 of 1
He's Steve jobs bud, he's got money
wait does this still crash everything if something dies on runtime?
cuz like
loading it i already have handling foe
for
but this died during its running
yea, no, i asked him to please get more RAM, and he said he needed to ask his dad .-.
yet ec2 is like so much more expensive than anything else
What error made your bot crash?
I've honestly never had my bot stop for a runtime error
me neither up until now
.
i fixed it by specifing
but literally 0 commits have been made
I can only imagine a reconnect with that error
discord api bug or whatever toothy said
idk how a param causes a runtime crash in the first place
because it should only take it in once
i think
thats why i said reconnect
the thing is, my dad is very proficient at using ec2 and aws shit
also my bot's website is hosted on aws
- some other complicated shit that even i don't really understand lol
That's their business model
If you're only at 7k members then you should absolutely not be running into any cache issues
That's very silly, my bots with 40k members use under 400mb
my 400 member server bot uses like 400mb too 
I also remember running my first two bots on the student trial windows ec2 instance for a year, if you've somehow capped that out then you're doing too much
maybe they are caching alot of things like prefixes for each guild and all
no
elif member.guild_permissions.ban_members:
^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'User' object has no attribute 'guild_permissions'
in doc I can see there are guild_permissions for user object ??
what should I do?
get their member object
i mean, show your code first of all
class Bankick(commands.Cog):
def __init__(self, bot):
self.bot = bot
@discord.slash_command(guild_ids=GUILDS, name="ban", description="Bans a member")
@commands.has_permissions(ban_members=True)
@option("member", discord.Member, required=True)
@option("reason", str, required=False)
@discord.default_permissions(ban_members=True)
async def ban(
self,
ctx,
member: discord.Member,
reason: str | None,
):
if member.id == ctx.author.id:
await ctx.respond("You can't ban yourself!")
elif member.guild_permissions.administrator:
await ctx.respond("You can't ban an admin")
else:
if not reason:
reason = f"None provided by {ctx.author}"
await member.ban(reason=reason)
await ctx.respond(
f"<@{ctx.author.id}>, <@{member.id}> has been banned successfully from this server!\n\nReason: {reason}"
)
@sage tendon
yea
if you do discord.User itll be converted to a User object which lacks any guild specific stuff
Like this? or changing all members to discord.user
none
your code is good as is
but it gives error
yea because you are putting the ID of someone in who isnt in the server anymore
dont do that, or make your code able to handle that
how can I do that
check if its a user object
also uh, your bot role shouldnt be so high as to be able to kick admins
if somebody has admin you cant kick with this code am I wrong @sage tendon
if member.id == discord.User like this?
Yes, but your bot should never be above an admin role..
isinstance()
"==" is for comparing values,
"is" is used to compare types/states
isinstance like toothy told you is the best option in your case.
trying to reset the cooldown of a command inside of my slash command in a cog but i just get none type has no attribute reset, i've tried both
command_name.reset_cooldown(ctx)
self.command_name.reset_cooldown(ctx)
do i need to get the command first and then use it? if so i also get none type
maybe there is an even better way to do it. can you explain why/how exactly the unwanted cooldown is casted and why you want to remove it?
i have a command that's moving players from one team to another and also updating their database. if a user is being added to a team as a free agent i have a check for that and want it so people can add a country code in that case and not wait the standard cooldown
you could use your own cooldown
def custom_cooldown(ctx):
if any(role.id in ALLOWED_ROLES for role in ctx.author.roles):
return None
else:
return discord.ext.commands.Cooldown(rate = 1, per = 3600)
this is my current implementation for a custom cooldown i already have, certain roles have no cooldown otherwise its just 1h
can i upload a gif in bot pfp?
yes
415?
do it from dev portal
same problem
then blame discord
LMAO
did you already try bot.user.edit
discord has no attribute bot
bot or Bot
Bot
you probably have conflicting discord libraries. Did you make sure to first uninstall all packages using the discord namespace, then installing the pycord library?
Yeah I deleted Discord dot pi and then installed pycord
We’re fine without using flash commands. As soon as I want to use them, it becomes a problem. I don’t know if it’s a pie cord thing.
Sorry I’m on mobile
pip list and send output?
i want to list ban member
speak sentence, get help
I'm planning to add a command to our Discord bot that lists all banned members. Are there any specific requirements or guidelines I should follow for this implementation?
like, what
add a command to our Discord bot that lists all banned members?
"any specific requirements or guidelines I should follow for this implementation"
i have no idea what this is supposed to mean tho
what do you mean with guidelines
https://docs.pycord.dev/en/stable/ here are the docs if you mean those
Pycord is a modern, easy to use, feature-rich, and async ready API wrapper for Discord. Features: Modern Pythonic API using async/ await syntax, Sane rate limit handling that prevents 429s, Command...
ya i need this for ctx.guild
use the search
thx
Is there such a thing for errors that occur when I press buttons etc.?
async def on_application_command_error(ctx: discord.ApplicationContext, error: discord.DiscordException):
if isinstance(error, commands.CommandOnCooldown):
await ctx.respond("This command is currently on cooldown!")
else:
raise error # Here we raise other errors to ensure they aren't ignored```
guys
when I try ctx.respond using a slash command
and try to send my discord embed
it just sends <discord.embed at yadayadayda>
any ideas?
You're not using the embed kwarg
wdym
?
You have on_error if you subclass your views
You're not passing your embed with the embed= kwarg
it works now thanks
one more thing
how can I detect if a user is spamming messages
or spam editing channels
or spam handing out perms
u get the idea
thats an issue you have to solve yourself really
need to record all those actions and decide how much is too much
or use an established anti spam and anti nuke bot
nah I wanna have my own
ur right
nope is this not, there is an on_error but it’s for everything
The library has helpers to help create component-based UIs. Shortcut decorators: Objects: Attributes children, disable_on_timeout, message, parent, timeout. Methods cls View.from_message, def add_i...
and Dark already told them that
this also exist but it’s not for all view you will need to setup for each
there's no need to reopen that issue
i did not talk about the same thing
i'd just subclass all views from one main subclass then, issue solved
you that’s the thing
the on error exist also so i can if i want tell him about that
Sometimes it surprises me how smart you can be
little bit of this, little bit of that
literally basic oop
sssh
is it possible to make group commands from slash commands ?
group cant be command also with slash
okay so to imitate this behavior I should probably have a choices as second argument thank you
yes
how to create automod rule
Models are classes that are received from Discord and are not meant to be created by the user of the library. Attributes key, url. Methods def is_animated, async read, def replace, async save, def ...
bruh I couldn't find that
will do in the future
i've had enough of not getting my searches
I found a lot
newrule = await ctx.guild.create_auto_moderation_rule(
name = "Spam setup",
event_type = discord.AutoModEventType.message_send,
trigger_type = discord.AutoModTriggerType.spam,
trigger_metadata = discord.AutoModTriggerType.spam,
actions = discord.AutoModActionType.block_message,
enabled = True,
exempt_roles = None,
exempt_channels = None,
reason = f"Rule creation ordered by {ctx.author}",
)
this returns this error:
File "c:\Users\[redacted]\Desktop\vscodeprojects\[redacted]\main.py", line 67, in spamsetup
newrule = await ctx.guild.create_auto_moderation_rule(
AttributeError: '_EnumValue_AutoModTriggerType' object has no attribute 'to_dict'
trigger_metadata should be a AutoModTriggerMetadata
Models are classes that are received from Discord and are not meant to be created by the user of the library. Attributes key, url. Methods def is_animated, async read, def replace, async save, def ...
trigger_metadata = discord.AutoModTriggerMetadata(mention_total_limit = 5)
it says I need a comma, and in the docs none of the other parameters are optional
so can I not just set a mentionlimit?
ok i see
oh shoot
-_-
newrule = await ctx.guild.create_auto_moderation_rule( <--- this line right here
name = "Spam setup",
event_type = discord.AutoModEventType.message_send,
trigger_type = discord.AutoModTriggerType.spam,
trigger_metadata = discord.AutoModTriggerMetadata(mention_total_limit = 5),
actions = discord.AutoModActionType.block_message,
enabled = True,
exempt_roles = None,
exempt_channels = None,
reason = f"Rule creation ordered by {ctx.author}",
)
Returns this error:
Traceback:
File "c:\Users\[redacted]\Desktop\vscodeprojects\raidbot\main.py", line 67, in spamsetup
newrule = await ctx.guild.create_auto_moderation_rule(
AttributeError:
'str' object has no attribute 'to_dict'
-I have no clue what's going on
-It's been happening for a while
Is that the full traceback?
i can send it if u want
thats where the error is and what it is
yes please :)
full traceback is needed for this issue
😄 will do
here u go:
Traceback (most recent call last):
File "C:\Python312\Lib\site-packages\discord\bot.py", line 1137, in invoke_application_command
await ctx.command.invoke(ctx)
File "C:\Python312\Lib\site-packages\discord\commands\core.py", line 435, in invoke
await injected(ctx)
File "C:\Python312\Lib\site-packages\discord\commands\core.py", line 146, in wrapped
raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: AttributeError: 'str' object has no attribute 'to_dict'
+Full traceback
done
stay now in one channel pls ;3
actions have to be a list
I still dont think that this is the full traceback. There might be more above. Sometimes there is a blank like that makes it look like a different error but it is related
your action is a single action but the docs require it to be a list of actions
ohhh
still doesn't work
show your code and the traceback
👍
also, why do you explicitly pass "None"? just leave those options away
newrule = await ctx.guild.create_auto_moderation_rule(
name = "Spam setup",
event_type = discord.AutoModEventType.message_send,
trigger_type = discord.AutoModTriggerType.spam,
trigger_metadata = discord.AutoModTriggerMetadata(mention_total_limit = 5),
actions = [discord.AutoModActionType.block_message],
enabled = True,
exempt_roles = None,
exempt_channels = None,
reason = f"Rule creation ordered by {ctx.author}",
)
wait
PS C:\Users\[redacted]/Desktop/vscodeprojects\raidbot> & C:/Python312/python.exe c:/Users/NishanPC/Desktop/vscodeprojects/raidbot/main.py
We have logged in as Glum#9657
Ignoring exception in command spamsetup:
Traceback (most recent call last):
File "C:\Python312\Lib\site-packages\discord\commands\core.py", line 138, in wrapped
ret = await coro(arg)
^^^^^^^^^^^^^^^
File "C:\Python312\Lib\site-packages\discord\commands\core.py", line 1082, in _invoke
await self.callback(ctx, **kwargs)
File "c:\Users\[redacted]\Desktop\vscodeprojects\raidbot\main.py", line 67, in spamsetup
newrule = await ctx.guild.create_auto_moderation_rule(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python312\Lib\site-packages\discord\guild.py", line 3925, in create_auto_moderation_rule
"actions": [a.to_dict() for a in actions],
^^^^^^^^^
AttributeError: '_EnumValue_AutoModActionType' object has no attribute 'to_dict'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Python312\Lib\site-packages\discord\bot.py", line 1137, in invoke_application_command
await ctx.command.invoke(ctx)
File "C:\Python312\Lib\site-packages\discord\commands\core.py", line 435, in invoke
await injected(ctx)
File "C:\Python312\Lib\site-packages\discord\commands\core.py", line 146, in wrapped
raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: AttributeError: '_EnumValue_AutoModActionType' object has no attribute 'to_dict'
you need one of these
Models are classes that are received from Discord and are not meant to be created by the user of the library. Attributes key, url. Methods def is_animated, async read, def replace, async save, def ...
where??
instead of an AutoModActionType
trigger_type = discord.AutoModAction(action_type=discord.AutoModActionType.timeout, metadata=discord.AutoModActionMetadata(channel_id=ctx.channel, timeout_duration=20m, custom_message="Message blocked. Do not spam."))
it says that
parantheses aren'tclosed
no
The API provides some enumerations for certain types of strings to avoid the API from being stringly typed in case the strings change in the future. All enumerations are subclasses of an internal c...
read the docs.
automodaction goes into the action kwarg
should be obvious from the name
dont get it
Bud
read this. pass what belongs.
You're providing to trigger_type a AutoModAction
When trigger_type takes a AutoModTriggerType
And actions is the one that receives a list of AutoModActions
Hey there, is it possible with paginator to use dropdowns menu or do i need to make it from scratch?
can you eleborate on what you want to do
I would like to make an help command where by a dropdown menu you can select for which category of commands you want to see the information for, and everytime you select the category from the dropdown menu the embed updates.
I was asking if paginator supports dropdown menus and if so how do i use them with paginator
Yes you can
When you make a page group with the paginator it will create a select menu for switching between groups
https://docs.pycord.dev/en/v2.6.0/ext/pages/index.html#discord.ext.pages.PageGroup
You can make a page for each command and pass the list of pages to the page group "category"
Alright thank you very much!
same error still cant figure it out
can you show the code again
sure 🙂
you arent listening
You are still passing the wrong type to actions
what do u mean
And
actionsis the one that receives a list ofAutoModActions
yeah so did I not make it a list?
I'm confused
do I need more than one action?
you are passing the wrong thing in the list
What's the right thing?
then
.
mb plun
Is it possible to make a discord bot that can;
For example,
A webhook is named Xavier but it says "Govern.co" as it's username.
It takes that Govern.co webhook user, switches it to "Anonymous" as it's username, with the same message, or altered message that sends the user to a website by saying "Go Now!"
Yes
Webhook.send takes a username (or user) kwarg
.rtfm webhook.send
I think I already know the answer to this - but with slash commands/autocomplete I have my autocomplete that retrieves the names from the sqlite3 db and then those names are used in the autocomplete. However when I obviously hit enter at present I pass the "string" i.e. the name and have to make another call to the db to retrieve the additional details - I assume I can't pass the "object" i.e. list of dict from the autocomplete to the command for example?
No, but you can cache the name dict pair from the first call. {name: dict} Than in the command reference that cache instead of making a second API call.
make sure to cache it based on the user and clear it every few minutes
discord.Emoji
discord.Emoji.animated
discord.Emoji.available
discord.Emoji.created_at
discord.Emoji.delete
discord.Emoji.edit
discord.Emoji.guild
discord.Emoji.guild_id
discord.Emoji.id
discord.Emoji.is_usable
discord.Emoji.managed
discord.Emoji.name
discord.Emoji.read
discord.Emoji.require_colons
discord.Emoji.roles
discord.Emoji.save
discord.Emoji.url
discord.Emoji.user
discord.PartialEmoji
discord.PartialEmoji.animated
just use the docs search
No
ok
next release
any beta
master has it I think
ok
how do external apps work?
do they work in any server
yes, thats the point
where can i find the docs for it
Pycord is a modern, easy to use, feature-rich, and async ready API wrapper for Discord. Features: Modern Pythonic API using async/ await syntax, Sane rate limit handling that prevents 429s, Command...
thank you
i already told you
yes
when
#1132206148309749830 message
ok so what I mean is
how can I record and in essence create my own audit log
that the bot can see
then I can use datetime to observe how closely the actions are taking place
i mean, thats what you have to figure out really
use a database, handle it all in memory, everything's possible
so I set up a whole log system
basically any ban, kick actions are recorded precisely with details and precise time
but my problem now is
I don't know how to listen to when a ban happens, and determine if the last ban was within x time to take action
and ik about bot.add_listener
please just use the event reference https://docs.pycord.dev/en/stable/api/events.html
it has everything you want
You're supposed to store that yourself and check timestamps
hey there, is it possible to suggest slash command so the person click it and it appears in his message?
or ctx.command.mention
No unfortunately
alright thanks, this is going to be added anytime soon?
I think (from what someone said to me, just quoting) that they didn't do that and preferred working on the ui component (buttons, select menus, etc...). But i wouldn't say it will come anytime soon as it is something quite niche
But by suggesting options you mean like having someone click on a command and it being prefilled?
yeah kinda
yeah so that's not possible
the command is /image collage and the option is layout
and i want that the user can click on a message that fills the layout option
no, discord removed that because of potential for abuse
Anyway how do i get the SlashCommand class?
ctx.command will return a SlashCommand object if used by a slash command
and if it's not used by a slash command?
yeah that's better, although how can i get the id?
oh thanks i didnt know about this
you also have discord.Bot.get_command("help") if you want in your code
yeah that's probably better, thank you to the both of you
especially if your commands get re registered with a different id for some reason
sub-commands would be like </math add:123>
i have a bot where i do the testing in a server and i have another bot in the actual server, so yeah it's better to use discord.Bot.get_command
exactly
no need to change the id this way
this doesnt return the id tho?
then you need to do .qualified_id
It doesn't mention it for some reason
Non c'è bisogno di metterlo in ``
Hai ragione mi ero scordato che ora era una menzione e quindi non mi serviva più segnarlo con i ``
U Italian?
Yeah
How do know italian anyway?
Lmao I have an Italian version of me
My dad is swiss italian
And I spent basically the first 13 years of my life going to school in italian
is it normal for discord bots being used by several thousand ppl to experience memory fragmentation
Yeah your italian was perfect
That's why there is sharding
uh my bot is in 113 servers
nowhere near the point of having to consider sharding
uh oh
but a few of the servers have a huge amount of users
But why is memory fragmentation a big deal anyways?
Like it's the point of ram to fix that
i'm running the thing on ec2 free tier
and i sometimes find sudden jumps in memory usage
that don't go down
i asked chatgpt 4o, and it tells me it's most likely memory fragmentation
that's bs
Maybe run some profilers on your python code, or just use a better provider honestly... even though ik that is not a real answer
i used objgraph to find which objects grow a lot, and used psutil to tell me my memory usage at different times
each one of those "----" things corresponds to a 15 minute interval
for the 87.39 to 92.39, there aren't new objects, but there are new objects for the bunch of 92.39's
Yeah but like - in your python code, you can run profilers to see what code takes memory - https://github.com/bloomberg/memray check at this for example
i've used tracemalloc
the lines that take the most memory are all the ones used by libraries
it could be the cache
what intents do you have enabled on your bot?
all
and do you need all of them?
you just have a big bot. ec2 free tier is just simply unviable
113 servers, ~7-8k users is considered big?
user wise yes
more than average. It's like you can run a minecraft server on a rpy fine but only for 4-5 users. Same kind of thing
I mean you can check, you can already get neat things for just a couple of dollars a month
if you are a student, microsoft azure is a free solution
not gonna mention anything not to make advertisement
i'm almost 17
ooh didn't know that
not in uni yet, if that's what you mean by "student"
I got all my students benefits while not being in uni aw
pycord is sponsored by nordblade i think
student = any one in school which includes high school
i see
the thing is, i don't think my dad's that proficient at azure, and he's the one who made all the configs for my ec2 host
and i don't have the time to learn aws well enough to do it all alone
The thing is, you don't need config for a discord bot, you need config for aws
yes i mean aws
nor you need much config for running a small docker container
at this point, I would really look for some small cheap vps, instead of getting locked behind config stuff
azure should support docker
i don't use docker
and docker is like easy
docker is always a good thing to learn
shouldn’t take more than 10 min to setup imo
yeah
also, my bot's website, as well as its db, are both hosted on aws
using route 53 (domain) and rds (db)
both of which my dad are highly proficient in
At this point I don't wanna look mean, but i don't think that using aws for everything is the way. Your dad (probably) uses that because of complex problems he has to face, like scalability, and high availability. Aws and other cloud providers can be helpful, but in the end, end up costing a lot and add unnecessary (in your case) configuration steps, which while probably helpful for the aforementioned usecases, make no sense to have on a discord bot.
a lot of the configuration is for like security
what security
the like only security issue is like your host getting ddos’ed and sql injects
Exactly what I meant
tbf he uses aws for work
You need that because the db is meant to be scalable and be accessible from everywhere and replicated
But you don't need that
Like if you spin up a small docker stack with a db + a custom image + some webserver you can call it a day, and forget ips access, because there isn't any public facing ports for the database
i can't just host this thing locally
besides you don't need aws to have a firewall, most hosting providers give you a nice and clean interface for that
Sure, but that dosen't mean you need to host them on aws and big cloud either
You get a small vps and you can forget it until your bot becomes wwaaay bigger. On the other hand, with big cloud providers, you would start getting instant bills, and be locked behind their thing because they won't allow you to take out your database data without paying even more. Trust me, go away while you can. Big cloud has a lot of advantages, but not really for you right now.
It is interesting when it handles a bunch of complicated things for you, and it becomes actually worth paying for it.
wdym by "taking out db data"
if you try to migrate to something else, they will charge based on how many bytes of data you have
interesting
i tried it and it was so confusing, i don't think they actually give you the free hosting. it's all buggy
although I haven’t used it myself, I have friends that genuinely recommend it
I don’t know more than that though
i dont know, im part of the github student program but yeah it was pure mess tbh
i don't have any problem getting other free things like the jetbrains softwares
i ended up paying for a ovhcloud vps, 1€/month
using railway rn and paying 0
I just use my own Server and paying for the electric bills...
I started with ovhcloud, then switched to other stuff because I disliked their ui & ux and found it very messy, and often bugged. But I can say it really mich worked fine, and did what it advertised.
Yeah until you need to host websites that's what sucks
cuz I did the same for a long time
the ux is indeed complicated, but i only used their site when i had to buy the vps so yeah i don't really care
right
i just access the vps with ssh
Yeah I definitely didn't have only a vps there, I had a bunch of other things like domains and webmail, and I just moved everything
i would never buy domains from ovh they have insane prices tbh
I live in a country where their picing was the cheapest
i use ssm for my current ec2
switzerland?
ye
oh
arent the prices in switzerland VERY high? this is what ppl say in italy
Grüezi
Yeah it is indeed. It's like salaries are higher but costs as well
Keep in mind that you also get more money than
Schweizer Franken
Salü zäme
average salary in italy is probably 1400 ish
month, day, year?
yeah switzerland is probably way more
idk
yeah per month sorry
but at the same time it's an average, so you have like 1% of people bumping that
yeah probably a lot of people have lower salaries
I dont know if its right
10k per month?
some say it 4k?
what language is that
German
i see
but Ik the minimum salary, if you work 100% is around 3.5k chf
@echo wraith i was looking at your website and wondered why wikipedia is a skill then realized it’s wordpress
lool I should really remove that as well
like at some point i was like i will add everything I did at some point
uh
But also should just remake that website, cuz I didn't touch it in like 1 year and it's from when I didn't know to program yet
are you also in hs
wdym
what is this?
arduino
high school
ye
wrong answer: limits to positive or negative infinity
it's an italian company?
yeah from Torino
strange, i've never heard of them
I dont know if this is expensive for domains
Aber das ist nur für die erste 12 Monate
#general
^^
aight
Warum zum Fick ist die .de option Bollinger als .info
💀
*Billiger
Sogar .eu ist billiger
Wtfff
.org teurer als .com ergibt eig auch wenig sinn
how would you host a domain you purchased from aws on something other than aws
Make its dns point to watherer ip your server uses
interesting
Hi there!
I wanted to know if you found it convenient to do an “import discord” in all the files of the project or if you had done otherwise?
Is it possible to buy a bot Nitro so that you can upload and share files up to 500 MB with the bot?
no
Does that mean I can only get up to 100 mb via Server Boost Level 3?
Not really, but if you structure your code well, not all files would need that
pycharm tells me that intent attributes are read only, so would doing smth like that have any effect
no you can ignore
so they do have effects?
pycharm want you to remove the spaces at the =
but you can ignore stuff like that
This works fine
i see
yes
but you should probably start with intents.default() and then enable or disable what you need
in that case i'd have to disable those things + enable messages, presences, and members, which is more lines
Hey there, im trying to put some local images in my paginator embeds although they aren't showing. What im missing?
You need to pass the files into each page too
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)```
Thank you very much, i got it
(Also, commands have a mention attribute you can use instead of formatting it yourself)
yeah i know but im a little bit confused on how to get the slash command class
Well you're already doing it
With get_application_command
Or get_command i forget which one applies where
i just replace #.qualified_id with #.mention right?
Ah get_command works if you're using discord.Bot
Pretty much, and remove the other </ parts since it's all included
yeah thank you
that's not the issue, and not what any linter would suggest
youd only ever consider that for passing kwargs
Does anyone know how to use the emojis thing in the dev portal?
do you mean through the api, or the actual portal?
API.
see #1132206148309749830 message, it's currently not merged to master
you can still just use the emoji markdown, no?
well yeah, but they probably mean actual management of the emojis
Hm okay.
Is there an issue for tracking forwarderd messages support?
we didn't open the pr yet because it's still widely unsupported and unfinished on discord's end
k thanks
Is there a way to test slash commands without waiting for an hour?
...why would you need to wait an hour?
Thats what these guys were saying: https://stackoverflow.com/questions/71096160/pycord-slash-commands-how-do-you-set-guild-ids-too-all-guilds-bot-is-in
that was never really true
restart discord and they'll appear
commands sync in seconds
Okay thanks, i'll try that since I don't like waiting
it was true when slash rolled out, the answer is just outdated
Restarting discord client indeed fixed it, thanks
i think i tried making slash commands on day 1 but i dont recall ever waiting longer than like 1m max
use ctrl+r, its faster
and you dont have to restart if you only change the function content
Thanks, I didn't know about that
it was widely tested and actually announced that global commands would take that long to sync, lib devs wouldn't have pushed users to use guild commands so strongly otherwise
prolly cause my bot wasnt in a lot of servers then
Yes, I was adjusting my existing commands and that was all instant and then I got confused once I added a new command
actually in slash commands even if u type hint a parameter as discord.Member still it will get discord.User because discord returns a user object so they would have to add an additional line to get the member object and that would be member = ctx.guild.get_member(user.id)
no.
that is just completely wrong
It's only a user object if the ID that was supplied is of someone who is not in the server
If the person is in the server, it will always be discord.Member unless the command is from a user app
That wrong lol
Discord always supplies a discord.User
It's the library that makes the conversion
Or that's what I remember Nelo said
not quite
I shut
the option type is ONLY user (i.e. if you annotate member: discord.Member, discord just interprets it as a user - this is why you can pass any user ID, not just member IDs)
discord does the conversion on their end and will return either member or user
yep
it's kind of dumb that you can't force it to actually be only member, since right now you have to handle the case that a non-member is submitted in any member options
There is even more to it,
You also have to handle the possibility that you get Discord.User in some rare cases.
(it happens, trust me)
thats... exactly what i just said
OHHHH
Silly me, i thought you were refering to "None" as in "can't find any data for some odd reason"
I beg your pardon Mr. Toothy 🙃
got channel permission change a hard ratelimit like renamen them?
I know if you change the channel name its like 2 every 10 minutes
but is that also for permissions?
don't think it's nearly as strict, no
channel names were made stricter because discord got tired of people using them as live counters
hey guys, any idea why my bot is doing that? when sending the right file
however when i send a wrong voice or a wrong file extension it does not
my friend tried it, it worked for him, not for me
it doesnt even print the content just says failed
nothing in console?
ughh my bad i changed pc and didnt turn on auto save on vscode 😭 so it was blank
rip LOL
spent like 20m on that
With server members etc.
it's a way for the user to have a custom example of how a prefix command works
the default help command of commands.Bot displays command.signature, which is a list of arguments
if you specify usage in a command, it will be used instead of the default signature
(it's easier to understand if you just try your bot's default help command)
I can't tell a difference between when I have usage="..." and when I don't
you would have to compare on an individual help command (e.g. help command_name)
mhm
I kept changing it to some small text and missing it as a result
How can I get name from interaction_metadata as in deprecated interaction.name?
the username?
nope
then the name of what lol
I used it to get the name of the application command
ctx.command
message object
That's very sad.
Luma, they only have the message
Damn you actually use French keyboard layout- respect
So use the message to get the context and then use that
i doubt they'd need to go off a message object if its their own bot's commands
they'll need to tell us
They don't have interaction. message.interaction is deprecated
And that is the parameter required in get_context
Message is not the requirement for the context ?
Ooo maybe not since it’s for slash command and not prefix in this case
No it's interaction
Yep mb
OFC French >
Yeah and then comes the French keyboard..... What the-
Bepo is fire but I'm not motivated enough to learn how to use it
4th actually
How can I supress DeprecationWarning?
fix it and dont use something that's deprecated :>
is it possible to add an image to embed that's not a url but a file
.local-file
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)```
thanks
there is no interaction.name alternative
continue using interaction.name and hope discord adds an alternative in the mean time
That's what I want to do, but I need to suppress the DeprecationWarning.
import warnings
warnings.filterwarnings("ignore", message="divide by zero encountered in divide")
-# Source
I think this should work
interaction_metadata.name actually does exist on the api, but discord is intentionally leaving it undocumented
changes the message to whatever warning you are getting ofc
Looks like it's not working.
show your code
What is the best practice for catching errors like this?
discord.errors.DiscordServerError: 503 Service Unavailable (error code: 0): upstream connect error or disconnect/reset before headers. reset reason: connection termination
what are you doing that causes that error
It rarely happens, but it completely crashes the bot I think
It was with a simple channel.purge, but I think Discord servers were having issues that time
pycord should completely handle such errors, and it shouldnt crash the bot
Hmm, okay i'll let it go for now, no use on adding a lot of try and excepts everywhere for something that rarely happens
can you show the full traceback
if anything, you make a global error handler for that
Sure, this is it:
Traceback (most recent call last):
File "/home/akkie100/.local/lib/python3.9/site-packages/discord/ext/tasks/init.py", line 169, in _loop
await self.coro(*args, **kwargs)
File "/home/akkie100/fintwit-bot/src/cogs/loops/timeline.py", line 144, in get_latest_tweet
await self.on_data(tweet, update_tweet_id=True)
File "/home/akkie100/fintwit-bot/src/cogs/loops/timeline.py", line 172, in on_data
e, category, base_symbols = await make_tweet_embed(
File "/home/akkie100/fintwit-bot/src/util/tweet_embed.py", line 80, in make_tweet_embed
e, category, base_symbols = await add_financials(
File "/home/akkie100/fintwit-bot/src/util/tweet_embed.py", line 331, in add_financials
await tweet_overview.overview(category, base_symbols, prediction)
File "/home/akkie100/fintwit-bot/src/cogs/loops/overview.py", line 59, in overview
await self.make_overview(category, tickers, sentiment)
File "/home/akkie100/fintwit-bot/src/cogs/loops/overview.py", line 181, in make_overview
await self.crypto_channel.purge(limit=1)
File "/home/akkie100/.local/lib/python3.9/site-packages/discord/channel.py", line 456, in purge
return await discord.abc._purge_messages_helper(
File "/home/akkie100/.local/lib/python3.9/site-packages/discord/abc.py", line 176, in _purge_messages_helper
await ret[-1].delete(reason=reason)
File "/home/akkie100/.local/lib/python3.9/site-packages/discord/message.py", line 1365, in delete
await del_func
File "/home/akkie100/.local/lib/python3.9/site-packages/discord/http.py", line 371, in request
raise DiscordServerError(response, data)
discord.errors.DiscordServerError: 503 Service Unavailable (error code: 0): upstream connect error or disconnect/reset before headers. reset reason: connection termination
Ooh loops don't have error handling
I already had that once
like if a loop crashes once it will never re-run
What did you do to fix it?
unless you restart
show me your /home/akkie100/fintwit-bot/src/cogs/loops/overview.py
well in that case it is probably best to put a try except around that because i have no idea if loop / task errors have an event / listener
Yeah I think I might if it happens more often, I just added a /restart command so I can restart it if i cant access the terminal
you cant restart your bot with a command if it isnt running lol
Hmm, I wonder how critical the error was now
import logging
...
def __init__(...):
...
self.global_overview_loop.start()
...
@loop(minutes=5)
async def global_overview_loop(self):
try:
await self.global_overview()
except Exception as e:
logging.error(e) # this is an example, add your own error handling here
async def global_overview(self):
if util.vars.tweets_db.empty:
return
# rest of the code
i find it very odd that it complains about line 144 when that is just else:
it isn't else it is get_latest_tweet
"line 144"
Yeah the error is from some time ago, I was working through my issues so the current code is probably already a bit different then at the time I got that error
Make something like this for every loop. Or maybe make your own decorator that does that if you have many loops
Thanks, that's a good idea!
Loop.error this could help too
I didn't know that's an option, I was using it for my commands but somehow didn't think of using it for loops
I just found it now when skimming the docs XD
Haha glad i'm not the only one that didn't know if its existence
I wonder if it restrts the task... I will check too
So i'm thinking if I add this:
@global_overview.error
async def overview_error(self, error: Exception):
logging.error(f"Error in global_overview loop: {error}")
# TODO: add more code
It should be able to handle errors better.
# TODO: add more code
looooool
haha before anyone says that more code should be added
Thanks again for the help, now I have an idea how to handle this
Is it possible to get guilds of a certain shard like in bot.guilds?
no but you can do for guild in self.bot.guilds if guild.shard_id == ...
.shards returns a map of shard_id to guilds
How can i create a event that is trigger only when the cog is loaded
kinda like the cog_onload but for the loading
i'll make a tag for it, but here's an example of custom events #998272089343668364 message
it might NOT work in init during load, since the listener might not exist at that point in time
hmm
yeah true
eh give it a try i guess
i was personally thinking you just dispatch it after using load_extension
(maybe override it to super().load_extension -> dispatch with get_cog)
yep it does not work
what i will do ig is since i have many cog and a func update it will first load everything and then dispach it for all of them
but you only need a single dispatch
so i guess it's back to your own function
yep i added it in my setup hook
that is trigger when i update my bot
and it works
thanks nelo
allgood
how to have the "status" with the phone icon?
It's kind of a work to do it
https://stackoverflow.com/questions/70903401/how-do-i-get-mobile-status-for-discord-bot-by-directly-modifying-identify-packet
TLDR not worth
and isn't it technically against tos
But breaking the rules is fun
okay, then i will not do it
Lmao watch me host my bot on an android 4.3 tablet
Because then technically speaking my bot is on mobile
Not yet out
I just tested this but it seems that the whole loop will be killed after raising an error once
So this is probably the best approach if the loop should try again later
Did you have the same results?
That would probably be the best idea, because besides, depending on what error you catch, you might want to have a different error handling there.
I did not test yet
@sage tendon do you think it would make sense to open an issue about loops not restarting if they crash?
maybe a decorator
Yeah you could match them again in the error decorator, but maybe a fatal crash should cause different behavior then a wrong http response or so
bruh fr ?
there is a pr: https://github.com/Pycord-Development/pycord/pull/2501
Well you can't expect everything to comme immediately. In any case, you can still upload emojis in the ddev portal and use them in your bot's messages witht heir id
once it is in master, you can use the github version of you want
nah I want to copy emoji of other server and create it in the guild but it didn't work
wth did you though ?
IK I READ this
wait 'm explaining to you
it isn't ctx. it is ``ctx.guild.`
ctx is an application context
you need to use the guild object
imo it's the thing image
Can you send me then entire code where you take the emoji from the first guild and add it to the other?
wanna see my code to check or no ?
look dm
done
look on ur dm
I made a decorator for it so I can use it on all my loops:
from functools import wraps
def handle_errors(func):
@wraps(func)
async def wrapper(*args, **kwargs):
try:
return await func(*args, **kwargs)
except Exception as e:
logger.error(f"Error in {func.__name__}", exc_info=e)
return wrapper
Still need to add more exceptions but it works
nice
You have a decorator @loop.error and inside of it you can add ur custom logic
So for example log the error and then start the loop again
yeah but it's wierd to make the loop crash if any error happens
Its logical
Since it’s a loop
Imagine a while or a for in that continue Even with error
It would be a giant mess
@digital bear
I know but my loops rarely crash and if they do i don't really care if they continue, they are repeating like every 4 hours or so
If they crash it's either Discord's servers fault or the website that i'm scraping lol
Depending on the error I could always stop the loop manually or restart it
I'll pr some documentation that says that bc the first time I did it wasn't intuitive at all.
Yeah maybe, but that how I think because for me this loop is like a while or a for in so it should have the same behavior. Maybe other will have different option ion
Maybe even add an arg restart after error
Yeah
Is there just buttons and select menus as ui elements?
modals
yeah ok but apart from that it's it
yea
in this thing
if TYPE_CHECKING:
from ..emoji import Emoji
from .view import View
B = TypeVar("B", bound="Button")
V = TypeVar("V", bound="View", covariant=True)
class Button(Item[V]):
"""Represents a UI button.
there is this B and V typevars. How do I use this thing if I subclass button? And what is it for exactly?
Hello, I would like to implement some functionality, but I'm not quite sure how to approach it
What I want is this: A message is sent with the bot's reaction. I then would want to wait for x time (say 20 minutes), and listen for if a certain user reacts to this message, if this time runs out and the user has not reacted to the message, I want to do some other action.
Can anyone help me implement this logic?
bot.wait_for
oh nvm im slow
You can use the wait_for. Basically ou give it an event, a timeout and a check to see if it is what you want, and it will raise a timeout error when it times out and return the reaction or whatever that returns if it finds it with the check
@sage tendon An idea on this? I'ts too complex for me.
Yeah, sorry, just was reading the docs, thanks a lot, this is what i was looking for
no problem :)
go away with typevars, thats one part of python i find extremely ugly lmao
they got better in py 3.12 cuz now they have their own syntax but I don't want my lib to be 3.12 only lol
this is very basic but say I call this: ```py
async def foo(x):
y: int = await something_that_takes_a_while(x)
print(y)
print("Hello there")
would the output be: ```bash
Hello There
<some number>
or bash <some number> Hello there
aka, does an await call stop execution?
If it does stop execution, how do you have something running in the background in py-cord? Do you have to use multiprocessing / threading?
async isnt threading
if you ran that function in a thread, it'd print like the top example (most likely, depends on the timing)
but normal async doesnt change the order in which code is executed
await means "wait here until this function finishes, and in the meantime, free the thread to do other stuff" e.g. handle other commands
also your example is kinda wrong, for your example to work properly you'd have to print inside of the async function, but i get what you mean lol
And sidenote cause i noticed you're typehinting the variable definition, you don't have to do that if the return type of the function you're calling is a single type (multiple work too, but is ambiguous)
pycord suddently broke
system, node, release, version, machine = infos = os.uname()
^^^^^^^^
AttributeError: module 'os' has no attribute 'uname'. Did you mean: 'name'?
?
that has absolutely nothing to do with pycord
i have no idea what happend it was running now it isn', but probably has nothing to do with pycord
you are right
bro wtf
AttributeError: partially initialized module 'discord' has no attribute 'ui' (most likely due to a circular import)
Can you show the pip list pls
╭───────────────────────┬─────────┬────────────────────────────────────────────────────────────╮
│ name │ version │ location │
├───────────────────────┼─────────┼────────────────────────────────────────────────────────────┤
│ aiohappyeyeballs │ 2.3.4 │ │
│ aiohttp │ 3.10.0 │ │
│ aiosignal │ 1.3.1 │ │
│ attrs │ 23.2.0 │ │
│ basedpyright │ 1.15.1 │ │
│ frozenlist │ 1.4.1 │ │
│ idna │ 3.7 │ │
│ multidict │ 6.0.5 │ │
│ nodejs-wheel-binaries │ 20.16.0 │ │
│ py-cord │ 2.6.0 │ │
│ pycord-reactive-views │ 0.1.0 │ -e C:\Users\Jérémie\Documents\GitHub\pycord-reactive-views │
│ python-dotenv │ 1.0.1 │ │
│ ruff │ 0.5.6 │ │
│ yarl │ 1.9.4 │ │
╰───────────────────────┴─────────┴────────────────────────────────────────────────────────────╯
whatever that view package is, that's likely it
no that's myself
it's the project I' making and I rolled git back to when it worked and nothing changed
reinstall pycord
I did that like 4 times now
can't view this rn, mobile
AttributeError: partially initialized module 'socket' has no attribute '_GLOBAL_DEFAULT_TIMEOUT' (most likely due to a circular import)
lol
already done that
then give up
because that's crazy
try 3.11
yeah was about to do that
but I don't see why since 3.12 always worked since today now...
lol
TypeError: _patch_task.<locals>.task_new_init() got an unexpected keyword argument 'eager_start'
python-BaseException
sys:1: RuntimeWarning: coroutine 'ClientRequest.write_bytes' was never awaited
time for a new project
good luck debugging why it doesn't work on 3.12
?rtfm discord.commands.SlashCommandGroup
you can use the doc search yknow
meme
go on
SO basically I have a folder called examples
And what I do is that I create the lib and write the examples
and run the examples to see if it works
I added a new example
and the name of the file broke everything
I called my example select.py
wow
and for some reason python decide that that should be used instead of discord's own select.py file
yeah
what would be a "good" way to get a category?
get_channel
how to put the time in embed footer? like that but "Today at [...]"
set embed.timestamp to a datetime object
(if you want the current time discord.utils.utcnow() is convenient, but it can be any time you want)
So I am trying to remake my bot in pycord. The commands work, but I keep getting an error message that the application did not respond. Never used pycord b4 so all help is appreciated! ```import random
import discord
from discord.ext.commands import Bot
from discord.ext import commands
bot = commands.Bot()
@bot.slash_command(name='motivationalunicorn',
description="Writing advice, prompts, and motivation!",
brief="A unicorn that helps you navigate through the journey of writing.")
async def motivational_unicorn(ctx):
possible_responses = [
'Virtual huggie!',
'Who is the best? You are!',
'YOU CAN DO IT!',
'You will never know if you do not try',
'You have come so far!',
'You got this!',
'Hang in there!',
'You are unstoppable!',
'You will take the world by storm!',
'I am so proud of you!',
'You are creating something out of nothing and that is a huge deal!',
'No matter what happens, you started something big and no one can take that away!',
'Do not give up!'
]
await ctx.respond(random.choice(possible_responses))
Show the full traceback
i dont think brief does anything for slash commands btw
This is what the error looks like. I don't see anything in my terminal.
What happens if you change commands.Bot to discord.Bot? It should still behave the same but better double checking.
.tag client
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)
that should only happen if you use ctx.channel.send
Are you sure you're using respond and not send?
Maybe check that dpy isn't still installed
that shouldnt happen tho lol
what part?
it not working lol
can you show your pip list
... not work lol, thats whats wrong
it should respond like normal
with commands.Bot as well
Tf
Hey there, im trying to make an help command where i can switch between command categories with a dropdown menu. Im trying to use paginator but im at a dead point i don't know how to switch to the new embed when a person select the category from the dropdown menu.
This is my command:
https://paste.pythondiscord.com/2ZHQ
This is my dropdown callback in another file:
https://paste.pythondiscord.com/NVIA
Or do i need to use page groups and how? there are no examples.
I was about to mention page groups
pages in PageGroup is your list of embeds for each command (I assume each command has its own embed)
And then you care about label and description which is what the Dropdown will use later
Has anyone successfully webhook.edit_message'd an image that has alt text/description? I can add an image, but it doesn't seem like the description gets submitted (can move to a thread if that's preferred).
I have to create a page group for each category right?
I've tried
files=[discord.File(description="Whatever", ...)]
chunked_messages[idx] = await webhook.edit_message(
message_id=chunked_messages[idx].id,
content=content,
thread=thread,
files=files,
)
as well as stuff like
chunked_messages[idx].attachments[0].description="Whatever"
attachments=[chunked_messages[idx].attachments[0]]
chunked_messages[idx] = await webhook.edit_message(
message_id=chunked_messages[idx].id,
content=content,
thread=thread,
attachments=attachments,
)
``` (since I'd expect that to `PATCH` the existing attachment to add a description field, please assume that content and thread are sane non-null values)
of course
you can remove the attachment and add a new one. I think this is the intended way
That makes sense, but I'm also failing to add a fresh attachment with a description property (first example)
something like this perhaps
await webhook.edit_message(
message_id=chunked_messages[idx].id,
content=content,
thread=thread,
files=files,
attachments=[]
)
I'm making files via something like
discord.File(buffer, filename=name, description=prompt[:1024])
``` where buffer is a `io.BytesIO` off of an `aiohttp` request, and I'm sure that `prompt` is a non-zero length string because I just used it for generating the image.
I haven't really worked with attachments on webhooks, but maybe it requires two separate edits: one to remove and another to add?
Sorry, revising my kinda n00b question here - I'm sending a webhook with no attachments initially, then retrieving an image in the background and updating with a new attachment. I have a good image description and want to attach it as alt text, but I don't understand how the web request is being generated to see if it's being sent to Discord (Discord bug) or if it's not (PyCord bug). Could I get a pointer to how editing a WebhookMessage creates a PATCH request with a body?
from what i can tell either:
- we didn't implement certain attachment compatibility in webhooks
- discord doesn't allow it (which i find unlikely?)
@sage tendon Sorry, where's the exact link to user apps documentation?
@bot.user_command(
name="test",
integration_types={
discord.IntegrationType.guild_install,
discord.IntegrationType.user_install,
},
)```
like that?
Here's the slash users example.
ok
Yeah
Each page group would be your category
ok yeah, identified
alright i got it finally
thank you
fixed with the code changes in https://github.com/Pycord-Development/pycord/pull/2513
Amazing! Thank you so much, I'll test now.
hmmmmm, behaviour is still inconsistent with normal message edits...
but that's more of a cache thing, not something we can deal with
not without restructuring how webhook messages work anyway
Patch seems to work for my use case. Cheers, appreciate the help, and now I know more about where this gets serialized to debug in future.
why do i get the feeling that my bot does the on_ready event whenever it resumes its session
because the event does fire
i thought that was on_resumed?
the session may not necessarily be resumed
like none
so it's always on discord's end if it doesn't just resume normally?
not always
so when would it my fault if that happens
@shell radish Sorry if I'm annoying, what is the limit of characters a bot can send in a message? Is it the same as the normal user? (a user who does not have nitro)
2000 in content
on the top of my head, if your computer gets shut down
ok ty!
In Py-Cord, how do I have a function, take for instance: ```py
async def foo(x):
sleep(10)
print(10)
run in the background, say in exec, something like this?:```py
<call foo>
print(20)
output:
20
10
Do you use multiprocessing / threading or can you do it in py-cord differently
I would like to use wait_for in this background process, that's why
should I be using asyncio.create_task?
So what you are doing is you want to run some blocking code, and inside of that code use wait_for
May I know exactly what this blocking code is?
sorry, what does the term blocking code mean, exactly?
From the Py-Cord Docs: ```py
@client.event
async def on_message(message):
if message.content.startswith('$thumb'):
channel = message.channel
await channel.send('Send me that 👍 reaction, mate')
def check(reaction, user):
return user == message.author and str(reaction.emoji) == '👍'
try:
reaction, user = await client.wait_for('reaction_add', timeout=60.0, check=check)
except asyncio.TimeoutError:
await channel.send('👎')
else:
await channel.send('👍')
That's essentially *exactly* what I want to do, except, its not in `on_message` and there's more logic I want to run after `wait_for` if you get what I mean
cuz my timeout=1200
yo to DM a user is it just user.send() or do I have to call user.create_dm() first?
U can do user.send it will create a dm before automatically
oh ok, thank you.
I will pose my original question better:
I would like to achieve the following: Give a user 20 minutes to react with 👍 to a specific message, but handle this in the background, so that I can handle other logic in the same function. I think discord.Bot.wait_for is exactly what I'm looking for, I just need a way to handle this (dummy) code:```py
def check(reaction, user):
return user == message.author and str(reaction.emoji) == '👍'
try:
reaction, user = await client.wait_for('reaction_add', timeout=60.0, check=check)
except asyncio.TimeoutError:
await channel.send('👎')
else:
await channel.send('👍')
in the background
Pycord uses asynchronous code for that. So you just need to put await before wait_for
And that's it so your current code is good
And yeah you would use create task for running multiple things
But what I would do is put the other logic in the background, not the wait_for
In the init
self.tasks: set[asyncio.Task] = set()
In your thing
task = asyncio.create_task(YOUR COUROUTINE WITHOUT AWAIT HERE)
self.tasks.add(task)
task.add_done_callback(tasks.discard)
so I use asyncio.create_task(some function), and in some function i have:
async def some_function():
def check(reaction, user):
return user == message.author and str(reaction.emoji) == '👍'
try:
reaction, user = await client.wait_for('reaction_add', timeout=60.0, check=check)
except asyncio.TimeoutError:
await channel.send('👎')
else:
await channel.send('👍')
Yeah plus that logic I sent you with self.tasks to store running tasks.
Just that some function there doesn't have access to message and channel so you should pass that in as parameters
why do I need that?
I had issues when doing without, and besides, it is a best practice
Got it
Tysm
np
is it possible to load a new cogs file and register the cog's slash commands?
without having to restart the bot
If i use self.bot.load_extension it loads the cog but doesnt register the slash command inside the file
i dont think you can
you can
just add await bot.sync_cmmands
ah yea
to sync command
Small problem... I hope
I’m creating my own bot but when I have to test it, it doesn’t let me show its commands in the menu. It only goes if I put for exemple "!"
I’m just starting out in programming.
if you made them prefix commands, theyll of course just work as prefix commands
show your code
import discord
from discord.ext import commands
from dotenv import load_dotenv
from discord import app_commands
import os
# Carica il token dal file .env
load_dotenv('.env')
TOKEN = os.environ['TOKEN']
class Bot(commands.Bot):
def __init__(self):
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
super().__init__(command_prefix=None, intents=intents) # Assicurati che command_prefix sia None
async def on_ready(self):
print('Il bot è online e pronto a ricevere comandi!')
async def setup_hook(self):
# Carica i vari cogs per i comandi
await self.load_extension('cogs.pex_depex')
await self.load_extension('cogs.staff_break')
await self.load_extension('cogs.ping')
await self.load_extension('cogs.counting')
await self.load_extension('cogs.exemple')
print("Comandi caricati")
bot = Bot()
# Evita di utilizzare process_commands in quanto non hai prefisso
bot.run(TOKEN)
put loading the cooks somewhere above bot.run