#discord-bots

1 messages · Page 408 of 1

fast osprey
#

Anywho I'm supportive of that, but I think you'll be severely disappointed with the percentage of people who read channel topics

#

People who are smart enough to do that are almost always smart enough to find those things themselves

tender bobcat
#

Ok so 10
Can we fit all of them in 1024 characterpithink (for why 10, I also considered interactions section one)

stark ingot
#

A pinned message would work as well. But if you limit what info is needed for each library then it helps.

#

I am planning on writing up a few examples and posting in #community-meta when I have time

timber dragon
#

I've updated my guides message to include the libraries too, may help shrug

stark ingot
#

Not sure why that message is not pinned.

tender bobcat
#

Well, there are no new pin message for 2y

fast osprey
drifting arrow
#

I don’t need no pinned messages

stark ingot
#

What library? Or are you using the raw API? I assume you want an example of how to send a message containing an action row?

viscid hornet
#

!d discord.ActionRow

unkempt canyonBOT
#

class discord.ActionRow```
Represents a Discord Bot UI Kit Action Row.

This is a component that holds up to 5 children components in a row.

This inherits from [`Component`](https://discordpy.readthedocs.io/en/stable/interactions/api.html#discord.Component)...
viscid hornet
#

define "styling"

#

what are you envisioning?

stark ingot
#

I dont know discord.py but action rows are pre components v2

viscid hornet
#

you can do this on a view, not on a modal yet

#

oh thats easy enough

#

!d discord.ui.View

unkempt canyonBOT
#

class discord.ui.View(*, timeout=180.0)```
Represents a UI view.

This object must be inherited to create a UI within Discord.

New in version 2.0.
fast osprey
#

Modals don't have any styling

#

It's just text inputs, at least in v1

stark ingot
#

They are asking about a message in response to a modal submit

fast osprey
#

Oh then the modal is irrelevant, sending a message works the same in this regard no matter how you're sending it.

You generally don't interact with rows yourself, just use the row kwarg when making components

heady swallow
#

is there a way to persist data for buttons (i.e. self.user) upon bot restart using .add_view on bot startup?

fast osprey
#

discord.py at least supports dynamic items if you can embed the info you want into the custom_id

tender bobcat
#

dynamic item is so helpful

#

I have a button that embed:
prefix(identifier for the kind of dynamic item related)
current page
interaction page(the page to be changed on interaction)
key(identifier of what to trigger in the prefix category)
author id

timber dragon
#

So good

real crag
#

hi could you learn how to make a discord bot? with python or node.js jajsjsj

fast osprey
#

Given this is the official python server, you're not going to get help with the latter

jaunty cape
tender bobcat
#

Profitable - (?)
It should be faster if you idex by the column frequently

#

Last time I checked you don't get money for indexing the database (?

sick birch
#

Database indexes do typically speed up reads on average, at the cost of slower inserts

#

You do need to make sure to use the right index on the right column, but it depends on many factors

fast osprey
#

Yeah this isn't a binary "is it indexed or not". You don't index the whole database, you add specific indices which will improve queries of a specific type

bright lava
#

How does being Polish change the fact that you can use Google to translate?
Say what word you'd use in Polish here, I'll translate

bright lava
#

So just say the word. I told you I'll translate it

bright lava
tender bobcat
#

I mean I was just joking
Sorry for making it sound way too serious

full lily
#

whats the status of discord.py compatability with slash commands and um what are they called

#

interactions

tender bobcat
#

Maybe harder to use than other library but should support everything except HTTP webhook based interaction(Doubt for any plan of support) and Component V2(Currently PR)

sick birch
#

When cog starts, all tags would be read from the database and saved in memory.
this might not scale well

#

are you trying to use the autocomplete thing for tags

#

you could load just the names then, i think that should be fine up to a very large number of tags

fast osprey
#

In order to collect, aggregate, copy, duplicate, display or make derivative use of the Service or any Content made available via the Service for other purposes (including commercial purposes) not stated herein, you must first obtain a license from OLX INDIA.

tender bobcat
#

Would be helpful to kindly remind them to read the ToS and don't need us to read it for them

#

So that's why

stark ingot
#

It seems this service also has an API in which case it is likely not difficult to obtain a license. Or have allowed routes of accessing the data.

gleaming inlet
#

@silent pier FYI JSON stuff still works.

drifting arrow
#

Dont share your token you muppet

silent pier
#

fkk 🤦‍♂️

drifting arrow
#

go reset them both right now

silent pier
#

mistake'

drifting arrow
#

Dont even speak. Go reset.

gleaming inlet
#

LMAO

#

💀

drifting arrow
#

There are users in here who most definitely have those tokens saved already

gleaming inlet
#

But briefly, it looked like some online bot hosting server stuff. I'm sure they have the utility to handle environment variables in the dashboard and that's way easier to manage @silent pier

silent pier
silent pier
drifting arrow
#

Also, you don't need longer names, just names with enough in them that you know what it is.

fast osprey
#

Also JSON is an incredibly crappy config format all things considered

drifting arrow
#

How dare you >:(

#

JSON is fine. Don't listen to @fast osprey he's just a hater

fast osprey
#

"Fine" is such a meaningless term

#

JSON was designed to be a data interchange format between separate systems. Not configuration within an individual system. There are formats far better suited

drifting arrow
#

Ahuh, sure. like what? XML?

fast osprey
#

yaml and toml are industry standards these days

#

xml is pretty ass, at least to read

drifting arrow
#

XML is what MSN messenger was built upon

#

Yep

fast osprey
#

Unencrypted config files are still not great for secrets (ex your discord token). But the format you pick is largely irrelevant if you do besides readability and size (which I'd rank JSON lower than literally every other option including .env)

drifting arrow
fast osprey
#

Okay...?

#

I'm not sure how the existence of bigger problems mean you shouldn't solve smaller ones

drifting arrow
#

What I'm trying to say is, if you can stop someone from getting access to the file or the data inside of it, you don't need to worry about whether the file is secure or encrypted or not.

#

But if someone can access the file or the contents they've already owned you.

fast osprey
#

You don't need direct access to a file to get its contents

drifting arrow
#

I know, I didn't say that was the only way.

fast osprey
#

If the claim is that secret management utilities don't give any incremental security, I'm not sure why every industry shop worth their salt would use them

drifting arrow
#

All I am trying to say is, if someone can already access the file or the contents, regardless of the file type or the content encryption level, then you've already lost everything.

fast osprey
#

That is just blatantly not true

drifting arrow
#

How so?

fast osprey
#

Let's say you have a code vulnerability that exposes read access to the file system. It matters if you're putting your secrets in that file or in a secret manager

#

You haven't "lost everything". Go ahead, read my config

drifting arrow
#

But you've also lost all those other files.

#

I dont need your tokens, I already have access to everything

fast osprey
#

What do you mean "lost". I think you're misunderstanding what a secret manager is

#

but again, if you move the things that are sensitive to a secret manager it doesn't matter

tender bobcat
#

Honestly, I am not sure having a secret manager and trusting them not have vulnerability, with the complexity of deploying code in the background(i.e. automatic code deployment) that needs secrets to operate would be worth it

#

It's just the tradeoff between the security/trust of the third party and the complexity of using the third party

#

But if using a plaintext format, hopefully you are not using json/XML for most of them (situational dependent)

fast osprey
#

All things equal it's better to not put secrets in a flat plaintext file, but my argument wasn't that it was easier to use a secret manager (or even necessarily worth the tradeoff).

But even among plaintext config formats, some just don't make sense when used for that purpose

tender bobcat
#

Yep, for the security/trust side, you shouldn't put secret in plaintext file because you shouldn't trust the read access of the filesystem not being access by thing it not suppose to

plain basalt
#

Is hard to make an discord bot? using python

tender bobcat
#

Hard is hard to define, it depend on your skill level

#

if you are new to python, yes, it is very hard, similar to most application you make that many people would use

#

or if you make a user facing application with more than just a few user use, it woulld probably easy to make one by translating the skill you learnt

exotic hazel
#

"it woulld probably easy to make one by translating the skill you learnt"
Sorry, can you elaborate on this? What does translating the skill mean?

tender bobcat
#

like, if you make a website with server before, it would be easy to translate it to designing discord Embed because you know how to structure thing to look nice

exotic hazel
#

Ah, that makes sense, thanks

tender bobcat
#

you make a webserver before using fastapi so you understand the priciple for async networking which is required for making discord bot

drifting arrow
tender bobcat
#

???

drifting arrow
#

Just start making one. Google some stuff and eventually you'll have a terribly made bot. Eventually you'll want features so you figure out how to make them.

Then and only then will you have a somewhat functioning bot. You'll create a community for it. YAY! \o/

tender bobcat
#

You made an assumption that you can making a functional bot with it, without knowing any concept and just work through it
And you also made an assumption that they won't give up, and will have the dedication to spend a long time just trial and error, bruteforcing, with minimal feedback(or just don't understand them)

It's possible, but not easy, and you are making a very bold assumption

drifting arrow
#

I mean, the only thing stopping anybody here from making a bot is their own time and dedication.

#

You dont need to know and understand everything going on to make a bot

#

Source: Me

tender bobcat
#

You don't, but you just going through a even harder path

drifting arrow
#

I started learning python just to make a discord bot. I knew frick all. still know frick all.

tender bobcat
#

I am not saying it's not possible
I am just saying it is not easy as you claimed

drifting arrow
#

¯_(ツ)_/¯

#

It also depends on what type of bot he wants to make.

#

How big he wants it. What database he wants, if any.

#

If he needs to use any apis for data.

#

If he wants to use webhooks and websockets.

tender bobcat
#

If you just copy and paste from GitHub, it is not making a bot

Anything further from just copy and paste require usage of concepts that are easily confusing

#

If you didn't know the concept

drifting arrow
#

Learn as you go I guess

tender bobcat
#

Like
Why await don't work here
Wdym event loop

tender bobcat
drifting arrow
#

You don't need to completely understand something to be able to use it.

tender bobcat
#

No, but it is the easier path

drifting arrow
#

Too long. Want bot now.

tender bobcat
#

Well, did OP said that?

drifting arrow
#

¯_(ツ)_/¯

tender bobcat
#

You just picking the very difficult path
And claim that it's very easy and making a wrong illusion

jaunty cape
drifting arrow
#

Lol

silent pier
stark ingot
tender bobcat
silent pier
silent pier
tender bobcat
#

There still contain information that you might not want other people to know from there
Such as your discord application id

silent pier
#

it should have thrown a file not found error

#

but idk why i made an empty config.json in home/container

#

this is WHY

tender bobcat
#

lol

tender bobcat
#

Nice

tender bobcat
#

I mean, the only slow part here is the network and you cannot fix it

#

It's not really necessary to optimise such
But the best way is don't inline it

#

One thing to start is having self.DATA in lowercase form

#

So you don't do power every time

sick birch
#

i think you should get all the contains with first, then only run through that loop for ones where it starts with current. it would be slightly faster

#

if you wanted to all out you could probably use your database's full text search feature (if it has one)

fast osprey
#

Chances are you're at the data volume where you're talking about the difference between ms

#

preemptively optimizing things before you've done any profiling to actually find the bottleneck can be a massive waste of time

sick birch
#

the network round trip delay with discord autocomplete is going to dominate. not many optimizations you make right now are going to help

#

if you're at the point where it takes on the order of seconds to search, then it could be time to look into optimizations

tender bobcat
#

You can do both thing in the loop

#

Since they are mutually exclusive, you check the first, if not, then second

sharp lintel
#

Micro optimization but if your suggestion list is huge, use generators and itertools, it's a lot faster

dark perch
#

Hey guys I just created a drop the handkerchief bot

#

The permissions and desc is not updated

#

But yeah it does work fine

pallid plank
#

Where's the nuke command?

dark perch
#

I just want feedback

fast osprey
#

Then post the code

unkempt canyonBOT
#

:incoming_envelope: :ok_hand: applied timeout to @flint crater until <t:1748610621:f> (10 minutes) (reason: attachments spam - sent 8 attachments).

The <@&831776746206265384> have been alerted for review.

fast osprey
#

Also <@&831776746206265384> kind of sketch someone unsolicited posting a bot invite link asking for admin

velvet compass
#

@dark perch your message was removed. Don't share bot invite links unsolicited like this. If you want feedback share the source code

dark perch
#

i haev src code in my github

#

check there its totally safe

tender bobcat
#

Well, you have to send the GitHub linkpithink , we couldn't magic that out

#

Just don't send bot/server invite

fast osprey
#

There's also no guarantee that a random code link you send is what's running behind the random bot you're asking people to add with administrator

tender bobcat
#

Yep

dark perch
#

totally harmless bot

fast osprey
#

Requests message content despite seemingly never using it

stark ingot
#

After skimming the code the 2 big things I noticed

  • Don't sync commands in on_ready. You should only be syncing when you have changes in your commands.
  • Don't use json as a database. You can use sqlite with minimal setup that would be a better option if you don't want to use another DB
dark perch
#

if u want to test it pls let me know

fast osprey
#

Intents are not perms

dark perch
#

yeah that too i'll update intents i know

#

i have a server where u can test withotu adding it

stark ingot
fast osprey
#

Oh interesting

dark perch
#

do uwant a test?

#

you can let me know if u want a test u can join my testing server

fast osprey
#

Personally I'm only interested in targeted questions on the code. It's time consuming to test someone's stuff for free with no attachment to the project when you could just do that yourself and distill out any questions

dark perch
#

k

jaunty cape
#

Dude when are you ever going to need Admin perms for that

fast osprey
#

Benefit of the doubt, new developers just throw admin permission to make problems go away without thinking of the implications

sick birch
#

measure it

fast osprey
#

profiling should absolutely be your first option

tender bobcat
#

Profiling should be the first thing before attempting to optimizing it

timber dragon
#

Can't you just use difflib

#

Also iirc a list compherison is faster than a loop

timber dragon
#

Damn regex

zealous urchin
fast osprey
#

maybe with components v2, I dunno, but not with v1

stark ingot
#

You could send 2 messages but that is prone to failures. Components V2 would be the way to go. A container followed by a TextDisplay

drifting arrow
hushed prairie
#

i uploaded a file on discord and its showing this text as well, how do i hide the text

#

im trying to prank my friend

woeful hill
#

pc client has file preview

#

¯_(ツ)_/¯

hushed prairie
woeful hill
#

it is not a permission

#

so no

hushed prairie
#

this works ig

fast osprey
#

If a) your notion of "pranking someone" is trying to mislead them to download a file to run on their computer and b) they fall for it, y'all got issues.

This also has nothing to do with bots, just you lying to people

fast osprey
#

Yeah that doesn't matter to anything I said

hushed prairie
#

he is quite dumb on things like this

#

thought it would be fun

#

i wont do it to just anyone lol

hushed prairie
#

just a discord server invite and rickroll youtube link

fast osprey
#

Still has nothing to do with bots, python, or development

hushed prairie
#

yeah

#

mbwrong channel

dusk pelican
#

yeah can somebody remove that

#

it is a bat file which has commands maybe

#

I think for windows users

#

I wouldnt trust if he she it says a discord invite link and a rick roll

#

grrr makes me angry

woeful hill
#

its an image of a file preview

tender bobcat
west hare
#

Do you know if there is a way to use selector first to choose an option and then prompt file upload? I can only see that file can be send from slash command itself, but without additional prompting there is no way to know which option would need file (+ it can be cancelled if option is not found)

fast osprey
#

You can have a choice as another parameter but that's about it

west hare
#

Is there a way then for autocomplete to fill data from other options?

#

So that I could put variables that need to be filled first to be able to find that option

#

In my case I have DB with 3 columns that specify category and it's subcategories and only by filtering by subcategories I could get a value that I need for upload

stark ingot
#

Yes, you can reference other options with autocomplete.
So if your first option has a list of choices you can then access that in the autocomplete option to provide recommendations based on that selection

west hare
#

Do you know how to do that with discord.py? It come with interaction: discord.Interaction and current: str parameters for autocomplete.

fast osprey
#

interaction.namespace will have the other current param values iirc

west hare
tender bobcat
#

I haven't tested it tho

stark ingot
#

👍

vapid parcel
#

Hey, does anyone know a Docstring generator for Classes and Functions, just curious on if there is a pypi package or something that can do it. Kinda like ruff and isort and basedpyright those do writes (not basedpyright) but you get what im saying.

#

something like cli_command numpy path_to_file.py or something

#

and it works on Python 3.12.xx ^

timber dragon
shrewd apex
#

there is also trelent extension

final breach
#

how can i use Components v2 on discord.py?
or i need to switch to discord.js?

fast osprey
#

it's not supported yet

tender bobcat
patent hull
#

You should only use it if you know and are super sure what you doing , because, at least on the dpy server, you will not receive any help about it until it gets merged

sick birch
#

looks pretty nice but it should have an option to run without user input on production

fast osprey
#

It also really depends on the target audience for this. IMO there's a very slim middle ground between people who would prefer to just set a config file and people who would prefer to do it within the bot itself or with a dashboard

#

why not?

stark ingot
#

I think it is pretty cool for your use case

timber dragon
#

No idea what it says but looks cool

tender bobcat
#

Idk if you are doing it but more fun if the set config is also saved so it retain for further usage

tender bobcat
#

Nice

pallid plank
#

Legend says "1".lower == "i"

burnt quiver
#

lmao

#

I am very late to the party aren't I

sick birch
#

Doesn’t the template feature basically do this

tender bobcat
#

Well, to differentiated from the template, you can have it also backup what role the user have and restore that
And for every user that is not currently in the server, it would save the record and restore it when they join, then remove the record(for indefinite or limited duration of time)

fast osprey
#

But the main differentiator is that the server templates are stored by discord, a multimillion dollar company with expansive server architecture, not one rando KEK

severe rampart
#

being able to store your own stuff locally is also nice, alternatively

severe rampart
#

I guess setup_hook?

#

I just load my cogs in setup_hook if that's what you mean

#

when people say not to use on_ready they generally say to use setup_hook instead

#

I have it like this in my bot:

async def load_cogs(client: commands.Bot) -> None:
    for filename in os.listdir("cogs"):
        if filename[-1] == "y":
            try:
                await client.load_extension(f"cogs.{filename[:-3]}")
                logger.display_notice(f"Cog {filename} successfully loaded")
            except Exception:
                logger.display_error(f"Cog {filename} failed to load")

@client.event
async def setup_hook() -> None:
    logger.display_notice("Starting cog loader")
    await load_cogs(client)
    logger.display_notice("Attempted to load all cogs")
    cprint(STARTUP_ART, BLUE)
    logger.display_notice("The bot is now running successfully")
#

but also I have a custom logger so like

#

and a custom printing function

#

I can remove the custom stuff probably

#

make it easier to read

#

i'll do that rq

#

oh okay cool

severe rampart
tender bobcat
#

Whatever don't important

severe rampart
#

Okay

severe rampart
#

I don't know the specifics of how that works

#

It will load all the cogs

#

then run the bot

#

I think

fast osprey
#

setup_hook is called exactly once between login and connect. The library calls it for you

#

It's also notably not an event

tender bobcat
#

is it not? let me check, I haven't touch setup_hook for a while

dapper ocean
#

What is the difference between those?

@app_commands.command()
@app_commands.guild_only()
@app_commands.guild_install()
@app_commands.allowed_contexts(guilds=True, dms=False, private_channels=True)
async def create(itx: Interaction) -> None:
    """
    """
@app_commands.command()
@app_commands.guild_only()
async def create(itx: Interaction) -> None:
    """
    """
fast osprey
tender bobcat
#

because I remember you do the event decorator vaguely

fast osprey
#

It works with the decorator due to an implementation detail of how the decorator works, but it's not something that I'd recommend

tender bobcat
#

so I gone to check code

tender bobcat
fast osprey
#

You subclass client

#

that is the right way

tender bobcat
#

well, the bot is too late to change now

stark ingot
dapper ocean
#

makes sense

#

ty

jaunty cape
fast osprey
timber dragon
toxic notch
#

Uh Guys what to do if the command says
discord.ext.commands.errors.CommandNotFound: Command "invite" is not found
Even though Its working and no error

timber dragon
#

Means someone did <your prefix>invite but invite isn't an actual prefix command for your bot

#

You can ignore the specific error in on_command_error or set the command_prefix to () if you don't use prefix command

silent ice
#

why it not show the cmd like /paymentinfo i already start it in terminal

tender bobcat
#

Did you sync the command?

fast osprey
#

guild_only does work on groups

timber dragon
#

Oh nvm it doesn't show groups

#

Want to mark an app commands group as user installable / usable (contexts)? There are two ways depending on how you defined it.

Documentation

  1. Subclass (recommended) or using commands.GroupCog
    You can use the decorator(s) directly on the class.
@app_commands.allowed_installs(...)
@app_commanda.allowed_contexts(...)
class MyGroup(app_commands.Group):
# class MyGroup(commands.GroupCog):
    ...
  1. Manual initialised
    Use the allowed_contexts= and allowed_installs= kwargs.
# same thing if inside a (Group)Cog
my_group = app_commands.Group(
    name=...,
    description=...,
    allowed_contexts=app_commands.AppCommandContext(
        guild=bool,
        dm_channel=bool,
        private_channel=bool,
    ),
    allowed_installs=app_commands.AppInstallationType(
        guild=bool,
        user=bool
    )
)

Note: sub command/groups cannot have their own contexts/install values.

#

Might aswell send it all here too

#

Set dm_channel and private_channel to false

rare wharf
#

whenever i put the code it says module discord not found and im using ios python code editor, how to fix???

timber dragon
#

You cannot installs packages like discord.py on a mobile app lol

woeful hill
#

laugh on termux

brazen raft
jaunty cape
fast osprey
#

!d discord.Guild.create_voice_channel

unkempt canyonBOT
#

await create_voice_channel(name, *, reason=None, category=None, position=..., bitrate=..., user_limit=..., rtc_region=..., video_quality_mode=..., overwrites=...)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

This is similar to [`create_text_channel()`](https://discordpy.readthedocs.io/en/stable/api.html#discord.Guild.create_text_channel) except makes a [`VoiceChannel`](https://discordpy.readthedocs.io/en/stable/api.html#discord.VoiceChannel) instead.

Changed in version 2.0: This function will now raise [`TypeError`](https://docs.python.org/3/library/exceptions.html#TypeError) instead of `InvalidArgument`.
timber dragon
#

What does a nsfw voice channel mean lol

#

Only text channels can be marked as nsfw

#

Time to pr™️

#

Now that's not a thing

#

Voice channels got no topic

#

can't set it

stark ingot
#

It is only available for

Text, Announcement, Forum, Media

#

But discord did not make it optional so they have to return it

timber dragon
#

Probably returns it for easy migration lol

woeful hill
#

you can set stage topic with your client, but idk if you can with bots

#

and yeah since you can use text chat in voice channel from years ago they added that

timber dragon
#

Yeah

timber dragon
#

A forgotten feature that they never documented or announced

woeful hill
#

i mean they keep changing it

timber dragon
#

Fr?

stark ingot
#

I think i implemented it in py-cord cant remember

timber dragon
#

Discord is a mess

fast osprey
stark ingot
#

That is relatively new, not sure if it is in the API

timber dragon
#

First time seeing it

#

Oh it's already in the clients

#

Good QoL feature

#

I don't see a pr for it on the docs repo so I guess not many know about it yet

woeful hill
# timber dragon Fr?

i think so, could be me just got the perm revoked at some point since it first time appear

timber dragon
#

Hmm

#

Lmaoo

stark ingot
#

Returned by the API but not documented anywhere (by discord)

"default_tag_setting": "match_all",

timber dragon
#

Yeah and for some reason it's a string

#

"match_some" and "match_all"

stark ingot
#

Also there is a template field 👀 wonder if that will ever be used.

#

And default sort order returns null despite not being listed as nullable in the docs :/

timber dragon
#

It is?

#

default_sort_order? ?integer the default sort order type used to order posts in GUILD_FORUM and GUILD_MEDIA channels. Defaults to null, which indicates a preferred sort order hasn't been set by a channel admin

stark ingot
#

shoot looking at the create docs not the object

timber dragon
#

Ah

timber dragon
stark ingot
#

yes

timber dragon
#

Interesting

#

So it could be some to be implemented code or something

stark ingot
#

My guess is it would be used as default text so when you hit new post it fills in the text box with whatever is in that string

timber dragon
#

Oooh

#

Yeah that makes more sense

stark ingot
#

Like what github issues do

timber dragon
#

I was thinking it could create like default posts but that doesn't really make sense now that I think about it lol

toxic notch
timber dragon
#

What did you change

#

It isn't really an error

toxic notch
#

Should i just send the command? its very tiny

#
@bot.command(name="invite")
async def invite(ctx):
    embed = discord.Embed(
        title="Server namae",
        description="Linkie :)",
        color=discord.Color.blue()
    )
    await ctx.send(embed=embed)
#

@timber dragon there's nothing wrong

#

i mean i check the python masterclass

timber dragon
#

So the command does exist

toxic notch
#

Yes

timber dragon
#

You sure your bot isn't running more than once?

timber dragon
#

Maybe you're running two instances, one with the command and the other without

toxic notch
#

I only have that command nothing else

#

i will add more once i know the issues

timber dragon
#

Can you send the full traceback

toxic notch
#

Alr brb

#
WARNING:discord.client:PyNaCl is not installed, voice will NOT be supported
Bot has logged in as Mizuki#4840
ERROR:discord.ext.commands.bot:Ignoring exception in command None
discord.ext.commands.errors.CommandNotFound: Command "invite" is not found
#

@timber dragon

#

here

stark ingot
#

Is the invite command an slash command or prefix command?

toxic notch
timber dragon
toxic notch
#

uh

timber dragon
#

So the command did work there right?

stark ingot
#

Pretty sure the traceback gets thrown out by defualt because it is ignored
-# Or i might just be silly

timber dragon
#

It shouldn't in dpy

toxic notch
#

@timber dragon sry if its blurry

timber dragon
#

That's you stopping the bot

#

Not the CommandNotFound error

toxic notch
#

Uh i dont get it

stark ingot
#

It looks like you are defining your commands after you start the bot. This might be the problem

toxic notch
#

Uh

#

im confuse

stark ingot
#

Can you show your whole code after you remove the token

timber dragon
timber dragon
#

Welp

#

Yeah that isn't gonna work

toxic notch
#

why?

timber dragon
#

Define the command first then just bot.run("token") at very end

toxic notch
#

Oh i must put it in the end?

timber dragon
# toxic notch why?

Running the bot blocks the "event loop" which means any code after it won't run until the bot is stopped

toxic notch
#

ahh

#

i still don't getting it

#

ama go to school now

#

still

#

Thank you guys

tender bobcat
slate swan
#

guys why does my bot join my channel then leave then join again then leave

fast osprey
#

because you wrote code that does that

tender bobcat
#

What channel

slate swan
slate swan
fast osprey
#

and how have you come to that conclusion

slate swan
#

umm

fast osprey
#

seeing the code would be helpful I think

slate swan
#

okay

#

huh i dont get it

unkempt canyonBOT
#

Please react with ✅ to upload your file(s) to our paste bin, which is more accessible for some users.

fast osprey
#

it's against discord tos to play music you don't have the rights to, and against youtube tos to redistribute their content

slate swan
#

bruh

#

howe come other bots do

fast osprey
#

what does that matter

slate swan
#

dont ban me i didjnt know 3607praying

fast osprey
#

lol I'm not a mod or anything

#

but you may want to read the tos and also the rules of this server

slate swan
#

ok

fast osprey
#

Are you asking for help or just promoting your bot at this point

#

Doesnt answer my question

fast osprey
#

Given that plenty of other bots do this, even though they don't need to, it's not really groundbreaking or innovative. Comes off as bragging at best and self promo at worse

drifting arrow
#

I like bragging.

#

:D

tender bobcat
#

I don't see you make any more features than server templates

#

Also 2 channel can have same name and your backup is screwed

fast osprey
#

It's not keyed by name. But we already had this discussion before, they were told that server templates does this and more reliably, and they decided they wanted to make it anyways for Some Reason

stark ingot
#

Maybe because it is their code and their time that they can do what they want pithink

fast osprey
#

People are allowed to do what they want with their time. It's a different matter when they feel compelled to go into a public help server, post that thing multiple times unsolicited, and ignore constructive criticism on it

tender bobcat
fast osprey
#

Looks that the "System" entry is just a category they decided to name that

toxic notch
#

Just seeing the image alone is already good enough for me to create the same type of stuff

#

Also how do i make my bot reply to a certain argument?

slate swan
#

Where do you guys host Bots?

Any Free thing? 🥸

fast osprey
#

!hosting

unkempt canyonBOT
#
Discord Bot Hosting

Using free hosting options like repl.it for continuous 24/7 bot hosting is strongly discouraged.
Instead, opt for a virtual private server (VPS) or use your own spare hardware if you'd rather not pay for hosting.

See our Discord Bot Hosting Guide on our website that compares many hosting providers, both free and paid.

You may also use #965291480992321536 to discuss different discord bot hosting options.

toxic notch
timber dragon
tender bobcat
#

Tbf I am wondering how much power my raspberry pi draw per month
Curious not never got a chance to find out

#

If it takes maximum power at all time(27W)
Assuming 1 month is 30 day
It would draw 19.44kWh

exotic hazel
tender bobcat
#

It running many many container

#

And also build stuff for me

tender bobcat
toxic notch
#

How to make the bot use reply to the author?

timber dragon
timber dragon
#

⚠️ Original tag by Vex#3110 called "raspberry pi" was edited and removed this information for some reason.

A raspberry pi is less economic, and less preformant than a cheap VPS? Why?
Cost:
pi b3: 35$
50 gig SD: 10-20$
Power supply: 10$
Other shit: 10$
Total: 55-70$

Scaleway VPS: 3.50USD/month
OVH VPS: 3.35USD/month

This means that it takes about a year for a PI to have a cheaper base cost.

Preformance:
https://i.imgur.com/KEBB9Jo.png

Of importance here is that a raspberry pi has half the ram, and your home internet connection, which, depending on where you are, can range from awful to good. In the end, you're still limited by the fact it has a usb ethernet connection instead of a proper connection. Furthermore, SD cards are slow. That's just the way it is, there isn't a way around it.

toxic notch
viscid hornet
viscid hornet
#

!d discord.ext.commands.Context.send

unkempt canyonBOT
#
await send(content=None, *, tts=False, embed=None, embeds=None, file=None, files=None, stickers=None, delete_after=None, nonce=None, allowed_mentions=None, reference=None, ...)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Sends a message to the destination with the content given.

This works similarly to [`send()`](https://discordpy.readthedocs.io/en/stable/api.html#discord.abc.Messageable.send) for non-interaction contexts...
viscid hornet
#

see that reference kwarg?

#

.reply(whatever) is just .send(whatever, reference = ctx.message)

#

!d discord.ext.commands.Context.reply

unkempt canyonBOT
#

await reply(content=None, **kwargs)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

A shortcut method to [`send()`](https://discordpy.readthedocs.io/en/stable/ext/commands/api.html#discord.ext.commands.Context.send) to reply to the [`Message`](https://discordpy.readthedocs.io/en/stable/api.html#discord.Message) referenced by this context.

For interaction based contexts, this is the same as [`send()`](https://discordpy.readthedocs.io/en/stable/ext/commands/api.html#discord.ext.commands.Context.send)...
toxic notch
#

yes or no?

viscid hornet
toxic notch
#

i still have to go to school

viscid hornet
toxic notch
tender bobcat
#

Also clearly I am not asking base cost related thing, literally just the electricity it consume

timber dragon
#

just trying to help, don't have to rude about it.

also notice the keywords: old, removed

tender bobcat
#

I'm not trying to be rude
I am just stating fact because I don't think you have read what I asked

tender bobcat
exotic hazel
tender bobcat
#

However, I would still recommend raspberry pi under:

  • you have reliable power
  • you have reliable and fast internet now/plan to have (independent of whether you are going to get a raspberry pi)
  • Not high electricity cost
  • plan to use for 3y or longer
toxic notch
#

Guys Can ask Some Questions 😭

#
@bot.command(name="ping")
async def ping(ctx, user: discord.Member):
    await ctx.send(f"{user.mention} Wake up!")
    await asycio.sleep(5)
    await ctx.send(f"{user.mention} Wake up!")
    await asycio.sleep(5)
    await ctx.send(f"{user.mention} Wake up!")
    await asycio.sleep(5)
    await ctx.send(f"{user.mention} Wake up!")
    await asycio.sleep(5)
    await ctx.send(f"{user.mention} Wake up!")
#

How do i make this work 😭

fast osprey
#

The base cost isn't negligible. Not selling your hardware is opportunity cost whether or not you choose to factor that in

fast osprey
toxic notch
#

Heres my question

fast osprey
toxic notch
#

Yeah ill just scrap it

tender bobcat
#

Like, you should really really consider that part before buying one

fast osprey
#

Opportunity cost is a thing that exists. You can't just say it doesn't

tender bobcat
#

I'm confused
When did I say it doesn't pithink

fast osprey
#

"No it's not"

tender bobcat
#

Oh:
No, it's not "negligible"

#

Idk how I could miss that to make it so ambiguous

#

Sorry, oops

fast osprey
#

ohhh, that read to apply to the second sentence but I see what you mean

#

nw

tender bobcat
#

lol

fast osprey
#

But yeah tbh I don't know the secondhand market for these things, how they depreciate etc etc

tender bobcat
#

Well, my not very good calculation just assume that if you ain't using it, it siting somewhere and act as a dust collector in your house/room or whatever

fast osprey
#

Ideally if you are comparing the two strategies assuming you already have one, the VPS option should be weighted assuming you could sell it

#

otherwise it's not a fair comparison

viscid hornet
tender bobcat
#

I mean, the main benefit I see for the raspberry pi is more you can host local applications and run stuff for you without need to connect outside internet (unless what you running needs it)

#

Such as I would just run PyCharm/other jetbrain ide backend on it

#

Oh yeah how can I forget this requirement:

tender bobcat
young dagger
toxic notch
#

Thank you so much

young dagger
#

Just added some conditions and a for loop. You are welcome! hattip

viscid hornet
#

start becomes 0

burnt quiver
#

just readability ig

#

real problem is he spelled asyncio wrong💔

#

though the IDE/Text editor should yell at him

#

also he forgot to await send

young dagger
# viscid hornet `start` becomes 0

It's good practice to use the start value when you're learning coding (this is why I used it for this example), But yes, range(5) works just the same

toxic notch
#

How to make the bot delete its own message but doesn't delete others message

#

I just use purge just to delete it 😭

young dagger
toxic notch
#

mb ur playing cs2

#

anyway Thanks homie

burnt quiver
#

tias

viscid hornet
viscid hornet
unkempt canyonBOT
#

await delete(*, delay=None)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Deletes the message.

Your own messages could be deleted without any proper permissions. However to delete other people’s messages, you must have [`manage_messages`](https://discordpy.readthedocs.io/en/stable/api.html#discord.Permissions.manage_messages)...
viscid hornet
#

this exists too

fast osprey
#

Alternatively use slash commands and reply ephemerally

exotic hazel
#

Ephemeral means it only appears for the person you're replying too and it can be dismissed right?

quick gust
#

it appears for the person who did the interaction

inland cradle
#

.

queen cliff
#

@vocal snow i need help

#

wait what the fuck

vocal snow
#

hi nova

#

i will help you

queen cliff
#

my bot broke

vocal snow
#

arre baapre baap send traceback

queen cliff
#

waht is that

#

how do i make slash commands in hikari

dapper ocean
#

:stare:

queen cliff
toxic notch
#

why theres 4 Nova here...

wind grove
#

the nova's are multiplying

toxic notch
#

man i cant stop making 10 generations of elif statement 😭

toxic notch
viscid hornet
toxic notch
#

still have school tho

viscid hornet
toxic notch
tender bobcat
timber dragon
#

Lots of people that know programming are young and still in school these days lol

toxic notch
#

Ok

woeful hill
#

you can manage your time :shocker:

brazen crane
toxic notch
#

Im still stuck at pagination 😭

brazen crane
#

Pagination?

toxic notch
#

yes

brazen crane
#

Like pages?

toxic notch
#

yes

tender bobcat
#

what issue you have with it?

brazen crane
#

Never done that w discord bots

#

What happendx?

toxic notch
tender bobcat
#

?wdym remembering it

brazen crane
tender bobcat
#

you mean storing the state?

toxic notch
brazen crane
#

Lol

#

Classic

tender bobcat
#

...You get exam on discord bot pagination???

toxic notch
#

No

#

Like I need to remember how it works

tender bobcat
#

all you need to remember:
you have multiple page, and you have button(or other thing) to switch page

#

other thing you just go to docs and see how to use the component, and create the logic

toxic notch
#

i think so?..

#

heres what im talking about

#

this lot

tender bobcat
#

in reality you either just have code saved from prev bot
copy from some github
or just live code it

#

you don't need to remember the exact code, there are no reason to

toxic notch
#

uh github and google colabs don't mix in well

tender bobcat
#

?

toxic notch
#

Uh google colabs does the same thing but different at the same time

#

same same but different...

tender bobcat
#

again I don't see any relation in between, github is just somewhere that store code, and google colabs is somewhere you run code

#

?

toxic notch
#

uh how do i explain this

tender bobcat
#

saying something is same and different at the same time give no context

toxic notch
#

man im so confused rn

woeful hill
#

You can also save colab notebook code to your google drive

#

¯_(ツ)_/¯

#

Isnt it save by default tho so you just have to open the old one

toxic notch
#

its not that uh i dont how to save im trying to explain uh things from github doesn't guarantee works... ig??

tender bobcat
#

Well, does your code guarantee to work? Neither

toxic notch
#

nope

tender bobcat
#

Stuff can just break

#

So your point isn't much valid

toxic notch
#

bruh

#

ill just make pagination tomorrow

tender bobcat
#

And if you are confident that your code is better than what people use and share
Live code is always an option :)

toxic notch
wise mica
woeful hill
#

What

molten bramble
#

trying to run a bot on my computer but it says this

woeful hill
#

Cd to the project folder

molten bramble
#

give me a minute my computer is being very very slow

#

got there and I put that file in my projects folder

drifting arrow
#

So you'll need to change directories to the correct directory

molten bramble
#

Ok

dusk pelican
#

I consider buying a raspberry pi 5 for hosting a dc bot

#

Or pi 6

tender bobcat
#

pi 6 don't exist yet

tender bobcat
solar marten
#

Please someone expert in vps (virtual machine) to help me. write to me privately.

tender bobcat
#

Stop spamming

vestal brook
vestal brook
#

only thing to worry about is electricity getting interrupted or the internet failing, but that rarely happens

stark ingot
#

You forgot the pip

molten bramble
#

ok

molten bramble
molten bramble
stark ingot
#

If you are just starting out making bots I recommend that you use slash commands. Prefix commands will only give you problems down the road. (Won't be able to be in more than 100 servers)

snow minnow
#

Not sure this matters, but figured I'd ask. If I want the response portion of my Discord Bot to use text-formatting like Bold/Italics etc, should I have it pull from a webpage using markdown, or html for the text-formatting?

fast osprey
#

What does "pull from a webpage" mean here

stark ingot
#

Just use discord markdown
Bold
**Bold**

snow minnow
# fast osprey What does "pull from a webpage" mean here

I'm working on my first ever Discord Bot to pull formatted text from a website. The bot will be used to provide Study Bible notes for Bible passages and I would like for the responses to retain the text-formatting of the study notes that I'll be hosting on a web page. If that makes sense.

#

That way the bot's response to something like !John 1:1 will look good instead of just being plain-text.

fast osprey
#

Where you get this text from and how you send it to discord are separate, and as said you'd use discord's markdown syntax for the latter

molten bramble
snow minnow
#

Ah okay I think I understand. I will want to source text using discords syntax and when it gets pulled into the channel it will be properly formatted.

tender bobcat
fast osprey
snow minnow
#

Appreciate the info 🙂 I'm gonna get busy getting this done. It's a big task.

#

This actually makes things a lot simpler for me too now that I don't have to create separate html pages for each book. I can just put it all in either one big text file (or more likely) individual text files.

fast osprey
#

Since it's a pretty small amount of text, local text file is fine. Heck this is small enough you could load it into memory once at startup pretty reasonably

snow minnow
#

If I were to go the route of text file. Would it be best to do one monolithic text file per chapter? Or should I do a separate text file per chapter? Or does it not matter?

fast osprey
#

Doesnt particularly matter IMO

brisk glade
#

Is there a way to make my bot work in User to User DMs / GCs? (example: like Heist, RoUtility, etc..)

fast osprey
#

You can make user installed commands that they can execute in dms yes

brisk glade
fast osprey
#

Don't see why not

brisk glade
fast osprey
#

How are you doing that? How are the commands declared?

brisk glade
fast osprey
#

But how are you making them user install?

brisk glade
fast osprey
#

No, in code

#

Commands aren't automatically set to be user installable unless you mark that in code

brisk glade
#
  1. await bot.tree.sync()
  2. bot.tree.add_command(example..())
shadow vigil
woeful hill
#

none of those make your command user install

shadow vigil
unkempt canyonBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

shadow vigil
#

they want to know if you are marking them as user slash commands as far as what im reading

fast osprey
brisk glade
#

yep

brisk glade
fast osprey
#

Don't sync in on_ready, or really do anything in it unless you understand how that event works

brisk glade
#

The question why the slash commands working in guilds, bot dms, but not in DMs / GCs

fast osprey
#

You need to stop syncing in on_ready before you do anything else

#

Or you are going to lock yourself out entirely

snow minnow
#

Right, so I've managed to finally get the first book of John typed out into Discord compatible formatting. I can read from the file. I'm just not sure how to plumb everything together to have it send me a verse when I issue a command. All I know how to do at the present time is read the entire file. What ways that are easy for a noob like me to just get the verse I want from the bot and nothing else? I'eve tried attaching the file here but it's not working so I put it here if you're interested to see what data I'm trying to get info from https://hastebin.com/share/udejuhoboc.vbnet

#

I'm trying to have my bot just give me a specific note for a verse via a command, like !John 1:1.

fast osprey
#

What part are you actively having trouble with? Setting up a bot? Making a command?

#

Also it's strongly recommended to use app (slash) commands instead of outdated text (prefix) commands

snow minnow
#

I've got a bot working. I'm just not sure what strategy is the best fit for what I'm looking to achieve.

fast osprey
#

Do you know how to make a command

#

one that just says "hello world"

snow minnow
#

Yep, I can make a command.

#

That's about the extent of my knowledge lol

#

I can create a bot, open the file and create a command and that's pretty much it for the time being.

#
from discord.ext import commands
import logging
from dotenv import load_dotenv
import os

file = open('John-1.txt', 'r')
f = file.readlines()
newList = []
for line in f:
    newList.append(line.strip())
print(newList)

load_dotenv()
token = os.getenv('DISCORD_TOKEN')

handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w')
intents = discord.Intents.default()
intents.message_content = True
intents.members = True

bot = commands.Bot(command_prefix='!', intents=intents)

@bot.event
async def on_ready():
    print(f"We are ready to go in, {bot.user.name}")

@bot.event
async def on_message(message):
    if message.author == bot.user:
        return
    await bot.process_commands(message)

bot.run(token, log_handler=handler, log_level=logging.DEBUG)```
#

This is what I've managed to do so far.

fast osprey
#

Where's the command?

snow minnow
#

Oh, I've not got that far yet as I was focusing more on opening the file and such.

fast osprey
#

then why would you say you have a command

snow minnow
#

I've got a prefix listed just not the command yet.

fast osprey
#

That's probably a good first step

snow minnow
#

Well, the reason I stalled on the command is because the command will change depending on what book I'm looking to get notes from. So for example !John 1:1 would be the command to find notes from the book of John and then if I wanted to look at notes for a verse in say, Matthew, it would then be a different command !Matthew 1:5 for example.

fast osprey
#

Then you could make multiple commands. Or one command that takes in a parameter

snow minnow
#

I wasn't sure how far to go in the code without figuring out the appropriate strategy as I'm not looking to waste a lot of time figuring a problem out only to find that it's not really helping and there is a better/less complex way heh

molten bramble
unkempt canyonBOT
snow minnow
# fast osprey And again noting this

I'm actually struggling with wanting to use a command or just have the bot act on seeing the words itself. So like if I were to just type "John 1:1" in the channel, it knows to give me the study notes for that verse.

#

Another thing I was thinking of, if the above would be too difficult. Would be to use [John 1:1] or [Matthew 2:5] meaning anything within the "[]"'s the bot can pull study notes for those verses.

#

Anyway, I changed the command to use / instead of ! and have a command:

async def hello(ctx):
    await ctx.send(f"Hello {ctx.author.mention}!")```
woeful hill
#

thats not a slash command, thats just a prefix command with forward slash as a prefix...

#

slash commands are when you type forward slash, a popup appear for you to choose a command

snow minnow
#

Oh, I see.

fast osprey
#

Bots that "try" to figure out if someone wants to invoke it rather than having a specific invocation are obnoxious more often than not

snow minnow
#

Yeah, I can see that being an issue. I may just opt for using [] instead.

fast osprey
#

what's wrong with using a command?

snow minnow
#

This bot will hopefully be used in a large apologetics server I'm in. If someone uses the / command, wouldn't it hide the command that was used?

#

If people can see the command used to invoke the bot, I think that would be best for usability sake.

fast osprey
#

/ commands very specifically make it easy to see the command that was run

#

and run it yourself

snow minnow
#

Oh! Well if it allows others to see the command you used then I'll use a command then.

#

As you can probably tell, I'm not too privy to what Discord can and cannot do lol

snow minnow
#
  File "/home/fleabeard/PycharmProjects/DiscordBot/main.py", line 15, in <module>
    client = Client(command_prefix="!", intents=intents)
NameError: name 'Client' is not defined```
#

I'm confused as to why I get this error?

sick birch
snow minnow
sick birch
snow minnow
#
  File "/home/fleabeard/PycharmProjects/DiscordBot/main.py", line 36, in <module>
    @client.tree.command(name="hello", description="Test slash command.", guild=GUILD_ID)
AttributeError: 'Client' object has no attribute 'tree'```
fast osprey
#

Clients don't come with a tree made for you

viscid hornet
snow minnow
#

Yeah, I was following a guide that was 8 months old. Apparently a lot has changed between then and now lol

woeful hill
#

not in term of Client and Bot

#

you can still define the CommandTree for Client, it's 1 more line of code

fast osprey
#

client never had a tree attached

snow minnow
fast osprey
#

You shouldn't be syncing in on_ready

#

whatever guide you're following is awful and not official

woeful hill
#

you made a class but didnt use it

fallen tangle
#

one of y'all should make a server where people can invite there discord bots and show them off lol

woeful hill
#

wait why are client and bot mixed together

snow minnow
woeful hill
#

whatever guide youre following, its probably a bad one
this is the official example of discord.py slash command
also i would suggest you learn a bit of python first, like making simple command line program to get at least the basics, and continue from there for more python knowledge

snow minnow
#

Thanks, yeah I'm going slow and trying supposed easy steps along the way lol

#

The project I'm trying to achieve is supposedly very simple to most people.

#

I'm pleased with how easy it was to get the bot to go online and join my server lol

#

Nothing has caught on fire yet, so that's a big win for me.

snow minnow
#

I think I got slash commands working. I just started over completly.

#
from discord.ext import commands
from discord import app_commands
import logging
from dotenv import load_dotenv
import os

#grab discord taken from .env file
load_dotenv()
token = os.getenv('DISCORD_TOKEN')

#basic logging for our project
handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w')

#setting up intents our bot needs for discord
intents = discord.Intents.default()
client = discord.Client(intents=intents)

#manually specify intents that we need
intents.message_content = True
intents.members = True
client = discord.Client(command_prefix="!", intents=intents)
tree = app_commands.CommandTree(client)

@client.event
async def on_ready():
    print(f"{client.user.name} has logged in successfully")
    await tree.sync()

@tree.command(name='ping', description='Use it to check bots latency')
async def ping(interaction: discord.Interaction):
    await interaction.response.send_message(f"Pong! Latency: {round(client.latency*1000)}ms")

@tree.command(name="hello", description="Test slash command!")
async def hello(interaction: discord.Interaction):
    await interaction.response.send_message(f"Hello {interaction.user.mention} how are you?")

#run the bot
client.run(token, log_handler=handler, log_level=logging.DEBUG)

fast osprey
#

you should not be syncing in on_ready, or you are going to lock your bot out of publishing slash commands

#

on_ready happens randomly and frequently

snow minnow
#

Are you saying to remove the await tree.sync() from the on_ready?

#

Or, should it go somewhere else entirely?

fast osprey
#

you should be syncing your tree only when you decide you want to

#

it's a heavily rate limited operation

snow minnow
#

When would you suggest one should sync their tree? I've not the foggiest idea of when/where it is appropriate. I just know all tutorials see to do exactly what I have done.

fast osprey
#

yeah because they have no idea what they're doing

#

it's entirely up to you where you put it, because it should be your choice when it happens

snow minnow
#

Ok, I'll comment my code to mention it may need to move out of the on_ready portion at some point unitl I can fully understand what's going on lol

fast osprey
#

If you leave it in there, again, you will lock yourself out of that API

snow minnow
#

Welp, better look into what on_start and syncing tree means in a broader sense than what I know of now (which isn't much! lol)

#

I hope I'm safe for now as I don't run the bot but a few minutes for testing.

fast osprey
#

Or you could just remove it thonk

snow minnow
#

I've been at this for 2 full days now lol. I think it's time to take a break 😄 Thanks for all your help.

molten bramble
#

my code for my bot it has ban, kick, mute, unmute, unban, clear warning maybe

burnt quiver
#

and use threads for tickets

#

and

#

make sure to handle errors

molten bramble
#

Ok

#

anything else?

burnt quiver
#

oh yeah don't sync in on_ready, use a command

#

also wait what, why do you have two bot.run and importing twice

molten bramble
#

I have vscode open and did ctrl f and there is only 1 bot.run

burnt quiver
#

use asqlite for asynchronous sql

#

sorry, forgot to mention that earlier

#

also, you should use user_id as a PRIMARY KEY so it allows for indexing -> Faster lookup

tender bobcat
molten bramble
#

This is my first discord bot that I wrote the code for

fast osprey
#

I also suggest you don't make commands which are only thin wrappers on discord functionality that already exists. It adds nothing while reducing security and auditing

molten bramble
#

Ok

burnt quiver
tender bobcat
#

Oh nice

molten bramble
full ether
#

do @silent messages behave any differently when composed by bots?

burnt quiver
#

But yeah other then that ig it works the same

tender bobcat
#

Like how auto text->emoji work such as :)

earnest mantle
#

a bot cant timeout someone who has the permission administrator?

stark ingot
#

No, administrators cannot be timed out

earnest mantle
tender bobcat
molten bramble
#

C:\Users\honem\Downloads\discord_bot_with_packages>python mod_bot.py
Traceback (most recent call last):
File "C:\Users\honem\Downloads\discord_bot_with_packages\mod_bot.py", line 12, in <module>
GUILD_ID = int(os.getenv("1290077081325277206s")) # Ensure this is set in your .env file
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

C:\Users\honem\Downloads\discord_bot_with_packages>
https://hastebin.com/share/obugiwigeb.python code

tender bobcat
#

The environment variable you refer to doesn't exist

#

!paste next time use this instead of whatever other pastebin in this server, thx

unkempt canyonBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

stark ingot
tender bobcat
#

If it's on the same member

#

!d discord.Member

#

!d discord.Member.remove_roles

unkempt canyonBOT
#

await remove_roles(*roles, reason=None, atomic=True)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Removes [`Role`](https://discordpy.readthedocs.io/en/stable/api.html#discord.Role)s from this member.

You must have [`manage_roles`](https://discordpy.readthedocs.io/en/stable/api.html#discord.Permissions.manage_roles) to use this, and the removed [`Role`](https://discordpy.readthedocs.io/en/stable/api.html#discord.Role)s must appear lower in the list of roles than the highest role of the client.
stark ingot
#

Yeah you are right, was not seeing the Modify Guild Member in the discord docs.

earnest mantle
#

what if i pre loaded the roles that has admin upon turning the bot on or upon joining a guild

woeful hill
#

You don't need a bot to do anti nuke, when the bot offline and someone nuking your server its over

earnest mantle
#

it’s a public discord bot

#

it isn’t for me

woeful hill
#

Then it is even more of a problem

#

People looking for anti raid, anti nuke bots because they are too lazy to setup their server correctly so it would not happen in the first place

burnt quiver
#

Real

toxic notch
#

Can someone tell me whats the problem in my code? it doesn't error and doesn't work :(

async def on_message(message):
    if bot.user.mentioned_in(message):
        await message.reply("Hello, you mentioned me! 😊")

    await bot.process_commands(message)
#

there's nothing wrong with it 😭

burnt quiver
toxic notch
burnt quiver
#

are you able to even listen for message eventse

toxic notch
#

im new to bot.events i only know commands

burnt quiver
toxic notch
burnt quiver
wise mica
#

There have been several big servers that have been hit this way

burnt quiver
#

you do realise you can't do anything to a server owner

wise mica
#

I suppose that's true, but my statement is still true of moderators of those servers

woeful hill
#

if a moderator got their account compromised well idk what else to say

#

anyways my point is, you rather prevent it than fixing it when it already happened

timber dragon
#

Can't really prevent a moderator from being compromised or going rogue, can you? Unless you got a glass bowl thing that can look into the future lol

woeful hill
#

I mean you got the point, choose what you trust

toxic notch
viscid hornet
#

!d discord.Client.user

unkempt canyonBOT
viscid hornet
#

hm indeed it is

viscid hornet
#

did you restart your bot?

toxic notch
#

i just gave up and made it command

viscid hornet
viscid hornet
tender bobcat
#
  1. Does the bot have message_content intent (You have to enable this in discord developer portal)
  2. Did you told the bot it have message_content intent? (intent = discord.Intents.all() or intent.message_content = True)
  3. Did the bot have the right to receive&send the message on the channel
quick gust
#

Don't think the bot needs message content intent to see the contents of the message it is being mentioned in

tender bobcat
#

Oh right I forgot

#

It was mention🥴

#

My brain just didn't notice that part when I wrote the message

toxic notch
#

@commands.cooldown(1, 10, commands.BucketType.user)
how to edit the msg that say ths command is on cd

burnt quiver
#

wait

toxic notch
burnt quiver
#

well you can't "rename"

burnt quiver
toxic notch
#

sorry for ping

burnt quiver
#

wdym?

woeful hill
#

You have the ctx, you can choose to just ignore it or reply with an fancy message saying its currently on cooldown

woeful hill
#

Im replying to you

#

:icant:

toxic notch
woeful hill
#

So, you have ctx, you can send/reply whatever you want using that ctx

#

If that what you mean "custom"

toxic notch
#

the very bottom

#

CommandOnCooldown

burnt quiver
burnt quiver
#

You can send whatever message you want

toxic notch
#

does it work if its on cd?

patent hull
#

Yes

#

That is the point lol

burnt quiver
#

:stab:

toxic notch
#

nope

burnt quiver
#

😔 Command_name is the name of the command

#
@bot.command()
async def ping(ctx) -> None:
    ...

@ping.error
...
toxic notch
#

mb

#

um

#

AttributeError: 'Command' object has no attribute 'CommandOncooldown'

burnt quiver
#

I think I mispelled it, check the docs

toxic notch
#

its google colabs itself i think

burnt quiver
#

I did

#

CommandOnCooldown is the correct one

toxic notch
burnt quiver
#

CommandOncooldown != CommandOnCooldown

toxic notch
#

i see..

#

mb blurry eye

#

idk wut to do anymore

tender bobcat
#

Did you redefine commands somewhere

#

discord.ext.commands should be a module, not a Command object

toxic notch
tender bobcat
#
>> from discord.ext import commands
>>> commands
<module 'discord.ext.commands' from '/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.13/site-packages/discord/ext/commands/__init__.py'>
>>> commands.NOT_EXIST_THING
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    commands.NOT_EXIST_THING
AttributeError: module 'discord.ext.commands' has no attribute 'NOT_EXIST_THING'
#

This is what you would see normally

#

So you must have re-defined commands in some way

toxic notch
#

uh i saw different

tender bobcat
#

I don't know how you have re-defined it because I cannot see your code

toxic notch
#

and this is the command anyway

#
 @commands.error
async def command_name_error(ctx, error):
    if isinstance(error, commands.CommandOnCooldown):
        await ctx.send("Youre on Cooldown", delete_after=5)
tender bobcat
#

We would need to see the whole code to debug this

#

But you might have make a command where the name call commands

#

Which would cause the exact issue you see here

fast osprey
#

Anything in this file above that code could have redefined what commands refers to

toxic notch
#

hol up

fast osprey
#

On a higher scope than the error, yes, but not in the same scope

toxic notch
tender bobcat
#

You overwrite the commands module with the commands Command

#

Therefore you cannot use the commands module

fast osprey
#

What you name things matters, you don't want to name any variables/functions/classes the same as anything else you're using (like an imported module)

toxic notch
#

I gotta rename the commands command?

tender bobcat
#

Yes

toxic notch
#

oh

burnt quiver
#

just use the kwarg in bot.command

fast osprey
#

Or import the module under an alias

toxic notch
#

wait leme try

#

it works after i renamed it to list

burnt quiver
#

isn't

@bot.command(name="commands", aliases...)
async def prefix_command(ctx...) -> None:

easier

toxic notch
#

uh idk

burnt quiver
#

all you'd have to do is change the function name

#

if you define the name kwarg in bot.command(), it will overide the function name

#

-# Idk if I'm making this more confusing

tender bobcat
burnt quiver
#

yes thanks, I think that's much easier to understand lol

toxic notch
#

uh

#

Anyway

#

Thank you guys for your help

#

i really really appreciated it

#

-# chatgpt just made it more confusing ngl

fast osprey
#

chatgpt thinks 3 isn't a prime number. You need to stop using it if you want to actually progress

toxic notch
#

i only use it if im stuck then ask yall here if possible

#

so i just go there for the code

tender bobcat
molten bramble
snow minnow
#

Alright friends, I have a discord bot now working that can take / slash-commands. How should I go about taking this command and having the bot search a local text file and reply with the appropriate info?

async def test(interaction: discord.Interaction):
    await interaction.response.send_message(f"How cool would it be if this was a Bible verse pulled from a text file?")```
#

I'm hoping to use a command structure like [text-to-be-searched] if that makes sense?

fast osprey
#

How much memory does the text file hold? How would you search for it?

#

you could just load it once into memory at startup rather than reopening the file every time someone runs the command if it's small enough

snow minnow
#

I'm certain that once the text file is 100% completed, it will fit more than comfortably in RAM.

fast osprey
#

How much ram do you have

snow minnow
#

8GB

fast osprey
#

The entirety of the english bible is around 5 MB

snow minnow
#

Yeah, this will probably be just a bit under 5MB once completed as it's just study notes for most not all verses 🙂

fast osprey
#

Soooo how will it not fit into memory thonk

snow minnow
#

No, I said it will fit more than comfortably in RAM 😄

fast osprey
#

oh then just do that

snow minnow
#

So how does one accomplish that exactly? Would I just be opening the text file into RAM in Python? I'm very much a newbie to not only Python but Discord overall lol

fast osprey
#

The simplest bit is yeah just read the file into memory, store it in a string

#

Depending on what you want to do with it, you could do something more complex

snow minnow
#

Cool!

fast osprey
#

Like you could bucket it into verses, like with a str : str dictionary

snow minnow
#

Thanks, I'll get to googling how to read the file into memory and storing it in a string.

snow minnow
#

Oh, that is my old code I've since abandoned lol. So does this:

f = file.readlines()
newList = []
for line in f:
    newList.append(line.strip())
print(newList)```

Load the text into memory and store it as a string?
fast osprey
#

Well, as a list of strings for each line

#

but yes you'll have all of the text in memory at that point

snow minnow
#

Nice! I'm almost there then haha thanks

#

I'm not sure if a list of strings for each line is the best approach. Or if I should do it some other way that's more effective that I'm not aware of.

fast osprey
#

It again depends on what you want to do with this text

#

If it's just for a lookup of verse name -> corresponding text, a dictionary that maps a string (verse name) to a string (its text) seems appropriate

snow minnow
#

Oh, I just want the bot to give me info from that list for a specific verse. So if I type [John 3:16] It will give me the study notes appropriate for that verse.

fast osprey
#

Then yeah I'd recommend using a dictionary for this

#
#populate the dictionary

all_text = ... #somehow load all of the text. If it's already split up for you by verse, great, if not you'll have to do it somehow
verse_map = {}
for x in ...:
  verse_map[verse_name] = verse_text


#in your command
await interaction.response.send_message(verse_map[the_verse_they_want])
snow minnow
fast osprey
#

A dictionary is just a mapping of one object to another

#

it's your choice what those objects are

snow minnow
#

Thanks, I really appreciate your helping me in this. I'll study up on dictionaries in python 🙂

#

Interesting, dictionaries seem a whole lot like sql lol

fast osprey
snow minnow
#

The key/value pairs is what gives me sql vibes lol