#discord-bots

1 messages ยท Page 127 of 1

loud junco
#

Oo ignore the time

#

It's according to GMT0 I believe

vestal pine
#

oh ok, thank you

#

but its weird cuz like before it was always same as my time ๐Ÿ˜ญ

loud junco
vestal pine
#

ok now it stopped working again

loud junco
#

Offline?

#

Or what

vestal pine
#

yes

loud junco
#

Go to the uptimerobot website

vestal pine
#

uptime robot?

loud junco
#

Yeye

vestal pine
#

alr

#

I am on there

loud junco
vestal pine
#

sure

loud junco
#

The link especially

vestal pine
loud junco
#

Try running it again

vestal pine
#

alright

loud junco
#

See if it's rate limited or something

vestal pine
loud junco
#

Ye

vestal pine
#

๐Ÿ’€

loud junco
#

Rate limited

#

Gotta wait for a few hours before u can start it again

#

It happens in replit quite frequently

vestal pine
#

oh ok

loud junco
#

And u can't do anything to stop it

vestal pine
#

should I make a new repl and copy paste the code?

loud junco
#

It won't work

vestal pine
#

oh ok

loud junco
#

Just wait

#

What I do is I have two bot

#

When one is rate limited I build the other one

#

Btw can anyone give me suggestion?

#

Should I use image as the Monopoly board like myuu. I have no experience in image stuff tho

vestal pine
#

hm?

loud junco
#

But using emoji as board is not going to work cuz there is going to be like 4 players

#

So the board is going to be like 14 x 14 or even bigger

vestal pine
#

i guess using an image gonna be better but there is the problem that the bot should have to change the picture by every move? ||I am not that experienced||

loud junco
#

But I think I should ask the professional before doing anything silly ๐Ÿ˜‚๐Ÿ˜‚๐Ÿ˜‚

vestal pine
#

^^

loud junco
#

Come out proffesionals

vestal pine
#

i guess am gonna run my bot locally till replit works again, because I am testing new things ๐Ÿ˜ญ

vestal pine
slate swan
#

repel it ๐Ÿ˜

vestal pine
#

never heard of it tbh

vestal pine
slate swan
#

Yeah itโ€™s a somewhat hidden gem

#

I know a bot dev uses it for his decently sized bot and has never had issues

vestal pine
#

wow

slate swan
#

and itโ€™s always free

#

crazy huh

vestal pine
#

fr lmao

lament depotBOT
vestal pine
#

whats this

#

oh nvm

vestal pine
loud junco
#

Should I use image as the Monopoly board like myuu. I have no experience in image stuff tho

slate swan
#

You're trying to make a bot play Monopoly?

loud junco
#

and its going to be more than 2-6 players

#

so emoji map doesnt work

#

i was thinking about adding the token on the map

#

add token and add house + hotel

#

on a default map

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 floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.

slate swan
# loud junco on a default map

I think you can use an image of the map and just update the image after each turn. Perhaps you could start by learning an image manipulation lib such as PIL to achieve this

radiant parrot
#

How would I get all the channels names under a category?

vocal snow
#

!d discord.CategoryChannel.channels

unkempt canyonBOT
#

property channels```
Returns the channels that are under this category.

These are sorted by the official Discord UI, which places voice channels below the text channels.
vocal snow
#

You can use a list comp and get the name attribute of all the objects in that

radiant parrot
#

Ah okay

#

Secondly how would I grab a few things from an embed and foward them

loud junco
radiant parrot
loud junco
#

send the description of an embed?

radiant parrot
#

I only want to grab certain things from the embed if it contains a word

loud junco
#

oo

radiant parrot
#

So if the title contains testing for example it will grab the whole title ๐Ÿ™‚

radiant parrot
loud junco
#

!d discord.Embed.description

unkempt canyonBOT
#

The description of the embed. This can be set during initialisation. Can only be up to 4096 characters.

loud junco
#

!d discord.Embed.title

unkempt canyonBOT
#

The title of the embed. This can be set during initialisation. Can only be up to 256 characters.

radiant parrot
loud junco
radiant parrot
naive briar
#

Show how did you do it

radiant parrot
#
@client.event
async def on_message(message):
    if message.webhook_id and message.embeds:
        embed = message.embeds[0]
        channel = client.get_channel('1039871964745152161')
        embed.remove_footer()    
        await channel.send(embed=embed)```
#

it shld be removing the footer yet isnt somehow

loud junco
#

!d discord.Embed.footer

slate swan
#

attributes don't come out of thin air, there's no such method

loud junco
#

!d discord.Embed.remove_footer

unkempt canyonBOT
#

remove_footer()```
Clears embedโ€™s footer information.

This function returns the class instance to allow for fluent-style chaining.

New in version 2.0.
slate swan
#

nvm

loud junco
#

๐Ÿคฃ

slate swan
naive briar
#

!d discord.Client.get_channel

unkempt canyonBOT
#

get_channel(id, /)```
Returns a channel or thread with the given ID.

Changed in version 2.0: `id` parameter is now positional-only.
slate swan
#

and the if statement is faulty as well

#

why would a webhook id be a part of list of embeds

radiant parrot
#

the channel id is the channel i want the copied embed to be sent in

slate swan
#

ids are integers, not strings?

radiant parrot
#

i have changed tht

slate swan
radiant parrot
#

but get this py TypeError: get_channel() takes 2 positional arguments but 3 were given

slate swan
#

now you added something that shouldn't be there

radiant parrot
#

wait i fixed it

#

so how would i now grab certain content from an embed to copy

slate swan
#

check the part of embed that data belongs to

slate swan
loud junco
#

i forgot what is it called

naive briar
unkempt canyonBOT
#

property fields```
Returns a [`list`](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.11)") of `EmbedProxy` denoting the field contents.

See [`add_field()`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Embed.add_field "discord.Embed.add_field") for possible values you can access.

If the attribute has no value then `None` is returned.
loud junco
#

is it counted as description?

naive briar
#

I don't know what do you mean

loud junco
slate swan
#

nope

loud junco
#

should i host my bot on oracle cloud

slate swan
#

id just do "text" in json.dumps(embed.to_dict()) to check if something is in the embed

#

if i don't know what part it exists in*

slate swan
loud junco
#

myex.dumps(me)

loud junco
slate swan
loud junco
#

like the best free option

loud junco
slate swan
loud junco
#

i dont have it ๐Ÿ’€

slate swan
#

are you a student?

slate swan
#

just copy paste with replacing text with your string and embed with the embed object you want to check in

radiant parrot
#

so can understand better

loud junco
slate swan
radiant parrot
#

like in a sense

slate swan
# loud junco ye

go on the above link, fill in the info to join GitHub students
it gives you access to tons of developer tools for free ( that are usually paid)
only if you want to ofc

mighty pilot
#

There is no guild specified

radiant parrot
mighty pilot
#

Show your code

#

Is GUILD_ID a number or is it just that

velvet tinsel
#

Okay, I take a break from discord.py and this shit happens

[2022-11-09 13:28:53] [INFO ] discord.client: logging in using static token

wtf? I'm using the correct token ๐Ÿ’€

velvet tinsel
mighty pilot
#

It's just telling you that it's logging into the bot with a static token

velvet tinsel
#

why do I need privileged intents?

#
discord.errors.PrivilegedIntentsRequired: Shard ID None is requesting privileged intents that have not been explicitly enabled in the developer portal. It is recommended to go to https://discord.com/developers/applications/ and explicitly enable the privileged intents within your application's page. If this is not possible, then consider disabling the privileged intents instead.
mighty pilot
#

!tag intents

unkempt canyonBOT
#

Using intents in discord.py

Intents are a feature of Discord that tells the gateway exactly which events to send your bot. By default discord.py has all intents enabled except for Members, Message Content, and Presences. These are needed for features such as on_member events, to get access to message content, and to get members' statuses.

To enable one of these intents, you need to first go to the Discord developer portal, then to the bot page of your bot's application. Scroll down to the Privileged Gateway Intents section, then enable the intents that you need.

Next, in your bot you need to set the intents you want to connect with in the bot's constructor using the intents keyword argument, like this:

from discord import Intents
from discord.ext import commands

intents = Intents.default()
intents.members = True

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

For more info about using intents, see the discord.py docs on intents, and for general information about them, see the Discord developer documentation on intents.

velvet tinsel
slate swan
#

you using message_content intents?

velvet tinsel
#

finally it's working

#

why do I need privileged intents

mighty pilot
velvet tinsel
#

I just created this bot

velvet tinsel
mossy jacinth
#

can someone help me here or tell me how to make an Trivia command without a lib?

velvet tinsel
#

nvm

mighty pilot
#

In the developer portal, there's 3 toggles for different intents that need to specifically be enabled

velvet tinsel
#

I read it wrong, thought it meant that you should enable it if your bot is in 100+ servers

mighty pilot
#

Ah no they'd just need verification beyond that

mighty pilot
mossy jacinth
mighty pilot
#

Oh I read the error wrong. Sorry not familiar with that library

mossy jacinth
#

neither am i.. just wanted to see if it would be simpler to use a lib to create a trivia command

placid skiff
#

what is that lib, and where do you use it? it is in conflict with asyncio

placid skiff
#

It has installed and probably it has using cffi which is a C interface for python

mossy jacinth
#

So i cant use it?

placid skiff
#

cffi uses PyPy, which is another C implementation

#

and PyPy doesn't support asyncio, so you will not be able to use it

mighty pilot
#

This is what that error means according to the docs for nextcord

In user defined base classes, abstract methods should raise this exception when they require derived classes to override the method, or while the class is being developed to indicate that the real implementation still needs to be added.

radiant parrot
#

How would i get rid of an embed field when converted embed to dict

mossy jacinth
#

then can someone tell me how i can at least make a trivia/quiz command?

placid skiff
#

you can try to learn more and maybe find a solution in #c-extensions channel

mighty pilot
drowsy atlas
#

hi! can I get some suggestions on creating a bot with python. links to documentation would be great.

mossy jacinth
mighty pilot
#

I would make it so it checks the reply to the message for an answer, if the answer matches correct answer, it's correct. If not, incorrect

upbeat otter
#

an id has to be an integer, strings wont work

slate swan
#

except for fetch_ methods

upbeat otter
#

yes yes, godly piece of advice ๐Ÿ›

slate swan
#

yes

#

you can also just pip uninstall python and uninstall discord to make life easier

radiant parrot
# slate swan yes

i have got the embed in a dict but how would i know remove a specific field

slate swan
unkempt canyonBOT
#

property fields```
Returns a [`list`](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.11)") of `EmbedProxy` denoting the field contents.

See [`add_field()`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Embed.add_field "discord.Embed.add_field") for possible values you can access.

If the attribute has no value then `None` is returned.
slate swan
#

uhhhhhh 1 min

upbeat otter
slate swan
#

actually list.remove works it gets that from the parent class which is not documented

slate swan
upbeat otter
#

๐Ÿ˜ณ

slate swan
#

hola amigo como estas
this is not related to discord bot but a text based bot,
i am trying to implement a fight() between two characters, like more popular bots out there (dank memer) however, there fight is between 2 real players, my fight is between 1 player and 1 enemy, the player is supposed to defeat the enemy using text based commands, can someone kindly help me design a logic as so how the enemy will attack the player and how so the player would attack the enemy

slate swan
#

lmao sarth is just an internet alias, my name's sarthak as well

slate swan
#

but no, because people like you and me exist-

#

but hey sarthak! i am sarthak sidhant!

slate swan
#

!d discord.Client.wait_for

unkempt canyonBOT
#

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

Waits for a WebSocket event to be dispatched.

This could be used to wait for a user to reply to a message, or to react to a message, or to edit a message in a self-contained way.

The `timeout` parameter is passed onto [`asyncio.wait_for()`](https://docs.python.org/3/library/asyncio-task.html#asyncio.wait_for "(in Python v3.11)"). By default, it does not timeout. Note that this does propagate the [`asyncio.TimeoutError`](https://docs.python.org/3/library/asyncio-exceptions.html#asyncio.TimeoutError "(in Python v3.11)") for you in case of timeout and is provided for ease of use.

In case the event returns multiple arguments, a [`tuple`](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.11)") containing those arguments is returned instead. Please check the [documentation](https://discordpy.readthedocs.io/en/latest/api.html#discord-api-events) for a list of events and their parameters.

This function returns the **first event that meets the requirements**...
slate swan
slate swan
#

plain python, how the user gonna fight, what the perimeters, what the fight seqeuenee

#

ill definitely make this in a discord bot later, therefore asked about it here

slate swan
slate swan
placid skiff
#

do you guys type with fingers?

slate swan
slate swan
upbeat otter
upbeat otter
slate swan
upbeat otter
#

tf

#

average JEE aspirant

placid skiff
#

Man please.
At least ashley will not read that D_D

slate swan
#

there's morning timings too but it's mostly for girls

placid skiff
#

Lol

upbeat otter
slate swan
upbeat otter
#

based

placid skiff
#

Well, at least do yourself a favour and let become your d... the famous guy

velvet compass
#

Lets stop whatever the hell this is

upbeat otter
#

lmao

placid skiff
slate swan
#

who wants to make a dc bot with me?

#

Exception has occurred: ImportError
cannot import name 'handle_message_parameters' from 'discord.http' (C:\Users\gosia\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\http.py) help?

upbeat otter
#

might be some installation issue

upbeat otter
slate swan
slate swan
winged coral
#

how

#

And what other discord related packages have you installed

tight obsidian
versed comet
#

does anyone have a ticket system that uses thread? please i need this script

cloud dawn
#

Maybe

mighty pilot
#

Forgot to un-ping my bad

cloud dawn
#

Sarth doesn't mind.

mighty pilot
#

I know some people get pretty upset about it and I'm usually good about turning it off if it's not in reply to something recent

slate swan
#

lol im mostly in the channel so it doesn't matter if you ping or not

mighty pilot
#

Alright @slate swan

cloud dawn
mighty pilot
#

Yea the notifications for it

ionic garden
#

and it only allowed me to select one

mighty pilot
#

max_values = 1

spring needle
#

How to obtain message id from the user who send command

mighty pilot
slate swan
spring needle
#

I want to do something when a user type /example the bot will send a dm to the user who sent /example

upbeat otter
slate swan
#

explain me please

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.

The content must be a type that can convert to a string through `str(content)`. If the content is set to `None` (the default), then the `embed` parameter must be provided.

To upload a single file, the `file` parameter should be used with a single [`File`](https://discordpy.readthedocs.io/en/latest/api.html#discord.File "discord.File") object. To upload multiple files, the `files` parameter should be used with a [`list`](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.11)") of [`File`](https://discordpy.readthedocs.io/en/latest/api.html#discord.File "discord.File") objects. **Specifying both parameters will lead to an exception**.

To upload a single embed, the `embed` parameter should be used with a single [`Embed`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Embed "discord.Embed") object. To upload multiple embeds, the `embeds` parameter should be used with a [`list`](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.11)") of [`Embed`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Embed "discord.Embed") objects. **Specifying both parameters will lead to an exception**.
cloud dawn
unkempt canyonBOT
#

@cloud dawn :white_check_mark: Your 3.11 eval job has completed with return code 0.

False
spring needle
upbeat otter
slate swan
cloud dawn
upbeat otter
spring needle
#

Kk

slate swan
mighty pilot
upbeat otter
slate swan
#

what mean ==

slate swan
slate swan
slate swan
upbeat otter
mighty pilot
slate swan
upbeat otter
slate swan
#

its more fun that being home ๐Ÿ—ฟ

#

anyways its getting ot lol

cloud dawn
#

On topic

slate swan
#

so i wanna make that the user that opened the ticket will get a dm after a staff member closes the ticket, interaction.user doesnt work there cuz the staff did the interaction

upbeat otter
# slate swan anyways its getting ot lol

totally not our fault, the discord api wrappers need to make their libraries more complicated to use so that more people and more beginners will ask for help in the channel.

the implementation in many libraries is too easy so far and people opt for those. There aren't enough problems to solve regarding discord bots, it's usually the problems related to "discord.py not found" or "why this not work" which are 99% of the times syntax errors and are not suitable for the channel but are "This error is in a discord bot".

Technically, this channel can be used as an OT channel, but the roles oppose this statement. Sadly.

#

You just wasted 15 seconds of your life reading that message ๐Ÿ˜” no comments if you read that actually

slate swan
# upbeat otter totally not our fault, the discord api wrappers need to make their libraries mo...

well, that is because andy is very smart in the aspect of developing. so when andy explains something to someone who doesnt have the same knowledge, it may be looked at as confusing because andy is explaining something with the assumption it can be understood as simply as he/she understands the topic. so yeah it creates confusion. thats why you ask more and more. the more you ask the more you know. dont walk away misunderstanding the topic because one explanation didnt give you the knowledge needed. im sure andy would have been willing to break down the explanation.

slate swan
upbeat otter
#

tf you people still simp for andy

slate swan
#

like the channel description or in a dictionary

slate swan
#

cuz it was in this channel itself

upbeat otter
#

yes

upbeat otter
slate swan
# slate swan w db?

you won't need a database if the ticket isn't supposed to be opened for too long, but yes thats the preferred way

slate swan
spring needle
#

Hereโ€™s my cog, it says that collab function doesnโ€™t exist

#

Here is the extension loader

#

Rate limitedโ€ฆ

placid skiff
#

commands name can't have uppercase letters, the name parameter too is all lowercase

cloud dawn
#

Actually command names can have uppercase in message commands.

#

And since kwarg passed doesn't exists it gets disregarded so the function name will be used.

#

So we need the traceback chief.

spring needle
spring needle
slate swan
sick birch
nocturne compass
#

how do i add this on replit

cloud dawn
#

Don't

#

That lib very bad

nocturne compass
#

i need to

#

i need to

#

how to add to replit pls

sick birch
nocturne compass
#

it wont work tho

#

i js need it how do i add it

cloud dawn
#

I recommend not following that tutorial.

sick birch
#

Isn't discord_slash discontinued?

cloud dawn
#

Last update on Feb 4, 2021

alpine cove
#

lmao

alpine cove
#

just dont

sick birch
cloud dawn
rustic edge
#

How can I make an arg optional?

cloud dawn
#

!arg-kwarg

unkempt canyonBOT
#

*args and **kwargs

These special parameters allow functions to take arbitrary amounts of positional and keyword arguments. The names args and kwargs are purely convention, and could be named any other valid variable name. The special functionality comes from the single and double asterisks (*). If both are used in a function signature, *args must appear before **kwargs.

Single asterisk
*args will ingest an arbitrary amount of positional arguments, and store it in a tuple. If there are parameters after *args in the parameter list with no default value, they will become required keyword arguments by default.

Double asterisk
**kwargs will ingest an arbitrary amount of keyword arguments, and store it in a dictionary. There can be no additional parameters after **kwargs in the parameter list.

Use cases
โ€ข Decorators (see !tags decorators)
โ€ข Inheritance (overriding methods)
โ€ข Future proofing (in the case of the first two bullet points, if the parameters change, your code won't break)
โ€ข Flexibility (writing functions that behave like dict() or print())

See !tags positional-keyword for information about positional and keyword arguments

rustic edge
#

ty

cloud dawn
#

Setting a default value will make it optional.

rustic edge
#

Wdym default value?

#

ooh i see, ty

cloud dawn
#

Example: ```py
def test(word: str = "Hello!") -> str:
return word + " World!"

print(test())
print(test("Flat"))

unkempt canyonBOT
#

@cloud dawn :white_check_mark: Your 3.11 eval job has completed with return code 0.

001 | Hello! World!
002 | Flat World!
rustic edge
#

async def commandlist(ctx, arg = 'None'):
    
    if arg == 'None':
        await ctx.send('!bread, !catcutie, !breadedcat, !sunglassescat')```
#

would be correct?

cloud dawn
#

Is this a self bot?

rustic edge
#

nope

cloud dawn
#

Oh no nvm, yeah I'd say so, but there is a help subclass for this.

rustic edge
#

Yep it worksd! tysm

slate swan
#

Traceback (most recent call last):
File "/home/container/bot.py", line 1, in <module>
import discord
ModuleNotFoundError: No module named 'discord'

mighty pilot
#

pip install discord.py (or other module)

rustic edge
#

!dm

unkempt canyonBOT
#

Dunder methods

Double-underscore methods, or "dunder" methods, are special methods defined in a class that are invoked implicitly. Like the name suggests, they are prefixed and suffixed with dunders. You've probably already seen some, such as the __init__ dunder method, also known as the "constructor" of a class, which is implicitly invoked when you instantiate an instance of a class.

When you create a new class, there will be default dunder methods inherited from the object class. However, we can override them by redefining these methods within the new class. For example, the default __init__ method from object doesn't take any arguments, so we almost always override that to fit our needs.

Other common dunder methods to override are __str__ and __repr__. __repr__ is the developer-friendly string representation of an object - usually the syntax to recreate it - and is implicitly called on arguments passed into the repr function. __str__ is the user-friendly string representation of an object, and is called by the str function. Note here that, if not overriden, the default __str__ invokes __repr__ as a fallback.

class Foo:
    def __init__(self, value):  # constructor
        self.value = value
    def __str__(self):
        return f"This is a Foo object, with a value of {self.value}!"  # string representation
    def __repr__(self):
        return f"Foo({self.value!r})"  # way to recreate this object


bar = Foo(5)

# print also implicitly calls __str__
print(bar)  # Output: This is a Foo object, with a value of 5!

# dev-friendly representation
print(repr(bar))  # Output: Foo(5)

Another example: did you know that when you use the <left operand> + <right operand> syntax, you're implicitly calling <left operand>.__add__(<right operand>)? The same applies to other operators, and you can look at the operator built-in module documentation for more information!

rustic edge
#

!direct-message

#

!directmessage

maiden fable
#

!d discord.User.send @rustic edge

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.

The content must be a type that can convert to a string through `str(content)`. If the content is set to `None` (the default), then the `embed` parameter must be provided.

To upload a single file, the `file` parameter should be used with a single [`File`](https://discordpy.readthedocs.io/en/latest/api.html#discord.File "discord.File") object. To upload multiple files, the `files` parameter should be used with a [`list`](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.11)") of [`File`](https://discordpy.readthedocs.io/en/latest/api.html#discord.File "discord.File") objects. **Specifying both parameters will lead to an exception**.

To upload a single embed, the `embed` parameter should be used with a single [`Embed`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Embed "discord.Embed") object. To upload multiple embeds, the `embeds` parameter should be used with a [`list`](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.11)") of [`Embed`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Embed "discord.Embed") objects. **Specifying both parameters will lead to an exception**.
rustic edge
#

ty lol

mighty pilot
#

What is nonce used for

#

Just seeing if the message was successfully sent?

slate swan
naive briar
mighty pilot
honest shoal
mighty pilot
#

Yea it sounds like it's a way to verify an ephemeral message was sent without being able to see it

mighty pilot
waxen cradle
#

!tags decorators

#

!tags decorators

unkempt canyonBOT
#

Decorators

A decorator is a function that modifies another function.

Consider the following example of a timer decorator:

>>> import time
>>> def timer(f):
...     def inner(*args, **kwargs):
...         start = time.time()
...         result = f(*args, **kwargs)
...         print('Time elapsed:', time.time() - start)
...         return result
...     return inner
...
>>> @timer
... def slow(delay=1):
...     time.sleep(delay)
...     return 'Finished!'
...
>>> print(slow())
Time elapsed: 1.0011568069458008
Finished!
>>> print(slow(3))
Time elapsed: 3.000307321548462
Finished!

More information:
โ€ข Corey Schafer's video on decorators
โ€ข Real python article

rustic edge
#

How can I check if a user includes themselves in a command argument?

mighty pilot
#

If arg == ctx.user

#

Or interaction.user if slash command

waxen cradle
#

why this bot doesn't start with Intents.all (RuntimeError: Event loop is closed) but with Intents.default the bot starts but it doesn't respond with anything when using its prefix

sick birch
#

With default, message content intent (which is a privileged intent) is not enabled, so none of your commands would work

dim pike
#

Hello, how can I activate the bot I made with python?

#

I made a bot with python for the first time

waxen cradle
waxen cradle
mighty pilot
#

90% of the time all you need is the bot scope, and maybe the applications.commands scope (when using slash commands)

#

With the associated permissions under the bot scope

radiant parrot
#

how can i remove the indexs of fields all at once?

vast kraken
nocturne compass
#

where do i put the comma ;-;

dim pike
waxen cradle
waxen cradle
solid dune
#

help Pls

nocturne compass
#

why wont a embed send i got this instead

hushed galleon
#

e.g. py await channel.send(embed=my_embed_variable)

hushed galleon
solid dune
spring summit
#

i have a redeem command, if you redeem your id gets written into a file. i want the bot to remove the id after a certain time, is it possible? if so, how

solid dune
hushed galleon
nocturne compass
#

works @hushed galleon thanks a lot bro

arctic folio
#

why am i getting this error ?

naive briar
#

Your token is invalid

slate swan
#

if people actually read error

arctic folio
#

its hard

#

still

slate swan
#

raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: WriteError: Unknown modifier: inc. Expected a valid update modifier or pipeline-style update specified as an array, full error: {'index': 0, 'code': 9, 'errmsg': 'Unknown modifier: inc. Expected a valid update modifier or pipeline-style update specified as an array'}

slate swan
#

what does it mean?

#

@slate swan can I dm you my bot's code?

#

I am trying to make a daily system thing where you can claim coins once 24 hours passed since your last claim

#

using mongodb as a db

slate swan
#

any articles on those?

#

!d discord.ext.commands.cooldown its a simple to use decorator

unkempt canyonBOT
#

@discord.ext.commands.cooldown(rate, per, type=discord.ext.commands.BucketType.default)```
A decorator that adds a cooldown to a [`Command`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Command "discord.ext.commands.Command")

A cooldown allows a command to only be used a specific amount of times in a specific time frame. These cooldowns can be based either on a per-guild, per-channel, per-user, per-role or global basis. Denoted by the third argument of `type` which must be of enum type [`BucketType`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.BucketType "discord.ext.commands.BucketType").

If a cooldown is triggered, then [`CommandOnCooldown`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.CommandOnCooldown "discord.ext.commands.CommandOnCooldown") is triggered in [`on_command_error()`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.discord.ext.commands.on_command_error "discord.discord.ext.commands.on_command_error") and the local error handler.

A command can only have a single cooldown.
hollow agate
#
class ApplicationManagerDropdown(discord.ui.Select):
    def __init__(self, roles):
        self.roles = roles

        for x in roles:
            discord.SelectOption(label=f"{x}")

        options = [
            discord.SelectOption(label='-------DESIGN-------'),``` Would it be possible to somehow make this work? I'm trying to have a dropdown that changes depending on a specific value.
#

Iโ€™ve tried to use .append as well, but I just cannot get anything to work.

slate swan
#

options = [ discord.SelectOption(label=x.name) for x in roles]

slate swan
#

the doc doesn't provide any

cloud dawn
unkempt canyonBOT
#

@discord.app_commands.checks.cooldown(rate, per, *, key=...)```
A decorator that adds a cooldown to a command.

A cooldown allows a command to only be used a specific amount of times in a specific time frame. These cooldowns are based off of the `key` function provided. If a `key` is not provided then it defaults to a user-level cooldown. The `key` function must take a single parameter, the [`discord.Interaction`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.Interaction "discord.Interaction") and return a value that is used as a key to the internal cooldown mapping.

The `key` function can optionally be a coroutine.

If a cooldown is triggered, then [`CommandOnCooldown`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.app_commands.CommandOnCooldown "discord.app_commands.CommandOnCooldown") is raised to the error handlers.

Examples

Setting a one per 5 seconds per member cooldown on a command:
cloud dawn
#

They do.

slate swan
#

I want the bot to send a certain message when the cooldown isn't done

slate swan
# slate swan any full example for that
from discord.ext import commands

bot = commands.Bot(...)

@commands.cooldown(1, 10, commands.BucketType.user)
@bot.command()
async def test(ctx):
    await ctx.send("this command can be used only once in 10 seconds")

bot.run()
slate swan
slate swan
#

are those hard to learn?

#

nah they are easy

#

ty

#

so I expect that when someone uses the command before a cooldown is done it raises an error

hollow agate
# slate swan use a list comp

Unfortunately, it's the same error I usually get. py Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/discord/ui/view.py", line 425, in _scheduled_task await item.callback(interaction) File "/Users//Desktop/Code/CookieServices/src/tickets/applications.py", line 61, in no await interaction.response.edit_message(content='Select the roles you would like to give them in the dropdown!', embed=None, view=view) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/discord/interactions.py", line 856, in edit_message await adapter.create_interaction_response( File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/discord/webhook/async_.py", line 220, in request raise HTTPException(response, data) discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body In components.0.components.0.options: Must be 19 or more in length.

slate swan
#

In components.0.components.0.options: Must be 19 or more in length.
what do you think this could mean

hollow agate
#

I must have 19 characters in the label? I donโ€™t quite understand.

slate swan
#

must have 19(+) elements for options

hollow agate
#

I still donโ€™t quite understand, Iโ€™m sorry.

slate swan
hollow agate
#

Yes, it is.

sick birch
#

Oddly specific number

hollow agate
#

Iโ€™m not sure whatโ€™s wrong haha

#

Iโ€™m sure not many people have tried to do this either :P

slate swan
hollow agate
#

Surely

slate swan
#

and the select's super().init

hollow agate
#
class ApplicationManagerDropdown(discord.ui.Select):
    def __init__(self, roles):
        self.roles = roles

        options = [discord.SelectOption(label=x) for x in roles]
        
        print(options)

        super().__init__(placeholder="Choose all the roles you're applying for!", min_values=1, max_values=19, options=options)

    async def callback(self, interaction: discord.Interaction):
        await interaction.response.send_message('test', ephemeral=True)

class ApplicationManagerDropdownView(discord.ui.View):
    def __init__(self, roles):
        super().__init__()
        self.roles = roles

        self.add_item(ApplicationManagerDropdown(roles))```
#

I can provide the entire file if that helps :D

slate swan
#

you are allowing user to choose a max of 19 options, but providing less than that

hollow agate
#

That worked ๐Ÿ˜‚

#

Thank you so much! I amโ€ฆ stupid :P

night ether
#

I am trying to make PyAv encode frames for aiortc. I receive bytes() object from server and I can't understand how I to properly encode bytes() object to make it numpy array to use AudioFrame.from_ndarray. To receive audio data I am using to_bytes, but looks like there is no from_bytes ๐Ÿ˜ฆ I receive pcm audio bytes() from here https://github.com/Pycord-Development/pycord/blob/master/discord/opus.py#L518 and want to encode it into PyAv's Frame. I am using aiortc, but it needs the bytes() to be in Frame already. https://github.com/aiortc/aiortc/blob/ffe2a566da74e000fc5bef354ae3f0a9a90c40e2/src/aiortc/codecs/opus.py#L65 So I need a way to encode bytes() into av.AudioFrame

unkempt canyonBOT
#

discord/opus.py line 518

return array.array("h", pcm[: ret * channel_count]).tobytes()```
`src/aiortc/codecs/opus.py` line 65
```py
def encode(```
silent portal
#

Any way I can do this in a better way ๐Ÿ˜ญ

hollow agate
#

I usually do that with max_values.

slate swan
night ether
hollow agate
#

Hm. They can choose up to 19 if all 19 are provided

#

How would I make it differ depending on how many roles are provided?

hollow agate
#

Oh lol

#

Thank you! ๐Ÿ˜…

slate swan
night ether
cloud dawn
slate swan
#

i also have some doubts with the logic

#

!e ```py
print(1>= 1> 0)

#

ow oki this works

spring summit
#

how do i add unixtimestamps to my commands? like for example i wanna do .hello and a embed is gonna pop up with 30 days relative time countdown from that moment

#

how would i do that

slate swan
#

!d discord.utils.format_dt

unkempt canyonBOT
#

discord.utils.format_dt(dt, /, style=None)```
A helper function to format a [`datetime.datetime`](https://docs.python.org/3/library/datetime.html#datetime.datetime "(in Python v3.11)") for presentation within Discord.

This allows for a locale-independent way of presenting data using Discord specific Markdown...
slate swan
#

pass in the datetime with style = "R"

spring summit
#

im kinda new to all this

#

OH my bad lol

slate swan
#

did you get it or should i show an example

spring summit
slate swan
# spring summit please do.

!e ```py
import datetime
now = datetime.datetime.now()
_5_mins_later = now + datetime.timedelta(minutes=5)
print(f"<t:{int(_5_mins_later.timestamp())}:R>")

unkempt canyonBOT
#

@slate swan :white_check_mark: Your 3.11 eval job has completed with return code 0.

<t:1668028718:R>
slate swan
#

when i paste the output: <t:1668028718:R>

spring summit
#

okay lemme try

#

OMG IT WORKS

nocturne compass
#

i want my bot to take someone to a url if they click my button how is this done?

waxen cradle
#

Intents.guild is present in Intents.all ?

slate swan
unkempt canyonBOT
#

@discord.ui.button(*, label=None, custom_id=None, disabled=False, style=<ButtonStyle.secondary: 2>, emoji=None, row=None)```
A decorator that attaches a button to a component.

The function being decorated should have three parameters, `self` representing the [`discord.ui.View`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.ui.View "discord.ui.View"), the [`discord.Interaction`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.Interaction "discord.Interaction") you receive and the [`discord.ui.Button`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.ui.Button "discord.ui.Button") being pressed.

Note

Buttons with a URL cannot be created with this function. Consider creating a [`Button`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.ui.Button "discord.ui.Button") manually instead. This is because buttons with a URL do not have a callback associated with them since Discord does not do any processing with it.
slate swan
#

and set button style to ButtonStyle.url

slate swan
waxen cradle
nocturne compass
slate swan
slate swan
# nocturne compass code currently

you can't make a url button like that in a view, will have to manually create a ui.Button instance and add it to the view using view.add_item

nocturne compass
#

got it ty @slate swan

spring summit
#

it doesnt work with embeds

#

what do i do

slate swan
waxen cradle
#

i want to make the bot send a message at a specific hour everyday, what should i modify here bcs i get "sys:1: RuntimeWarning: coroutine 'Loop._loop' was never awaited"

strange python
#

send me a dm :)

sick birch
#

!rule 6 9

unkempt canyonBOT
#

6. Do not post unapproved advertising.

9. Do not offer or ask for paid work of any kind.

sick birch
#

Also save yourself the money and get help for free here :)

primal token
sick birch
#

indeed i did

#

as you can tell i am not very mature

strange python
#

i need someone to help me make a python script thats send a message every 5 minutes in my discord server and deletes its self after 1 minute and also if someone dms me it will send an automated message back dm me please :)

digital lava
#

i need help my discord bot is broken

potent spear
#

nice

primal token
digital lava
sick birch
#

bozo

primal token
#

I dont making mine authentic

sick birch
strange python
#

wait do pthyon scrips run 24/7

sick birch
sick birch
strange python
#

do replit scrips work on python

sick birch
#

Replit works but we don't recommended it

#

Not a very good "host"

strange python
#

yeah replit is shitty

digital lava
#

you can run it off of your pc

strange python
#

only runs for 10 minutes max

strange python
#

i have it downloaded

sick birch
#

Sure, is it a .py file?

waxen cradle
strange python
#

thats is what it is

sick birch
# waxen cradle umm no

You might consider updating as I believe 2.0 has a nice method for running a loop at a specific time of day

strange python
#

i jus downloaded it straight from replit

slate swan
sick birch
strange python
#

yeah its a replit

slate swan
#

bruh that's a nodejs project

strange python
#

i was wondering if i could import to python

sick birch
#

Yes, but it isn't a Python project

#

It's written in Node.js

strange python
#

how do i make it a python project

sick birch
#

Rewrite it from scratch

#

Python and Nodejs are 2 seperate programming languages

#

So Nodejs code won't work on Python and vice versa

strange python
#

can i give you like $20 and you do it for me

#

its an easy script

sick birch
#

No, that's against our server rules. Or you can do it yourself for free

#

(With help from this server)

strange python
#

i dont know how to do this stuff

mighty pilot
#

It's an easy script just rewrite it flexpoli

sick birch
#

Sounds like a good time to pick up a new skill!

slate swan
sick birch
#

If you'd like, I can send resources over to help you get started

mighty pilot
#

There are also resources to host a node.js bot but you likely won't find them here

#

At least not in abundance

sick birch
#

DevOps and your programming language should mostly be independent of each other IMO

mighty pilot
#

I used to use a website called autocode which is a serverless hosting site for node.js that offers a free tier for I think 500 api requests a month?

sick birch
#

Personally I like to dockerize my code and chuck it onto EKS or just run it on ECS

slate swan
#

imagine hosting

sick birch
#

or if its just a hobby bot i'll throw it onto my raspberry pi

#

which i still can't find

#

even though it's connected to the network

slate swan
#

wtf

mighty pilot
#

I got a whole ass dell rack server in my house Nicehaunt just for hobbies

sick birch
sick birch
mighty pilot
#

Gonna throw a plex server vm on it soon

#

Got a buddy that has a few thousand movies on his Google drive and he's already bought a couple hard drives for me to load up on movies

potent spear
mighty pilot
#

Ooo that's smart

sick birch
#

the thing can't heat up to save its life

mighty pilot
#

Just burn your house down and search the rubble

sick birch
#

unlike my PC

#

you would think a liquid cooler would do an adequate job but nope
80C when coding

mighty pilot
#

How many outlets do you have in your house that you can't find where it's plugged in lmao

pliant gulch
#

If it has sound you could load up software that plays a ping

sick birch
mighty pilot
#

I own a house

pliant gulch
#

You can prob find the IP via wireshark or termshark

potent spear
pliant gulch
#

Or prob ssh (...).local if you know the username & hostname

sick birch
#

piece of shit raspberry pi

potent spear
#

I don't see why not finding it would be a problem
think of it as a VPS

slate swan
#

aaaa_stress simply searching for it is also an option

patent lark
#

hm.

mighty pilot
#

Just walk around the walls and trace down everything that's plugged in anywhere lmaopika sounds like you don't want to find it

pliant gulch
#

inb4 shut off all your breakers in your house and slowly turn them back on to see which breaker causes the Pi to go off the network

sick birch
sick birch
#

dont use it much these days anyway
the pi is probably off plotting plans to take over the world

pliant gulch
#

Don't let the Pi figure out how to do matrix dot products

mighty pilot
#

Make sure all your guns are accounted for you don't want it integrating those into its own system

sick birch
mighty pilot
#

Just not too close. You gotta be able to get to it before they do

pliant gulch
potent spear
mighty pilot
#

free heat source

#

Use one like this it'll act as an afterburner for itself and be more efficient as a heat source

mighty pilot
#

Anyone know if there's a discord bot for streaming video to discord? Like from a website not from a video game streaming service

pliant gulch
# potent spear

If this was a joke about plugging itself into itself then I wouldn't be afraid as most circuits are protected nowawadays

pliant gulch
#

Because otherwise you'd basically have a glorified link sender

mighty pilot
#

Well it would be via discord call. Like screenshare

pliant gulch
#

Well, that's impossible

#

Unless you self-bot, but then again, it's a self-bot

nocturne compass
#

how do i make my bot send a message after a person says something to it

#

if that makes sense

#

i want my bot to reply back to when the person says there id

mighty pilot
#

Yea I don't wanna go around breaking tos with a self bot. Just had an idea to stream a TV series 24/7 in my server. Tried doing it with an alt account but discord dropped my frame rate significantly after 24 hours so I was wondering if there's some alternative where I could do it via a bot that's told when to stream and such

pliant gulch
#

So there is no intended way for bot's to stream

mighty pilot
#

Missed opportunity

pliant gulch
#

And either way the bot would also receive a frame rate drop probably (if it were to be added)

mighty pilot
#

This could be used to wait for a user to reply to a message, or to react to a message, or to edit a message in a self-contained way.

#

Wait_for()

nocturne compass
mighty pilot
#

The link I sent

#

It has an example of waiting for a reply

waxen cradle
#

For the discord bot sending a message at a specific hour, should i use date.time ?

hushed galleon
spice scroll
#

everything is against me trying to run a fucking discord bot, when I try on replit it says this:

#

i fixed it once by sending kill 1 in the shell but now that doesnt work

#

aight nvm

#

i got it ||for now||

upbeat gust
ivory spindle
#

i just transferred my bot from replit to railway, is there a way to copy the sqlite database over with all of the data? if not what similar database is there that keeps all the data even if i migrate to a different platform

mighty pilot
#

There should be a way to export the database then import it to the new machine

ivory spindle
ionic garden
#

how do i make a select menu contain all users
in a server

hushed galleon
ionic garden
#

i guess i'll wait

spice scroll
#

Hm

spice scroll
slate swan
upbeat gust
#

Use a vps

slate swan
slate swan
#

there arent problems w json right?

cloud dawn
slate swan
#

๐Ÿ˜ญ

cloud dawn
#

Json files aren't really meant to be edited.

slate swan
#

db is just harder for me to use

cloud dawn
#

I've tried both actually and json to let it work correctly is far more difficult then a db

#

And why just for you?

slate swan
#

wdym

cloud dawn
#

Well you said harder for me to use

slate swan
#

yes

cloud dawn
#

Why just for you?

slate swan
#

its hard for a lot of ppl but also for me

cloud dawn
#

I'm confident that everyone can learn sql in like a day

#

Easy to learn hard to master kind of language

slate swan
#

ive tried learning

cloud dawn
#

What did you try?

#

I recommend trying out postgresql then you can create a db and have an interface to test queries

slate swan
#

thanks!

cloud dawn
#

If you have any difficulties just ping me.

slate swan
#

okay tysmmm

cloud dawn
#

Great thing about it is that you don't need to know how to create a db with raw sql with is often the hardest part with sqlite

slate swan
#

someone told me to make the create giveaway slash command id but idk how to do it

cloud dawn
slate swan
#

i made the create giveaway

#

but idk how to make it have an id

slate swan
#

!paste

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 floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.

alpine cove
#

like doesnt matter if psql sql or sqlite

#

just learn at least of them

#

its gonna become handy in the feature pretty sure

cloud dawn
alpine cove
slate swan
#

how do I make all this 1 string so I don't get this error?

slate swan
#

thank you i'll try it

#

it is also way to long and you will still get an error

#

oh nvm i see

slate swan
#

Trying to make the bot respond with the string but I got an error

slate swan
#

could you show me an example?

#

? what made you write "message" in the command argument

#

I thought the string would be the message since I specified message = string

placid skiff
#

bruh

#

Just like others functions, the parameters that you define must be provided

def myfunc(value):
  print(value)
myfunc() #raises TypeError error, missing 1 required positional argument
mufunc(1) #prints 1 

in dpy function parameters are taken by the input of the user within the command

@command()
async def mycommand(ctx, value):
  #ctx is passed by default when the command is casted
  await ctx.send(value)

if the user types <prefix>mycommand MissingRequiredArgument error is raised since value parameter was not being passed. If the user types <prefix>mycommand hello then value will be equals to hello and the bot will send hello

cloud dawn
#

That's a long prefix ngl

signal hedge
#

what happened

naive briar
#

Your token is invalid

verbal monolith
#

copy paste ti here

#

no not the token

signal hedge
#

thank you very much

spice scroll
#

Def not the token

verbal monolith
#

were in scotland

#

im not sure its legal

slate swan
#

loooli that message was sent 12 hrs ago bruh

abstract onyx
#

why not a ak, ar I don't know anything that can be used in semi automatic

cloud dawn
#

I suggest postgresql

slate swan
#

If I have my dms closed, and dm a discord bot, would the bot be able to add reactions to my message?

verbal monolith
#

it negates the closed dms

slate swan
#

So the bot would be able to respond too?

#

if you have the dms closed it wont be able to send you the message

#

even if there already is a convo

#

the reactions can be added unless you block the bot

cloud dawn
#

Discord bot on paper.

slate swan
#

!ytdl

unkempt canyonBOT
#

Per Python Discord's Rule 5, we are unable to assist with questions related to youtube-dl, pytube, or other YouTube video downloaders, as their usage violates YouTube's Terms of Service.

For reference, this usage is covered by the following clauses in YouTube's TOS, as of 2021-03-17:

The following restrictions apply to your use of the Service. You are not allowed to:

1. access, reproduce, download, distribute, transmit, broadcast, display, sell, license, alter, modify or otherwise use any part of the Service or any Content except: (a) as specifically permitted by the Service;  (b) with prior written permission from YouTube and, if applicable, the respective rights holders; or (c) as permitted by applicable law;

3. access the Service using any automated means (such as robots, botnets or scrapers) except: (a) in the case of public search engines, in accordance with YouTubeโ€™s robots.txt file; (b) with YouTubeโ€™s prior written permission; or (c) as permitted by applicable law;

9. use the Service to view or listen to Content other than for personal, non-commercial use (for example, you may not publicly screen videos or stream music from the Service)
cloud dawn
#

i can almost cite this ngl

loud junco
#

how to send picture in embed

upbeat gust
unkempt canyonBOT
#

set_image(*, url)```
Sets the image for the embed content.

This function returns the class instance to allow for fluent-style chaining.
loud junco
#

thanks

hallow marten
#

how can i take input with slash commands on nextcord

whole sparrow
#

like inter is disnake.CommandInteraction, whats bot?

slate swan
whole sparrow
#

ah yh im dumb its commands.Bot

#

thanks

#

Any reason why self.bot.get_channel(voice_channel_id) is returning a nonetype?

#

in disnake

slate swan
#

the channel is not cached yet

#

or the voice_channel_id is invalid

whole sparrow
#

Hmm id is valid so i'd assume its not that, what do you mean by it's not cached? and how would I solve it

slate swan
whole sparrow
#

ahh

#

its fetch instead of get_channel

slate swan
#

fetch makes an api call yes

#

it will always give you the channel even if its not cached

whole sparrow
#

Yeah, thanks so much just searched up on google.

#

Yep, never knew about caching and channels so now its good knowledge

#

thanks for your help

hallow palm
#

What is the reason why nobody tests their bots? It seems standard to just run it and hope nothing errors.

slate swan
hushed galleon
slate swan
#

it just tests all the constructors afaik

slate swan
hallow palm
#

For all the nagging i see on testing things, i am quite surprised how often testing gets skipped for a large variety of software.

slate swan
#

if it works, it works

hallow palm
#

Not as a complaint to bot devs. More so just the wierd standard of making tooling such as d.py not testable.

pliant gulch
#

discord.py could be testable, but it's quite cumbersome to mock all those objects

hallow palm
#

As its more a tooling thing than a developer perspective.

pliant gulch
#

not to mention mocking HTTP requests

#

I have seen regular bot developers unit test before but it doesn't add as many benefits as it should

#

I would just test your code inline rather than write down unit tests

#

Another reason in my eyes would be, well what exactly do you need to test? Discord.py wraps the API so mostly they would only need to test their abstractions, so once you get rid of testing the API from discord you get rid of like, 90% of the wrapper basically

kind trellis
#

How can I capture what the user is replying to when a command is sent?

pliant gulch
#

You'd basically be testing attributes at that point

pliant gulch
slate swan
unkempt canyonBOT
#

The message that this message references. This is only applicable to messages of type MessageType.pins_add, crossposted messages created by a followed channel integration, or message replies.

New in version 1.5.

cerulean folio
#

Hi guys ! I just started thinking with the OOP paradigm few days ago, and I think i'm doing good already. However I still kinda get lost in my flow of data and I'd like to have some help if you guys fancy. In the following program, the bot instantly cancels the report after I run the command, without throwing any error and I'm confused. Can you guys help me figure it out? :D

https://paste.pythondiscord.com/numidetowo

hushed galleon
kind trellis
#

How do I integrate it into ctx.reply?

hushed galleon
cerulean folio
slate swan
hushed galleon
kind trellis
slate swan
kind trellis
slate swan
#

ctx.message.reference.resolved.reply

kind trellis
slate swan
#

idk about that but most probably not

kind trellis
#

One way to find out

cerulean folio
jovial lynx
#

how do i get intents to work?

discord.intents = intents.default()
client = commands.Bot(command_prefix='!', intents=intents)
Traceback (most recent call last):
  File "/home/ciaran/discord_bots/main.py", line 12, in <module>
    discord.intents = intents.default()
NameError: name 'intents' is not defined
unkempt canyonBOT
#

Using intents in discord.py

Intents are a feature of Discord that tells the gateway exactly which events to send your bot. By default discord.py has all intents enabled except for Members, Message Content, and Presences. These are needed for features such as on_member events, to get access to message content, and to get members' statuses.

To enable one of these intents, you need to first go to the Discord developer portal, then to the bot page of your bot's application. Scroll down to the Privileged Gateway Intents section, then enable the intents that you need.

Next, in your bot you need to set the intents you want to connect with in the bot's constructor using the intents keyword argument, like this:

from discord import Intents
from discord.ext import commands

intents = Intents.default()
intents.members = True

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

For more info about using intents, see the discord.py docs on intents, and for general information about them, see the Discord developer documentation on intents.

hushed galleon
#

-1 for only importing Intents, and -1 for not enabling message_content

jovial lynx
#

oh okay, and now this:

Traceback (most recent call last):
  File "/home/ciaran/discord_bots/main.py", line 25, in <module>
    @client.command()
NameError: name 'client' is not defined
hushed galleon
#

but otherwise yeah that example is how you'd do it

jovial lynx
#

oh it changed to bot

#

okay got it

slate swan
spring needle
#

How to get command from cogs?

hushed galleon
#

maybe there's another PR about it, if not ill do it

spring needle
#

I tried bot.get_command but it requires self and ctx arg, when I added them to callback it says self not defined

hushed galleon
#

what do you need the command for? where are you using it in your code?

slate swan
hushed galleon
#

bot.get_command() should only require a single string describing the command's name

spring needle
#

Yes, I want to let my code run the command in the cog

#

As a interaction response to the selection menu

quaint epoch
#

!d discord.ext.commands.Bot.get_command

unkempt canyonBOT
#

get_command(name, /)```
Get a [`Command`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Command "discord.ext.commands.Command") from the internal list of commands.

This could also be used as a way to get aliases.

The name could be fully qualified (e.g. `'foo bar'`) will get the subcommand `bar` of the group command `foo`. If a subcommand is not found then `None` is returned just as usual.

Changed in version 2.0: `name` parameter is now positional-only.
naive briar
#

My god I can't type

hushed galleon
#

hm, i guess that might be alright to do, though imo its usually easier to refactor your command into a third function

naive briar
#

!d discord.ext.commands.Context.from_interaction

unkempt canyonBOT
#

classmethod await from_interaction(interaction, /)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Creates a context from a [`discord.Interaction`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.Interaction "discord.Interaction"). This only works on application command based interactions, such as slash commands or context menus.

On slash command based interactions this creates a synthetic [`Message`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Message "discord.Message") that points to an ephemeral message that the command invoker has executed. This means that [`Context.author`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Context.author "discord.ext.commands.Context.author") returns the member that invoked the command.

In a message context menu based interaction, the [`Context.message`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Context.message "discord.ext.commands.Context.message") attribute is the message that the command is being executed on. This means that [`Context.author`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Context.author "discord.ext.commands.Context.author") returns the author of the message being targetted. To get the member that invoked the command then [`discord.Interaction.user`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.Interaction.user "discord.Interaction.user") should be used instead.

New in version 2.0.
cerulean folio
#
async def check_cancel(self):
    while not self.view.canceled:
        continue
    return True

Is this a proper way to listen to a cancel button?

#

(I subclassed View and added self.canceled = False that gets changed with a button callback)

hushed galleon
#

your while-loop would run indefinitely and block the event loop

cerulean folio
#

I'll use asyncio.wait() and it will run with another function tho

#

I mean I'm already using it

upbeat otter
hushed galleon
#

but your function is still not yielding to the event loop

cerulean folio
#

I don't get it

jovial lynx
#

how do i solve this?

2022-11-10 14:03:46 WARNING  discord.ext.commands.bot Privileged message content intent is missing, commands may not work as expected.
hushed galleon
#

that yielding only occurs when the task does an await, or async for, or async with

#

while not cancelled: pass never yields, so it prevents all other tasks from running

#

(not to mention it maxes out your CPU core)

hushed galleon
hushed galleon
#

e.g. py intents = discord.Intents.default() intents.message_content = True bot = commands.Bot(...) # here is same as what you had before

jovial lynx
#

wtf why is the bot dming the responses

#

instead of sending in chat

#
    if message.content.startswith('hello'):
        msg = 'Hello, how are you? {0.author.mention}'.format(message)
        await message.author.send(msg)
hushed galleon
hushed galleon
#

if you want to send to the same channel that the message came from, you'd write message.channel.send()

#

the documentation will help you figure out what attributes and methods there are

#

!d discord.Message.channel

unkempt canyonBOT
kind trellis
hushed galleon
#

whenever the message doesnt reference anything, yes

#

resolved might also return none too

ocean dragon
#

how can I add a parameter to load_extension? should I inherit commands.Bot or is there a better way?

main.py

await bot.load_extension(f"bot.member")

bot/member.py

class MyBot(commands.Cog):
    def __init__(self, bot:commands.Bot) -> None:
        self.bot = bot
        self.database = "?"
mighty yarrow
#

how to create invite link using icord.py?

slate swan
upbeat otter
unkempt canyonBOT
#

await create_invite(*, reason=None, max_age=0, max_uses=0, temporary=False, unique=True, target_type=None, target_user=None, target_application_id=None)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Creates an instant invite from a text or voice channel.

You must have [`create_instant_invite`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Permissions.create_instant_invite "discord.Permissions.create_instant_invite") to do this.
upbeat otter
#

or you can make self.database a class variable instead and then import the cog class manually and set the database variable

#

'''bot/member.py'''
class SomeCogIDC(commands.Cog):
  database: ... = None

  def __init__(self) -> None:
    ...

''' main.py '''

from bot.member import SomeCogIDC

SomeCogIDC.database = "no"
slate swan
ocean dragon
#

I guess I'll override, I have many bots and many cogs for bots, so it'll be cleanest

#

what is monkeypatch though

slate swan
#

you can just make database an attr of bot tho

slate swan
upbeat otter
#

"some" "fun"
ahem

robust forge
#

hello

nocturne compass
#

bot wont send embed how to fix?

upbeat otter
nocturne compass
slate swan
maiden fable
#

Not this again

slate swan
#

code :

@bot.event
async def on_member_join(member):
    Channel = bot.get_channel(1040275571311116368)

    background = Editor("pic.png")
    profile_image = await load_image_async(str(member.display_avatar.url))

    profile = Editor(profile_image).resize((200, 200)).circle_image()
    poppins = Font.poppins(size=50, variant="bold")

    poppins_small = Font.poppins(size=20, variant="light")

    background.paste(profile, (320, 60))
    background.ellipse((320, 60), 200, 200, outline="white",stroke_width=5)
    
    background.text((414, 320), f"Member: #{len(member.guild.members)}", color="white", font=poppins_small, align="center")
    background.text((414, 260), f"{member.name}#{member.discriminator}", color="white", font=poppins, align="center")
    file = File(fp=background.image_bytes, filename="pic.png")
    await Channel.send(f"Helloooo {member.mention} welcome to **{member.guild.name}** ๐Ÿ›น๐Ÿ›น", file=file)```

error:
```Ignoring exception in on_member_join
Traceback (most recent call last):
  File "C:\Users\PC\AppData\Roaming\Python\Python39\site-packages\nextcord\client.py", line 502, in _run_event
    await coro(*args, **kwargs)
  File "c:\Users\PC\Desktop\Skater Hub Bot\cogs\moderation.py", line 121, in on_member_join
    await channel.send(embed=embed)
AttributeError: 'NoneType' object has no attribute 'send'
Ignoring exception in on_member_join
Traceback (most recent call last):
  File "C:\Users\PC\AppData\Roaming\Python\Python39\site-packages\nextcord\client.py", line 502, in _run_event
    await coro(*args, **kwargs)
  File "c:\Users\PC\Desktop\Skater Hub Bot\cogs\moderation.py", line 121, in on_member_join
    await channel.send(embed=embed)
AttributeError: 'NoneType' object has no attribute 'send'```
paper sluice
#

get_<...> tries to get stuff from bot's cache, if it doesn't exist it returns None
use fetch_<...> when get returns None

slate swan
#

ru talking to me?

paper sluice
#

ya

maiden fable
#

Lol

slate swan
#

oh i didnt put get

#

likw

#

in the channel but i do that always

paper sluice
#

im talking about

    Channel = bot.get_channel(1040275571311116368)

slate swan
#

bot.fetch_channel?

paper sluice
#

yea

slate swan
#

ill try now ty!

#

C:\Users\PC\AppData\Roaming\Python\Python39\site-packages\nextcord\client.py:509: RuntimeWarning: coroutine 'Client.fetch_channel' was never awaited
pass
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

#

i dont do await channel = bot.fetch_channel(id), right?

#
Traceback (most recent call last):
  File "C:\Users\PC\AppData\Roaming\Python\Python39\site-packages\nextcord\client.py", line 502, in _run_event
    await coro(*args, **kwargs)
  File "c:\Users\PC\Desktop\Skater Hub Bot\cogs\moderation.py", line 121, in on_member_join
    await channel.send(embed=embed)
AttributeError: 'NoneType' object has no attribute 'send'
Ignoring exception in on_member_join
Traceback (most recent call last):
  File "C:\Users\PC\AppData\Roaming\Python\Python39\site-packages\nextcord\client.py", line 502, in _run_event
    await coro(*args, **kwargs)
  File "c:\Users\PC\Desktop\Skater Hub Bot\main.py", line 120, in on_member_join
    await Channel.send(f"Helloooo {member.mention} welcome to **{member.guild.name}** \U0001f6f9\U0001f6f9", file=file)
TypeError: coroutine.send() takes no keyword arguments
C:\Users\PC\AppData\Roaming\Python\Python39\site-packages\nextcord\client.py:509: RuntimeWarning: coroutine 'Client.fetch_channel' was never awaited
  pass
RuntimeWarning: Enable tracemalloc to get the object allocation traceback```
maiden fable
#

channel = await bot.fetch_channel

slate swan
#

OH

#
Traceback (most recent call last):
  File "C:\Users\PC\AppData\Roaming\Python\Python39\site-packages\nextcord\client.py", line 502, in _run_event
    await coro(*args, **kwargs)
  File "c:\Users\PC\Desktop\Skater Hub Bot\cogs\moderation.py", line 121, in on_member_join
    await channel.send(embed=embed)
AttributeError: 'NoneType' object has no attribute 'send'```
maiden fable
#

ID is prolly wrong

slate swan
#

it is sending that but not w the stuff in the img

#

@maiden fable

maiden fable
#

Ah sorry never used Pillow

slate swan
#

oh okay ty!

upbeat otter
upbeat otter
maiden fable
#

Seriously tho

upbeat otter
#

nvm, I need to seriously fix my mind

maiden fable
#

Well u can help him if u have used Pillow lol

upbeat otter
#

haven't ever
totally not learning pillow until desperation arrives

maiden fable
#

!pypi easy_pil is always there but ๐Ÿคท

unkempt canyonBOT
ivory spindle
vale wing
#

You should just quit replit if you need data storage

#

In fact you should quit it anyway

#

I see no reason in using browser IDE when you can use local IDE which is much more flexible and powerful

#

Unless you have like very low-end PC that can't even run VSC

sick birch
#

anything after 2000s should be able to run VSC

#

or even emacs

spring needle
#

How to invoke a command from another cog in discord py? For example when I do /menu then a embed message and a selection menu will pop up and if I select something in the selection menu, I want it to run another command from another cog

maiden fable
unkempt canyonBOT
#

get_command(name, /)```
Get a [`Command`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Command "discord.ext.commands.Command") from the internal list of commands.

This could also be used as a way to get aliases.

The name could be fully qualified (e.g. `'foo bar'`) will get the subcommand `bar` of the group command `foo`. If a subcommand is not found then `None` is returned just as usual.

Changed in version 2.0: `name` parameter is now positional-only.
spring needle
maiden fable
#

then the name is wrong?

#

!d discord.ext.commands.Bot.cogs

unkempt canyonBOT
spring needle
#

So if I want the abc command is the cog to run I use โ€œbot.get_command(โ€˜abcโ€™)โ€

maiden fable
#

Mhm

spring needle
#

Ya and just interaction failed

#

No error in the console

maiden fable
#

Do u have an error handler

spring needle
#

No

maiden fable
#

Hm weird

#

Mind showing the code?

shrewd apex
spring needle
mighty pilot
slate swan
#

anyone have any examples of discord py, using buttons with @bot.listen commands.

slate swan
mighty pilot
#

Alright

spring needle
slate swan
#

Guy

#

Am tryna make a free crypto mining discord bot

#

but when somebody does !mine

#

it mines for him in his account

#

but how do i make it when its mining

#

but when it does thhe procces

#

it pauses the bot

#

is there anyways i make it so it doesnt pause the bot or does the mining in another cmd tab like open another cmd tab and do it in there

#

is there if there is pls tell me

#

i dont think thats possible

cloud dawn
#

It's not like his account will mine then...?

#

Confusion 100%

slate swan
#

ok just tell me

#

is it possible to make a cmd procces open in a new tab

cloud dawn
#

I don't think you read what we typed

slate swan
#

so it doesnt pause the discord bot?

#

ok sorry forgot what i wrote just tell me

cloud dawn
slate swan
#

how

cloud dawn
#

!d asyncio.create_subprocess_shell

unkempt canyonBOT
#

coroutine asyncio.create_subprocess_shell(cmd, stdin=None, stdout=None, stderr=None, limit=None, **kwds)```
Run the *cmd* shell command.

The *limit* argument sets the buffer limit for [`StreamReader`](https://docs.python.org/3/library/asyncio-stream.html#asyncio.StreamReader "asyncio.StreamReader") wrappers for `Process.stdout` and `Process.stderr` (if [`subprocess.PIPE`](https://docs.python.org/3/library/subprocess.html#subprocess.PIPE "subprocess.PIPE") is passed to *stdout* and *stderr* arguments).

Return a [`Process`](https://docs.python.org/3/library/asyncio-subprocess.html#asyncio.subprocess.Process "asyncio.subprocess.Process") instance.

See the documentation of [`loop.subprocess_shell()`](https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.subprocess_shell "asyncio.loop.subprocess_shell") for other parameters.

Important

It is the applicationโ€™s responsibility to ensure that all whitespace and special characters are quoted appropriately to avoid [shell injection](https://en.wikipedia.org/wiki/Shell_injection#Shell_injection) vulnerabilities. The [`shlex.quote()`](https://docs.python.org/3/library/shlex.html#shlex.quote "shlex.quote") function can be used to properly escape whitespace and special shell characters in strings that are going to be used to construct shell commands...
cloud dawn
#

Yes

slate swan
#

nvm am not gonna be able to let u understand

#

i want u to make it for me

cloud dawn
#

Most likely

#

It's 1 line of code

slate swan
#

os.system(f"java -jar cryptomining.jar {arg1} {arg2} {arg3} 60 5000 y")

#

@cloud dawn can you help me w some

#

can u make it so when it runs this command it opens a new shell pls

cloud dawn
slate swan
cloud dawn
slate swan
#

how do i use discord buttons on @bot.listen commands on embeds

#

pls do it for me please

cloud dawn
slate swan
#

@cloud dawn i just need u to give me a code i replace with this that makes it so it runs this command but in a different cmd os.system(f"java -jar XDDOS.jar {arg1} {arg2} {arg3} 60 5000 y")

#

like just transform that function innto a code a that makes it so it runs in new cmd

#

why u go Sad

#

me now sed D:

maiden fable
#

what is happening here

#

!d asyncio.create_subprocess_shell if u wanna run a cmd command from a discord bot

unkempt canyonBOT
#

coroutine asyncio.create_subprocess_shell(cmd, stdin=None, stdout=None, stderr=None, limit=None, **kwds)```
Run the *cmd* shell command.

The *limit* argument sets the buffer limit for [`StreamReader`](https://docs.python.org/3/library/asyncio-stream.html#asyncio.StreamReader "asyncio.StreamReader") wrappers for `Process.stdout` and `Process.stderr` (if [`subprocess.PIPE`](https://docs.python.org/3/library/subprocess.html#subprocess.PIPE "subprocess.PIPE") is passed to *stdout* and *stderr* arguments).

Return a [`Process`](https://docs.python.org/3/library/asyncio-subprocess.html#asyncio.subprocess.Process "asyncio.subprocess.Process") instance.

See the documentation of [`loop.subprocess_shell()`](https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.subprocess_shell "asyncio.loop.subprocess_shell") for other parameters.

Important

It is the applicationโ€™s responsibility to ensure that all whitespace and special characters are quoted appropriately to avoid [shell injection](https://en.wikipedia.org/wiki/Shell_injection#Shell_injection) vulnerabilities. The [`shlex.quote()`](https://docs.python.org/3/library/shlex.html#shlex.quote "shlex.quote") function can be used to properly escape whitespace and special shell characters in strings that are going to be used to construct shell commands...
slate swan
#

@maiden fable am new to this i dont understand anything

#

can u just make this os.system(f"java -jar cryptomining.jar {arg1} {arg2} {arg3} 60 5000 y")

maiden fable
#

Uh, do u know about asyncio and awaiting stuff?

slate swan
#

into a command which does the same but in a new cmd

maiden fable
#

confusion 100
@cloud dawn is more experienced and will help u thanks

slate swan
#

oke D:

cloud dawn
#

We won't help with this since this tool is mostly used to ddos minecraft servers.