#discord-bots
1 messages ยท Page 420 of 1
Must aswell file a complaint of me calling you slow too.
Dude
you are here giving out "advices" and you cannot understand yourself simple common names.
I had expectations from a developer like you to understand the concept of a PRODUCTION branch
You keep saying I don't understand this and you're refusing to identify what it is you think I don't understand
Cause you are not understanding ๐
I told you I know what production means and you're insisting I don't
That's the wrose, cause you're not identifying it yourself, i bet dozed bucks rn there is people laughing at this.
Me saying I don't care what you call your branches is not the same as me saying I don't understand this word you're using
And automatic syncing effects this how?
It's not related
That was supposed to be a joke...
I know
But y'all started a new convo completely out of that context
What can I say..
What if a user, on production or not, does many adjustments to a certain thing they're working on, and every few changes they restart the bot? Now you got the bot sending the PUT /commands request way too often - even if it doesn't actually hit the rate limit, you just spam an endpoint.
And personally I don't even think this is an edge case.
I'm actually working on something myself to write automated acceptance tests against discord bots/slash commands. Generally I don't think any better is possible in discord bot development publicly without manual testing, so it's not like other types of testing people can reasonably do but just ignore.
Sounds amazing, curious how that turns out.
If you are restarting the bot you likely expect a change though. There is no point to restart if you are planning on immediately changing something without using it. And yes it is 1 extra request for global commands and 1 extra request per guild with guild commands in the worst case scenario. It is only a few requests in comparison to bot start up
Huh? I was continuing what he said, i cannot take advices from a person that cannot understand what they're saying.
Proved since he wasn't able to understand his own words.
Holy production, production is production, not a pickle
๐ฅ
The only thing syncing your commands does is updating command attributes. It has nothing to do with changes I make in the code that are besides that. and I often find myself restarting very often especially when I'm making a design prototype with components, for example. But with other things too
Getting offended that badly upon being called slow, based on they're saying, it's just crazier.
A smart automatic syncing system only syncs commands that have changes to their definition
"That badly" means "I don't like you insulting me"
Okay dude
Then re-read your words multiple times before saying something, and understand common arguments / words.
It's going fine so far. I'm between a bunch of things at the moment. I got serious about it when I saw someone else already did similar (not including slash commands) with this https://github.com/CraftSpider/dpytest and when I tried it it no longer worked. But I've gone over the code used pieces of it. The basic idea of both is just to take the discord client instance, replace the HTTP client (it has one with very specific methods that aren't specific to http) with a custom one, and to inject messages into where it processes them from. So it'll build a backend in memory of guilds, add messages when http calls go out, and pass the json data for them to where it would normally be parsed after reading it off a websocket. I'm in the very early stages and probably not explaining it well off the top of my head. But it's real event data back to the client with a fake backend. All in memory.
The use case right now is you can make a function to setup your bot instance, add your cogs, message handlers, etc, and write a test for what you want, like test_should_get_level_up_reply_on_first_message and create a guild add a user to it add the bot to it, have the user say something and see if the bot replies, while hiding all of the implementation details of the bot away, except for maybe database connection details.
A package that assists in writing tests for discord.py - CraftSpider/dpytest
I will be nice, but i have a limit.
That's so well explained, much appreciated, if you remember me let me know once this has a release, curious to see.
Ideally a testing suite would use mocking, but I don't think anyone has bothered fully mocking out the discord api given there really aren't any commercial use cases to justify that degree of investment
Mocking doesn't allow you to specify the what of your application and avoid the how though. You can't say your bot is fit for release anyway if you don't test it in a production like environment, as a philosophy to me with just the features I use it's worth the investment and the discord API is well documented and the discord library as well. I practically have a little mini discord domain model entirely in memory at the moment with just the parts I'm using of guilds, messages, users, and something to fire off events on any changes and send details to the client with default values for anything not used.
I don't think anyone seriously suggests that automated tests completely negate the need for manual checks
Just that mocking is probably the best tool we have for the automated side when you're dealing with an external api
What you're doing is automating testing on your bot with demo users?
Firing events to the client with fake user data setup for each test, with a backend to match (In memory for now)
Thought about the concept of this in the past but just turned it down in my head as it's too much work when I can usually test it with my user or demo variables
It becomes easy once you do it. If you can manually test you can write a good acceptance test if there is enough in place. It becomes easy and turns into stuff like "make guild" "make user" "add user to server", "send message as user" "wait for message back" if you want to go know your bot will reply to someone right you got to basically do that anyway and when you write tests a lot it becomes fast. (In general)
Realistically I don't need to be afraid of my code failing in some various ways depending on the user or whatever object.
Your project has purpose but Idk how necessary it is

When I manually test, it's a matter of a few minutes or less. I don't do long term testing
Also some things genuinely need zero testing
My goal is to be able to change large amounts of code without worrying about any of it breaking or changing. I agree that you can get away with no testing, I imagine by limiting what you change, but it's not how I prefer to approach it. i would manually test of course to see if it looked right but I'd personally make progress faster with automated tests.
Hmm, maybe that's just besides my use cases. You do deserve props tho
๐
At some point it starts saying the same things over and over again
The dpytest library deserves it really and anyone before me who emphasized acceptance testing before it for me to even be doing it. I'm literally using pieces of existing code that still work to get started.

Randomness in general I've seen pick the same things a lot for this kind of stuff.
It's actually quite simple to interact with
Ohhh, it's Gemini saying the same thing over and over again, I've noticed that.
The instructions work quite well.
Made it talk to itself lol
Bru
Yea it works
Sure hope that's the paid version of Gemini
Question regarding discord.py:
I have a GroupCog. How do I add it as a child of an app_commands.Group
I already know the deal with the data don't worry lol
The design of groupcog assumes the groupcog is the top level
aw man
That doesn't really tell us if you're using the paid version does it
I agree that mocking is incredibly valuable. I've actually used it on important code when I was foregoing end to end testing. But there's also the setup code necessary to make sure everything works. (I can't think of a good comparison with discord so I'm gonna keep this more general) If I have a class that needs the current weather it shouldn't care where the weather comes from and I should be able to test that It works in isolation, and mock it out, but if it is supposed to get it from weather.com I gotta set it up with the right implementation for real, which I also have to test against a url to a real page to know if it will work (e.g. with wiremock), and when I do all of this I don't know that when input comes in to my application the right stuff will even be called. Mocking also doesn't necessarily help me when I do something and an event should be fired off, it's just not enough. My application can still break. Also I'm not saying automated testing should stop manual checks I'm just saying I can see why people might be so loose here.
There are always caveats when you consider this space is like 99.9% hobbyists and there's really no money involved
Just put everything into the class?
class G1(Group):
...
class G2(Group): ...```
You mean to say like this?
class Parent(Group):
middle = Group(....)
@middle.command()
async def ....
Ah so middle shall not be subclass 
You could stitch this together if you really wanted but I suggest this way
!d discord.app_commands.Group.add_command
add_command(command, /, *, override=False)```
Adds a command or group to this groupโs internal list of commands.
is the alternative
I'm not sure how much I intend with this publicly. It's really just an experiment right now, I do have a simple bot I have to make and I'm not making it without. I'll definitely make public whatever code I have , say something in here and answer any questions but beyond that no promises.
You could also do this with a separate subclassing for middle too and just
class Parent(Group):
middle = Middle()
class Middle(Group):
@command()
...
But that feels unnecessarily verbose
def commands_payload_from_tree(tree: app_commands.CommandTree, /, walk: bool = True):
"""Returns a list of all commands as dicts, used for TopGG's commands feature."""
func = tree.walk_commands if walk else tree.get_commands
return json.dumps([cmd.to_dict(tree=tree) for cmd in func()], indent=4)```
Something I made for <https://top.gg/bot/bot_id/dashboard/commands>
Are you familiar how to remove top.gg default gradient?
Show me a screenshot of what you mean
I've had a code that was removing it a while back, while discussing with mimu bot developers, they've helped me out.
So you know top.gg has a default gradient appearing onto the pages, which is customizable, default red.
Like a red glow top page.
What i mean is removing the gradient from your own bot's page.
You know you can edit the whole page with css, right?
Yes, mimu owners gave me a code to remove gradient, but it doesn't work anymore, i haven't been updating my top.gg
I can quickly figure it out with inspect, wait
It just looks lame when you make your own page fully built with css, and custom colors.
having the default top.gg gradient
let's say i'll follow my style, having black white and gray shades
that gradient just makes it look terrible
๐คฃ
I just had a snippet that worked like a year ago
If you find out let me know, that's a huge improvement
link the typing animation at the top is cool
that is indeed
anyway i dont want this to look like self promo so ill just delete
I don't think it does, u good.
see, that top red gradient
looks horrible if you customize your whole page.
"flashy gradient" ๐คฃ
Im figuring it out atm
The css?
Yeh, wait ill show u
body > div[class^="sc-"],
body > div[class*="sc-"] {
background: none !important;
background-image: none !important;
box-shadow: none !important;
}
this removes any gradient backgrounds from top gg containers
I found it lul
body > div > svg,
body > div[class^="sc-"] > svg,
body > div[class*="sc-"] > svg {
display: none !important;
}
and this hides top.gg default color at the top
Ah, "any". I found the element for the one at the top
try them out in ur current css
on the bot
shit finna look so much smoother, that gradient is terrible placed on bot's pages
I js had a quick chat like a year ago with a mimu dev, they helped me, but probably don't know about my existance ๐
There's actually no other gradients
this shit like a year old man
i js received it ๐
but try it up, it's actually cool
.w-full.h-screen.inset-0.-z-10.absolute {
background: none !important;
}```
Is what I came up with, does the job
Go ahead (:
I mean yeah
But if yours removes the gradient, it's savage
Yuh
You can now put any color there to change the whole background
Or if you want a different-color gradient, I can do that too
i love this anyone wanne rate my dc bot script
Yeah, im familiar, you can change the whole page, even texting, it can be savage.
Go ahead
Actually not the whole page's background. That's a different element. It's only a section at the top.
I just discontinued my bot, and im creating a new v2, it will be absolute savage can't lie, i'll show you something in a bit.
One mistake there currently is, im "uploading" images, instead of using urls, kind of delains my containers.
Just send snippets code.
wahts that gng
It might suit some bots tho
But some nah
Let's gossip a bit
what you think about carl bot developers?
me6 is ass
idk but carl is usefull sometimes
x = 1
y = 2
if x == y:
print("will this print (no)")
as in posting your codes like this
ahhh ok how i do it like u like the box thing
@app_commands.describe(member="The member to ban", reason="Reason for the ban")
@app_commands.check(rollen_check)
async def ban(interaction: discord.Interaction, member: discord.Member, reason: str = "No reason provided"):
if member == interaction.user:
await interaction.response.send_message("You cannot ban yourself.", ephemeral=True)
return
if member == interaction.guild.me:
await interaction.response.send_message("I cannot ban myself.", ephemeral=True)
return
if interaction.user.top_role <= member.top_role:
await interaction.response.send_message("You cannot ban a member with an equal or higher role.", ephemeral=True)
return
try:
await member.ban(reason=reason)
await interaction.response.send_message(f"Member {member} has been banned.\nReason: {reason}")
except discord.Forbidden:
await interaction.response.send_message("I lack the permissions to ban this member.", ephemeral=True)
except discord.HTTPException:
await interaction.response.send_message("Failed to ban the member due to an unexpected error.", ephemeral=True)
@ban.error
async def ban_error(interaction: discord.Interaction, error):
if isinstance(error, app_commands.errors.CheckFailure):
await interaction.response.send_message("You do not have the required role to use this command.", ephemeral=True)
else:
await interaction.response.send_message("An unexpected error occurred.", ephemeral=True)```
this iss jst for ban
pffffff
You don't really need an application to ban someone from a server when Discord already gives you that ability
Why do people still do @cmd.error that's something inside of 2019 youtube tutorials
tbh my code looks like shit
i just did that bc i wanted to
Understandable
Idk them
Honestly, there are various discussions, most of coms, that are huge, and reason why bleed bot made hella bread from discord, it's cause all of these features, are implemented onto bots.
Half of the moderation features are now covered by the Discord client and are unnecessary on bots
I'd be careful using that word, not even sure what that means in this context...
this was also my first dc bot so i used chatgpt to help me learn the module and waht i can do with it
Yeah edit that out
So, there is soomething i want to tell you.
waht is it
chatgpt codes based on your prompt, in can be good, it can be bad.
You need to have your own experience into coding, to be using chatgpt properly.
chatgpt is frying people's brain thinking they code.
i didnt just copy and paste i used it to explain it to me
It can be good if you have experience, and you already know the structure in your head, it can be a lot more productive.
ik the strucutures
And im not talking about a prompt e.g "Create me a ban command"
I started with chatgpt, 2 years ago xD
I remember telling it "make me a command that ..."
Will not shame people for doing that. But eventually you should get good enough to grow out of that "phase"
๐ญ
wild
that's exactly why beginners into coding world should avoid using chatgpt
depends how they use it
and not just chatgpt, but any AI models
wdym with features
If you have your own experience, and you know structure, and if you can atleast define 3 feature of python, it could work ๐คฃ
Code completions can actually help people. But there's a difference
I second this
saves me a lot of manual labour
e.g dataclasses
gng ik how to do stuff but idk all the words im not that good in englisch
I got to a point when I often turn off my code completions when I genuinely want to enjoy a code block that I already know how to make xDxD
__slots__ another beautiful python feature
Prove it to me
ye nah idk that
I doubt that
but i can made scripts bymyself
Why? You don't like saving your projects memory?
Studies prove it can save 30-40%
Don't glaze
It's good!
Faiiir
Ok ok, what about __all__, have you been using it?
not me having that onto antinukes
I made a wrapper that I'm very proud of
it's just
Is it public?
Holy docstring
lovely
Or did you make it for your personal use
I keep saying I'll put it on my github but idk
Originally I made a dumb code for personal usage, this one shall be public ig
f it ill put it right now
Awesome
exactly, so chatgpt is not helping you a lot.
Is it "Pythonic" to use underscore in module name?
For now I'll put it on my Github as dumb code, not planning to make it an actual module rn
check pep 8
Yo
Gurt

I'm new, and looking forward to knowing the way things are done here
Into python, or discord bot's specifically?
helloworld("print)
I'm new to both of them
!resources
The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.
And the ui of discord is strange to me
https://github.com/TheServerit/webhook_events
Tried my best with README.md ๐๐ป
If I see that people like it (what's the chance...), I'll make it pipable (:
good work!
i think they will like it
Not using them personally (I can't, ineligible country), but for my wrapper
luckly i can, and i use them, but they're shit
Do you mean something like this?
where is setup_hook in there?
I have no idea what that is
This?
Cuz this is the only info on like 6 websites I just tried to look through
yeah, it's a method you can implement in a bot subclass
yeah i havent messed with subclassing in a way I understand it so im just not gonna risk screwing up my cogs for some errors im already raising through try and except
subclassing (OOP) is an extremely fundamental concept in python generally and these libraries specifically
I never learned OOP i just dove straight in
You are doing yourself a massive disservice in avoiding it
I can look at a tutorial but I doubt I'll understand it
I learned discord.py just by memorizing patterns of code and adjusting it to what I need all your terminology is just another language to me
If I tell you that is not an effective way of gaining skill or learning, would you listen?
If you don't share common terminology or fundamental concepts, people aren't going to be able to help you. You're just asking people to write code for you at that point
probably but I got my bot working with systems I wanted
I got a lot of stuff to work
json as a db ๐คจ
With that attitude sure
I mean ig you learn file handling all that, but just so you know it's not a db u want in the future
when u learn SQL you'll really see the diff
It's not like I just looked at it and didn't try, I spent a few hours looking at tutorials, following and trying to understand but eh I couldnt get it to work nor understand it
What precisely do you mean by "tutorials"
YouTube is made up shit
By mouth breathers in their basement trying to get Internet attention
Terrible educational resource
dont talk about brocode like that, he taught me some coding stuff
And how do you know that stuff is accurate, complete, or best practice?
You think they work
meh I just learned what subclasses are but I dont see its usecase
It's a way of taking an existing class and either overriding parts of it or adding on additional things
yeah idk maybe its cuz im not in a developer mindset but I dont see the usecase for that
You have one right in front of you
You have an existing class (Bot) and you want everything it does normally except for overriding one thing (setup_hook)
btw quick question does anyone know why my discord.CustomActivity works in VSC but when I move it to my server it just doesnt?
Im using a task.loop to achieve it with an array of statuses
status = discord.Status.idle
@bot.event
async def on_ready():
update_status.start()
try:
synced = await bot.tree.sync()
print(f"Synced {len(synced)} command(s)")
for s in synced:
print(f"โ
{s}")
except Exception as e:
print(f"Error syncing commands: {e}")
@tasks.loop(seconds=30)
async def update_status():
statuses = [
discord.CustomActivity(name='Cats > People'),
]
current = update_status.current_loop % len(statuses)
await bot.change_presence(activity=statuses[current], status=status)
wait isn't persistent buttons is a subclass of the command?
class persistant_buttons(commands.Cog)
def __init__(self, bot):
self.bot = bot
async def function_name(self):
self.bot.add_view(other_class_name())
```
await bot.cog_add(persistant_buttons(bot))
class A:
...
class B(A):
...
B is a subclass of A
as of now I don't think there's a way to check the total size of the embed in chars
lemme see if I can write a func
There's no builtin but it's easy to make
def find_total_chars(embeds: list[discord.Embed]) -> int:
total_chars = 0
for embed in embeds:
if embed.title:
total_chars+= len(embed.title)
if embed.description:
total_chars+= len(embed.description)
if embed.fields:
for field in embed.fields:
if field.name:
total_chars+= len(field.name)
if field.value:
total_chars+= len(field.value)
if embed.author and embed.author.name:
total_chars+= len(embed.author.name)
if embed.footer and embed.footer.text:
total_chars+= len(embed.footer.text)
return total_chars
```Should work, and I believe values can be an empty string here? so Im using a falsey check instead of a `is None` check
well techinically using is a is None check would work and the len() of emtpty string would return 0 either ways
Aw man
property fields```
Returns a [`list`](https://docs.python.org/3/library/stdtypes.html#list) of `EmbedProxy` denoting the field contents.
See [`add_field()`](https://discordpy.readthedocs.io/en/stable/api.html#discord.Embed.add_field) for possible values you can access.
If the attribute has no value then `None` is returned.
oh so it returns None instead of an empty string, interesting
wait nvm that's right
Falsy checks cover None anyway
ye
np!
i doubt danny would implement a utils helper func for this since it's pretty simple
lemme see
wait wait
LMAO IM STUPID
just do len(your_embed)
it will return the total chars
yes
Yep
Yea they got that and more operations for embed, like eq and bool
IIrc bool is True when embed is not empty
!d discord.ui.LayoutView.content_length
content_length()```
[`int`](https://docs.python.org/3/library/functions.html#int): Returns the total length of all text content in the viewโs items.
A view is allowed to have a maximum of 4000 display characters across all its items.
Hey, you shouldn't run anything on_ready
That event can fire multiple times.
Since you were so smart yesterday, create your own safe_message while making an enum with maximum discord's limit.
And you check the same_message with the enum created with maximum discord's limit for messages.
wha
?
^
Are you reading what i've said?
He can simply make a enum class containing the max characters for embed / message
what why do u need an enum
a class that could potetially be re-used in a longer term.
just use it as a constant
To give it the max len of characters of message / embed.
If you think that's best practice, keep on doing so!
also what safe_message
cause this definitely ain't
seems like u aren't reading what I said ๐ญ
THIS MESSAGE
THIS MESSAGE
A safe message function can be various, but in this case he can make it in order to verify the message content to max characters.
What you've shown him it's such a bad practice code.
Imagine running that every single time into your code.
terrible choice, if you help people, atleast tell them the right ways of doing a thing.
what's wrong with len(embed)
And if you cannot understand the logic of having an enum with max characters, just don't talk.
uh ok
Iโm not doing len(embed) for the sake of it. The point of the enum is to centralize Discords known hard limits (like max title length = 256, description = 4096, total embed = 6000, etc.), so I never risk exceeding them. This is clean, maintainable, and avoids magic numbers sprinkled everywhere. It also makes future validation checks easier and prevents runtime errors due to Discord rejecting oversized payloads.
guess what the user asked
Hey, how do I check the size of an embed message?
I know the total size can't exceed 6,000 characters.
For example, I want to send 10 embeds in one message, but if any of them exceeds this limit when added to the rest, they would be skipped.
.
?
Exactly! Cause he definitely wanted to make sure to not EXCEED it!
so message will always be safe and available
so what i've said is FURTHER validations
not sure what you're saying here lmao so I'm just gonna stop this cuz the user already got what they need, .i.e, "Hey, how do I check the size of an embed message?", which is using the len function
Im not sure what you're saying
How to validate his code using enums, but if it's so hard understanding the whole point of an enum, might aswell consider quitting development tbh (You).
Thanks
Im still working on that menu i've showed u yesterday
I'll ping u once i have a finalized prototype, it looks so cool 
Nicee
There are some good videos, you just have to be careful. I for example, learned OOP on YouTube
Thanks to @stark ingot i was able to see this, it's actually easier than it seems to setup, and you don't need to learn sql that complex way, there are ORMs you can use.
They generate the initial init of database file, they allow you to migrate, downgrade database after changes.
e.g you can use PostgreSQL, which is used for long term data storing, and most common across discord bots.
In order to setup the connection, you'll have to learn that on your own, but there are various ways.
It only depends if you use windows or linux, most common vps used is ubuntu (linux), so if you plan on hosting your bot, you just have to download psql locally
and just create your table, which is the only thing you have to learn.
and easiest way it's just granting all permissions to table you create lol
All this doesn't even require a day, but a few hours to set up properly.
or if you use windows, localhost, just download pgadmin
or you can use Docker, most common tool across developers, and you can just literally run the database on it, without downloading anything ๐
just passing some default values you'll use into your .env or settings, wherever you get your settings from
You can even connect to remote databases (on your VPS) with PG admin on your PC
exactly
i just feel like using json it's more work than making your life easier ๐
and it ain't even a db
Jsons are definitely easier to interact with but are just not meant to serve as a db
nah, all that write, open logic is just terrible
it's just easier to manage a orm at that point
Model.create_or_update()
like ong ๐คฃ
Anyway I switched some of my code to use an ORM, it works fine, I had a few times where two processes interfered with each other and caused a db lock though
jsons are fine if your data is static
I was told that enabling WAL should help against this
?
What ORM do you use?
after trying some, i went for sqlalchemy
tortoise orm has migrations failures if not handled in a certain way, it's harder to understand
I use a lib called sqlalchemy that interacts with sqlite
Yuh
How does that work though
I don't know, i believe that's something related to SQLite
WAL writes the database transaction to a log file first
I have 2 py processes that use the same db file, idk if that's exactly why it may happen though
Temp file?
Not really
it needs to be persistent so that the transactions aren't lost in cases of a crash
Does it also make it auto retry on db lock? or must i manually do that
unless it really ensures db locks don't happen
afaik it significantly reduces the database locks (if not completely remove them)
you could just set a busy_timeout PRAGMA if you want sqlite to auto-retry
I moved to a db BECAUSE of race conditions so I really hate still having them
But tbh it's probably not such good practice to save to disk each operation, maybe I'm wrong
But due to my RPI's low specs I don't want to overload the ram with stuff like redis
I really don't think that two different programs should be both accessing a single database file simultaneously
That's right but Idk how else I should implement it
I have a process for topgg webhook events, it saves the time of when the user voted in the db
Then my bot process checks, on command execution for example, if 12 hours have passed since the said time and if so, set that field to None, etc
I could possibly make the 12 hours check in the first process, maybe in another thread
But the check still has to be done on the bot process if I want to actually use the information
why do you need two different database connections for that
"race conditions" can happen regardless of if it's the same or a different process
How'd it be possible to use one across 2 running processes
Sorry for mention
No worries, but I just start an aiohttp server inside a Cog which has access to all the attributes of my Bot, including the database wrapper - which manages the database operations
Or just make your life easier and use topggpy
!pypi topggpy
A simple API wrapper for Top.gg written in Python.
Released on <t:1636189849:D>.
That doesn't matter, what matters is where the process runs
Is the aiohttp server not blocking?
Do you run on a separate thread?
Of course...
Cant you just store the last voted timestamp to the db and then check them when the user use the command the next time
So having a single process with the topgg webhook events being on a second thread should do it?
Does it for me, haven't run into a race condition for the past 2 years
That's what I do
And do both threads save and read?
You done it different than my approach tho
Yes
You set it as voted or not
I set it as last voted
๐ค
I'll try it then, what do you use for running on another thread (
)
Am i reading it wrong
Not bool, rather timestamp only
In fact, I have more than 2 aiohttp apprunners that access the same database file
asyncio
I'll probably just use uvicorn
to_thread or threadsafe
Never done that before lul
Wut. It's totally fine to have two processes access the same sqlite db, you don't need to migrate them into the same process
That's an anti pattern, you want separate processes
Not directly? I mean it's fine if theres another layer that queues/manages the transactions, which the two processes communicate with, but both processes shouldn't be accessing the database file directly
Or am I wrong
Why would I be getting the db locks though
Especially considering I have low user count so saves are not common at all
And is enabling WAL the best thing I can do about it?
tbf then there's probably something else wrong with your code. The transactions don't take long enough for you to have frequent db locks
You should have WAL mode enabled regardless
This is why libraries like asqlite enable it by default
And does the file it uses just keep growing
I mean to say does it get auto cleared anyhow
WAL doesnt grown indefinitely, no afaik
Ideally it doesn't
@gritty inlet Is there a specific reason why you've selected using SQLite?
Recommendations
As of my code Idk, this is my base setup
Umm, i see, most of the people i work with, we all use PostgreSQL for discord bots, or any long term data storage.
And honestly, it's just so much better, and no need to do all that.
SQLite is perfectly fine
Then an example operation
wym by long term data storage? All dbms can handle long term data storage
check specifically postgresql.
Anything here that can potentially cause race conditions? Doesn't look like it to me
What is "all that shit" which SQLite "makes you do"
And you should go take a walk, considering you don't know what a production branch usage is for.
SQLite and PosgreSQL are very similar
postgreSQL doesn't make you all that WAL part, 2 managers or whatsoever they're talking about.
Im not speaking about specifically related usage of postgresql or slqlite
In my use i only change $1 to ? And the same postgres sql i use run perfectly on sqlite
Because you can't understand common words, something you've done yesterday, and in my eyes you just look like a yapper, sorry.
and i don't care if you take it as an insult, or not, im telling the man to try postgresql, since he might enjoy it more.
It's preferences.
And we're asking you to justify why and instead of answering you just insult me
I will justify questions coming from them, not you.
You came into my subject out of nowhere.
It's not "your" subject. You're speaking in an open forum
Right, it's a topic i specifically wanted to discuss with @woeful hill and @gritty inlet, is there a problem im not invloving you in it?
ooffff, you felt left out, im sorry, here take a pickle ๐ฅ
I'm discussing it too, and that doesnt give you a right to just insult me
If you don't want to engage that's your decision
Not in the postgreSQL topic, sorry, u outta it.
I'm not
Then keep talking to yourself, you'll feel ignored even more, but i don't have an extra pickle.
I don't really agree, people can ask questions about something in a public channel
But no reason to keep going with this
I'm not talking to myself
Sorry, it's personal with him.
Alright then...
Anyways, if you want an in depth discussion on databases that's better served in #databases . But SQLite is completely fine
If you do want to try postgresql, and not go against similiar problems, ping me or dm me.
It was meant to be a recommandation, not saying one is better than other.
"One is not better than the other"
Hm I see the WAL logic now
But thing is, I want changes to take effect pretty much immediately
So saving every x amount of data might not be good unless it's a low amount, still Idk
They will, WAL doesnt introduce a meaningful delay
There's an eye opening page on the SQLite website about how sqlite operates at scale. It's designed for what you're describing
How come
When I get from the db, it'd only have what's already there and not things that haven't been saved yet

But, consider that in discord bots, postgrelsql might be a better choice in my opinion after trying both, very small knowledge into using "SQLite", i can start off by saying the concurrency, postgresql is designed for multiple concurent read/write operations, while sqlite it's like single file locked under multiple writes, different is that postgresql won't choke under load.
You're imagining WAL like some slow queue that gets popped from occasionally
That's not how it works
My situation: I want users to vote and right after that have the benefits of it
Isn't it a save each x amount of data
As a somewhat side-comment, frankly you're not building something where the speed of one database vs another actually matters. Build software first, scale it when you need to, because most software never actually needs to scale
about scalability, SQLite is used for small projects, meanwhile postgreSQL can scale milions of rows, heavy traffic.
SQLite is not only used for "small" projects
SQLite is used for some massive thing with huge scale, and it functions perfectly well in that capacity
it doesn't even have async driver
The SQLite website itself runs on a sqlite database and thar incurs orders of magnitude more usage than you ever will
It does have async drivers wut
it's the most used database in the world for a reason, it works well, it works fast
??? does it?
asqlite and aiosqlite are the most popular
Oh shit, my bad, i thought it didn't
that's my mistake there, read above too.
Oh my mistake, it may be that but other operations on the same connection can access that "unsaved data", can they?
quick question tho
@fast osprey
What if app crashes mid write?
file corruption is inevitable i believe, using SQLite
mmmm
How about the queries?
or features?
Last time i tried it, it was absolute basic, compared to postgresql having jsonfields, enums, indexing (also partial indexing), triggers etc.
lame
postgres certainly has more features than sqlite but uh, indexing? that's pretty much universal across any real database
i just brought it in
Choose your DB based on its features and your needs, you don't always need something advanced
sharding most databases is complex, sharding postgres certainly isn't a walk in the park either
im just trying to find a positive + for sqlite, which i can't.
Do you need what it called the "scale" of the program
SQLite requires vastly less overhead and moving a database between infrastructure is incredibly easy
also refer to my earlier message: your software probably isn't ever going to reach the scale where that matters, and if on the off chance it does you can migrate at that stage, if you design everything you make to work like large scale software from the get-go you won't be able to get anything done
If you write the code solely based on one thing that you cant change when it scale, its the design problem, i have it myself with some libraries
People love solving for problems they don't have and probably never will
Since you all are trying to ride SQLite so much, over PostgreSQL, make a clear label of why you think SQLite would be eventually a best practice.
In complex projects / relatively small
I am actually curious to see.
Me personally, i would NEVER use SQLite into a complex projects.
Im saying sqlite is on pair with postgres
like, to be 100% honest, 99% of people who have ever sent a message asking for help with data storage in this channel could probably run their database off a single json file and rarely if ever experience an issue with it. It's not a good idea and you really should use a database, but modern computers and data storage are phenomenally powerful and reliable
I have never said one is absolutely better than the other
True ๐
I dont care about the scale, my program have no users, and if i do, i will change it when i feel i need the changes
I don't know, you guys just jumped on me saying SQLite has that that and that, which is trying to prove a point as in it being better.
I understand at a small scale, or local projects, it might be great.
But here, we are talking about discord bots.
You were saying sqlite is bad, so we just back it up?
We don't care about it being better, we care about it being misrepresented as not being good enough for production software and that you must use an alternative, which is quite definitively is, and is widely used as such
I didn't say it's bad, im saying postgreSQL might suit most discord bots.
You are the one comparing one with the other
Yeah, cause you guys kept on riding SQLite.
All i did was come with a recommandation to that guy to try postgreSQL over SQLite, since he might enjoy it more.
I love postgres, I use it for everything and I have no intent to switch to sqlite, but the reality is that almost anyone making a bot here could use sqlite without issue and with a huge degree less complexity than what's required to set up and manage postgres
You can't compare scalabilty over SQLite and postgreSQL
exactly, most people prefer using postgres, and that's what im trying to point out.
You were saying its hard to scale, so im saying that sqlite is absolutely viable for large scale uses
Dont take it the wrong way
It is, postgre can scale milion rows and heavy traffic.
"Most people prefer Postgres" is a gross mischaracterization
This guy feels offended over everything
I didn't say I was offended
I prefer postgres because I'm an experienced software engineer writing production software at places that use it. When I started programming I used sqlite because it was good enough and it meant I didn't have to learn both SQL databases and managing infrastructure & networks and stuff. sqlite is an amazing choice for people who don't want to deal with the complexity of managing a separate database service
you're lucky, i don't have pickles anymore for you, but i can give you a ๐ฌ

And really people shouldn't even have a preference. They are different tools that fit different use cases better. That's like saying you prefer a hammer to a screwdriver
Most people use it for discord bots too, since it's not even that complex to setup.
Honestly if we took a database usage chart for bots I would imagine it's pretty evenly split between sqlite3, postgres, mariadb, and mongodb
You're like so mad over the fact that i tried to recommend postgresql for his discord bot, you're the reason why im being like this, you just get on my nerves.
I'm not mad
Mostly beginners, but im not speaking of beginners here.
tell Dyno bot to use mongodb
Mysql and oracle would be the best engines then since they are 2nd and 1st in most used databases ๐
Talks about stats
Mongo is widely used among larger apps lol? It wouldn't be my preference but as with sqlite the fact remains that it's fineโข and you can get away with using it to a way higher scale than I think you realise
This is all completely anecdotal, and even if you did have data on what database is used most that doesn't remotely inform you about what database is best in this specific case. It's random trivia
But, i respect everyone point, apart of solstice, You guys can use SQLite, me saying try postgreSQL was strictly to recommend him a proper database for discord bots.
new day, new argument
Im not entertaining this anymore, since everyone clearly has they're own things in mind.
solstice is making similar points to me in a well presented and respectful way, I don't think it's at all fair to go "I respect everyone's ideas but theirs" tbqh
My final and honest recommandation, for discord bots, is that your fingers won't hurt trying out postgreSQL over SQLite.
They've been adversarial against me for some weird personal hangup
You don't wanna see what happened yesterday, it's always me being in love with solstice.
Why is it always you vs everyone 
I kind of enjoy it ๐
read my mind
looking forward to tomorrow's argument
But also, wtf you got 25 hours on vscode
I've had some arguments with solstice in the past, that doesn't mean I need to be adversarial to them for all future points, we agree on many things regardless of things we may disagree on
This is my final message over this tho.
Hey... in my excuses, it's my pc running, it ain't me.
๐
๐
Oh, yeah, so look, for further validations, about "Enum" part, it wasn't to write something from scratch, it was to validate the max embed / message limits.
Directly doing an Enum, that's for the best practice, making your own safe_message
You don't like people helping you? I've been nothing but nice to you 
It's called a suggestion..
^^
Some people ask for help, but they clearly don't want help.
How you've felt forced? I've only told you the best practices, if you wanna learn the shit practices go again. I've marked my help with ^^, you called me a GPT user while debugging your code.
Spooky, does this happen to you often, like outside this channel ๐คฃ
From what I understood the default checkpoint is every 1000 pages of data which should be around 4MB
But I don't think my operations fit for that as they take much less - I don't want to have data in the WAL storage for too long
Not really ๐
I hope I got a correct understanding of it
hello who wanna developa discord bot with me
Lmaoo
It's just special here
I'm still convinced this channel is actually just a social experiment
This channel is special
For trying to teach best practices i get called in so many terms by this adam guy, the conversation can be seen above.
I really think it will help to not envision WAL like some slow queue that gets popped. I recommend turning it on and seeing what actually happens
^
guys who wanna dev a discord bot with me
Like, he thought event doesn't load for him, or thinking it was library issue and not his code ๐
This isnt a job board
guys who wanna dev a discord obt
And when i told him he was showing me that he was logging the fucking exception of .load_extension
never logging the actual files loading, only logging if the .load_extension fail, and not your cogs
but i guess some people dont' wanna learn, and would rather be imbeciles.
GUYS WHO WANNA DE VIWTH ME A DISCORD BOT
Can someone explain WAL mode in baby terms?
I might have to make a bingo board for this channel
Imma assume WAL isnt useful for read only, shall I
๐โ๏ธโ๏ธ
<@&831776746206265384> lol
Write changes to a diary before editing the main book.
Beginners don't have a great working knowledge of how software is made. If you want my honest opinion I think you went in way too hard with sarcasm/talking down to them about the issues. It's understood in pydis that people may have little experience, or not know how to solev problems or ask for help effectively. If you're going to contribute by helping people here IMO you need to have patience for those people as a prerequisite. Not everyone you help will have a decent knowledge level and you've got to tailor your help to individuals.
WAL mode does ||WAL thing||
Should be clear enough
yes come
Smh
does the baby understand english
Okay that makes much more sense
Yes but esl
if you would read conversation,, i been nothing but respectful to adam, bringing up extra points for his code. If you would read you would understand and see, but he just been insulting, and said i use GPT for debugging a fucking log, you can see that all, so dont say this unless youโre familiar with yesterday context
And best practices today over how to validate messages, since it seems like he is making heavy messages, its even easier for him to set max values over a enum for best practices
If you feel like someone isn't receptive to your "help", then don't help them
So real man
Then why are you bringing up yesterday's conversation
and my points were good, he probably thinks i was yapping
you are a pickle
Perhaps, i wanna show y'all something, i still need to validate a few things, and remove lag caused due to attachments, since im uploading and not using an url, i'll js make a github public repo with my assets
y'all see when i'll send video in a sec
Thats not the help they need
And im trying to teach them best practices, but they've proved to me that they are not here to learn, but only complain thinking what they do is right.
Sometimes you've got to pick one battle at a time, people learn good practices over time. I really wish we could just get everyone to make perfect code, but yeh reality is if we push tons and tons of best practice into people's heads before they even get started they'll just quit.
@timber dragon
Told you i will ping you once i have a prototype.
If command disabled, that deny turns into allow, basically doing the opposite of denial.
Updated my db code, we'll see if it goes good
@gritty inlet i want your opinion on this too 
The command?
that's 1 feature of the panel.
As in commands management of the bot.
and the callable already exists and it's handled.
If command enabled, they can deny users / roles
if command disabled, they can allow users / roles
doing opposite, all done thru a proper ui, and not 1000 commands
How does the async session on your orm work? Does it make a connection pool?
It works good
I set one process to use WAL and the other not to. The one that doesn't - only reads
that looks really good. I think the layout can be better like with bokder and bigger text, but the functionality is nice
also good music 
you should share it at https://canary.discord.com/channels/613425648685547541/1403147433369800888 too
Isn't that just the integration panel but slower
Wait I just realized, yeah setting roles or users for commands is already a thing in integrations
yeah, most people dont know, so its still a good system bot.
Panel will hold all features settings.
removing in totality commands usage for setups
Users also have settings, for theyre privacy and all
panel is slow due to attachments, since im doing upload, i will swap to url.
Why not just point people to the native feature rather than trying to compete with it
Don't see why, you could just tell users this can be done via server settings
It's less about speeds if you ask me
You guys need to understand that if you want your bot to be big, you need to also implement shit people use/want
even prefix commands, people wont change that, you gotta understand the marketplace
or even most coms, use antinukes, which are useless also, its easy to say โjust dont give permsโ
so i want to compete with current market, the users can also have fake perks to use bot commands and not actually having the permission
its just about the market manโฆ we cant change that
since discord wanted to bad to get rid of prefix commands, years back, fully interactionable
you think they couldnt stop bots doing so? nah
its just that people wont change some things
okay so hello y'all i need a bit of help with syncing slash commands (also i'm using pycord) it's apparently not happening automatically but DOES happen when i kick and re add my bot, i can't really access my command tree since pycord is weird, i'd appreciate some help here
and this is something going on for years now
Reload your client
I can't really agree since I'm one that doesn't understand why people still make moderation bots
As an example
But do as you choose
Its just stuff people that wantโฆ
what do you mean exactly by that ๐ญ
Ctrl + R
i've done that many many times now ๐ญ
Do it immediately after syncing
Well people should understand they don't need bots for so much stuff anymore
But we don't have to agree on this
And then check the integrations tab in server settings
That's unecessary
The immediately
As one who has done that a lot
I'm not implying it needs to be done within nanoseconds
xd
Just before doing other things to isolate the variables at play
i agree with you, but something we cant changeโฆ
You choose not to
Personally I have given up few stuff once I realized Discord had better implementations of them
No memory leak so that's good as well
Really not a huge fan of the fatalism that users are stupid and refuse change and it's a good idea to cater to that. It's a self fulfilling cycle
It's a conscious decision to feed that vs refusing and dragging them to better end results
These stats are probably a bit off but hey at least there's something (unless it's scrapers)
if you think the average people are stupid and design your software base on that, that, is the problem
The only reason users are still "attached" to those bot features is the bots keeping feeding them to the users
okay so should i be looking for anything specific in integrations tab ๐ญ
you dont have to always spoonfeed everyone everything
The commands you're expecting
the command is there but it's just not synced
If you see the commands there but not in your slash menu, that's an issue with your local client
If it's in the integrations menu it is synced
no it literally isn't
i removed an option from the command in my code but in the server the option is still there
i'm new so sorry if i'm using words wrong ๐ญ
How are you checking if that option is there?
by typing the command?
Then that's your local client
The integrations tab is canonical. What you see in the / menu is what your client has cached
wow okay
thanks anyway
it appears i was just misunderstanding what you said it works now ๐ญ
nw 
Memory usage of my bot's process
As of the feature I mentioned earlier
I don't have any paid features whatsoever but I just wanted a nice lil way to potentially encourage votes ๐ Worth doing
I mean as long as the vote doesn't give you a removal of any paywall or other advantages there's no real reason for users to do it, but hey a special color is something
What does your bot do, generally
"Music bot" got it bro ๐ฅ
That's all I need to know when it comes to memory consumption
Don't get why people still make these bots
either a lack of ideas or because the alternatives are (rightfully) dropping left and right
66gb? Are yoy making GTA6
I don't have anything against the concept of music bots
But I absolutely don't get how someone can sit and make a bot that exists in thousands of copies
I just euphony bot. I looked up how to make a music bot and it's not worth the hassle
ig you can learn a couple of things making it
It really isn't.
as long as you're not copy pasting
What can I say then go learn how to handle audio streams without publishing another Discord music bot 
lmao
i was studying a bit of audio engineering long ago, i need to pick it up again
Yes, just with thousands of other bots. I don't criticize you specifically but I just don't get it
its really interesting
Music bots
They really don't need to; Have you ever seen someone using all those services "in one" outside of Discord?
Plus you really shouldn't support YouTube, at least not in the typical way
Isn't youtube music not allowed cuz youtube didn't want people using their api for music bots and discord cracked down on it
Yep
Can't you resolve video name from link in any way that doesn't violate their tos though?
this absolutely violates tos (and the rules of this server lol)

you can probably use their public api for that i think
resolving the video name isn't the problem
redistributing the content is, which violates law in addition to tos
The music audio doesn't necessarily come in a violating way though? Or you mean the act of using the name of the youtube video for anything
You can still make music bots you just gotta find a source that's legal
If the content itself is copyrighted, you are violating law by redistributing it without a license from the copyright holder. Youtube is irrelevant
the audio is a part of their content and redistributing without permission is against the law
Even if it's royalty free, you may not be violating copyright law but you are violating youtube TOS
Yeah obviously. See I was specifically talking about a way to "bypass" the YouTube problem.
It is still a problem if you end up getting the music itself in unwanted ways
If you have royalty free music you got yourself, you can distribute it. That's the only case
!rule 5
5. Do not provide or request help on projects that may violate terms of service, or that may be deemed inappropriate, malicious, or illegal.
might apply
Some bots/apps like Rythm (Rythm now) genuinely buy licenses
But most don't. And that's a problem
I bet a thousands bets none of these songs are royalty free though 

spotify listening sessions exist, compensate the artist, and have vastly better audio quality than a shitty discord call 
Listen Together is an underrated feature, indeed.
Don't try to argue about copyright
Bots can do 1% of what users can in terms of normal client things
So no it wouldn't work
So you mean a bot that does as if it was a user? Im pretty sure thats against the tos
Not if you use a bot token. But again you'd be very limited
It can be done very partially
So just a wrapper around the whole discord GUI? Good luck with that, especially in Python
First of all, yeah this would not be a Python thing
Second, it's too much work
Third, it's too much work just to not being able to do much
tkinter is so ass in tasks
better just not try to do this or at least use javascript
Well yeah, still i think you should really think about this once more.
there are many such open source project u could reference from though
even if not against the letter of the tos, that would absolutely be a misuse of a bot account
Sketchiest looking container xd
Anyway no idea what you mean by connecting to html
HTML is just a format, not code
Looks like a website made by AI
I know because it looks like a huge companies email login
Yes but at the end of the day you'd be using javascript
Pairing html with python is shit
- Do not impersonate other Applications, Discord employees or partners, or Discord services. This includes deception via your and your Applicationโs account and identity.
Hm although why would that ui be a violation, you just wrap what the bot can already do.
And bots can send messages in channels anyway, you could call that possible impersonation already
Reasonably discord isn't going to take action against a rando using a bot to send their own messages because tee hee
but it is completely against the spirit of the distinction between account types
https://github.com/SwiftcordApp/Swiftcord this is one im waiting to get updated and maintained again, such a good project
Custom clients using user tokens are very explicitly against the TOS
That one does?
discord moderators have come forward multiple times in the official discord community server saying they don't care
Will I get banned for using Swiftcord/Is using Swiftcord illegal?
Nobody really knows what Discord's official stance on unofficial clients is. However, hundreds of people and I have been using Swiftcord for quite a while, and nobody has been banned to date. I do not take any responsibility for account bans due to the use of Swiftcord, whether direct or indirect, although there's a very low possibility of that occurring. I recommend trying Swiftcord with an alt if possible.
What a joke of an answer
individual opinions don't override tos
Does swiftcord use user tokens? Yes or no
how else would you log in?
-_- you DONT
which means?
Are you sure you know the difference betwen bot token and user token
Why would you need a custom client for a user
๐ค what does bot token have to do with this
!
You already got a client right now
why people want alternative clients? uh most likely because discord is electron
and probably because they want client features discord currently doesnt offer
Oh so it is vencord-like?
The design looks so shitty icel
Anyway that violates tos
ish, vencord modifies the existing discord client, what i sent is a fully custom client built from scratch using native widgets
i dont have something against people who use anything but it'd be smart from those people to not share that they do
Please man don't try to argue how it is not against the tos because it just is ๐น again you'd be smart to not tell people you use it
it neither smart nor dumb there is no recorded case of discord banning custom clients and official staff members at discord have come forward saying they couldn't care less, but yes it's written in their ToS to not modify the client
which makes legally sense, but in practice discord doesn't care so why should the users
Why does it matter what the staff members say? Staff members do NOT mirror the tos neither can you trust them for legal matters
It's a pretty moot point because this isn't bot related, or python related, and this server's rules specifically say not to violate service TOS regardless of whether you personally think it's okay or not
discord staff is discord, it is of their opinion that they dont care
You are already wrong by saying staff are the true representation of the platform and its rules
the employees are sure representitive of the company they work for, which is why they are hired
People are hired for specific reasons. Not every employee has the authority to communicate binding policy
that's like saying a grocery store cashier can just tell you it's okay to take whatever you want
I said representation of the platform and its rules, not representitives
if they dont have the authority and make such claims then they would be legally liable for any act based on said claims
Yeah?
TOS aren't legally binding
im not speaking of ToS
This whole conversation has been about tos
i'm talking about an employee making a claim which then a user could act against
and if that act happens to fall under unlawful terms then the employee in question would be held liable

Nobody in this conversation has made a point about the likelihood of being acted against, but you're fixated on that for some reason
that is irrelevant
multiple official discord moderators have legitemetialy come forward saying they don't care, i see no reason for a user to care themselves at that point, regardless of what is stated in a ToS
That is your choice to make, but again it is against tos and everything I said stands
yes im not disagreeing
it is irrelevant to this channel, irrelevant to this server, and against the rules

๐ฆ๐ฆfor now here's a random snippet
import asyncio
def to_thread(func) -> ...:
"""
A decorator to automatically turn synchronous functions to asynchronous
by running them in a separate thread with `asyncio.to_thread`.
"""
def wrapper(*args, **kwrags):
return asyncio.to_thread(func, *args, **kwrags)
return wrapper
@to_thread
def sync_func():
print("Hello World")
async def main():
await sync_func()
asyncio.run(main())```
dope
hot
but where paramspec
or for 3.12+
import asyncio
from typing import Awaitable, Callable
def to_thread[**P, T](func: Callable[P, T]) -> Callable[P, Awaitable[T]]:
async def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
return await asyncio.to_thread(func, *args, **kwargs)
return wrapper
Meh was too lazy for any typing
Also why not import these from collections.abc
And it actually doesn't matter if you make wrapper async or not
im so confused why it's only getting 2 of my roles neither one is the conditional
thats everything involving the issue
anything else just continues the action of the component
I have 4 roles the roles its printing is Early Support and the @ everyone role. The conditionals is the manager and mod role
but it's only printing 2 roles even tho I put a print above the conditional
It's impossible to diagnose why a print statement isn't working without showing the print statement and surrounding code as context.
for roles in interaction.user.roles:
print(roles.name)
if roles.id == (1424179881880584232, 1413800644787310592):
pass
else:
pass
```
thats the whole code
I've tried a few different stuff
print(roles.name)
if roles.id == (1424179881880584232 or 1413800644787310592):
pass
else:
pass```
```for roles in interaction.user.roles:
print(roles.name)
if roles.id in (1424179881880584232 or 1413800644787310592):
pass
else:
pass```
so weird
What else is in that loop?
nothing
Where you create the embed
What are you expecting lol
It keeps going to else
You only let 2 roles be printed
Have you realized
Oh you mean it doesn't print that text?
It should be letting the interaction continue when the button is pushed if you have either of the 2 roles
.
when it's printed theres only 2 roles in the terminal
im getting tired of explaining the same way
- You click the button
- It loops your roles
- If you have 1 of the roles it continues
- Else you're denied
- The print statement only shows 2 roles in the user list
I have 5 roles total
Show me the print statement please
the second time this loop runs interaction.response.send_message is raising an error. That happens after the second print statement.
Somewhere your error handling is eating that exception and not printing it to console.
I'd just like to see the lines in the code where he prints the roles
it's right above the conditional
Once you sent your full code it was a lot easier to figure out the error, so when people are asking for your full code it's really Important to provide it.
You can see it in the screenshot above, which also explains why it's only printing twice. For every iteration, inter.response.send_message is being called. That object can only reply once.
hmmm
You're right!
It is a full member object. Using the cache may make problems worse and would rely on the cache they may not even be enabled.
Don't do an interaction response inside an iteration unless you stop the iteration right after (return await ...)
@narrow hazel
oh so just move it back to the for loop
no, if the rols is in the tuple, do return await to stop the iteration
add return before the await
Finally
why did you completely un-indent the if statement
Because it works now
yea that too lol
This is my alt
.
It doesn't. It only checks the topmost role you have
I wonder if you can do a bitwise and with roles hmmm
Why though, his logic is fine
No, the if must be inside the for
And you need to stop iteration when you respond
well clearly it still works
they already showed the if statement outside of the for loop ๐
Yeah I can see now but he can fix it by simply moving the indentions
thanks zenith
You need to check all of the allowed roles with the roles the user has, breaking at the first match, and falling back to no permissions error if the user doesn't have either of the roles
Pseudo code:
For role in roles
if role in user.roles:
break
Else:
# handle not allowed
Return # very important!!
# handle allowed
Unless you can do else after for and I didn't know, anyway that's useless
It's not. You can have an else on a loop which only executes if you didn't break out of the loop earlier.
This code flow I've illustrated follows code standards including guard clause ifs, which prevents nesting all of your code inside a bunch of checks
Whatever you put after the loop will happen, with else or without, wouldn't it
Ah i get it actually
!e The break prevents it from happening.
for i in range(5):
print(i)
if i == 3:
break
else:
print("didn't break")
print("6")
Yeah thought so
:white_check_mark: Your 3.14 eval job has completed with return code 0.
001 | 0
002 | 1
003 | 2
004 | 3
005 | 6
I'm on mobile don't judge my typing lol
Personally I'd just return instead of break
Wouldn't this work?
for role in user.roles:
if role.id in (role_id1, role_id2):
# allowed logic
return
# not allowed logic
That's what I'd do, yes
doesnt the comma mean and?
oh
I need to start learning using a DB. I just spent like 10 minutes trying to figure out why a button wasn't working. turns out my persistant buttons doesnt save anything except the buttons ๐
because I save None to the persistant buttons


