#discord-bots

1 messages ยท Page 694 of 1

slate swan
#

Oh no

quick kindle
#

๐Ÿคฆโ€โ™‚๏ธ

boreal ravine
#

and that video is literally shit, he doesn't even explain what the code does

quick kindle
#

hmm

slate swan
#

My bad for the ping shouldve turned it off

boreal ravine
slate swan
#

Dang does tutorials suck

quick kindle
#

whats the good tutorial for making a discord music bot then? Now that rythm is also ded?

carmine pilot
#

i just learned by trying to make projects and learning my issues with non cheating questions that just helped me know how to solve my solution

quick kindle
#

id rather stick to web dev and html, css and all cuz that sh** easier

carmine pilot
quick kindle
#

but python is interesting tho

slate swan
carmine pilot
slate swan
quick kindle
#

there's a similar program to python called small basic. Its a programming app for kids and easier than programming languages

carmine pilot
#

small basic?

quick kindle
#

yes

carmine pilot
#

tf

boreal ravine
#

!ot

unkempt canyonBOT
slate swan
#

So your saying python is for kids?

quick kindle
#

no

boreal ravine
#

stop going off topic

quick kindle
#

but small basic is

quick kindle
slate swan
carmine pilot
#

indeed

quick kindle
#

ok lester

boreal ravine
#

who's lester?

carmine pilot
#

BRUH

slate swan
carmine pilot
#

LMFAO

quick kindle
#

this guy

#

lul

slate swan
#

He cute tho ngl

quick kindle
#

๐Ÿคฃ

slate swan
#

No but really lets stay on topic

boreal ravine
#

!ot

unkempt canyonBOT
carmine pilot
#

.

quick kindle
#

...

slate swan
#

Yeah lets stay on topic

quick kindle
#

k

#

the main problem im facing while making music discord bots is the indentation. Otherwise, when I made the messaging discord bot, it was fine

#

maybe cuz i did the indentation right who knows?

slate swan
#

Indentation?

quick kindle
#

uh huh

slate swan
#

Of all things indentation?

quick kindle
#

yes

slate swan
#

Your kidding?

boreal ravine
quick kindle
#

and ofc the .env file

slate swan
#

Read pep 8 lol

quick kindle
slate swan
#

Its 4 spaces.

quick kindle
#

except python

slate swan
#

You gotta be joking indentations in python is so easy lol

quick kindle
#

nah

slate swan
#

!indents

unkempt canyonBOT
#

Indentation

Indentation is leading whitespace (spaces and tabs) at the beginning of a line of code. In the case of Python, they are used to determine the grouping of statements.

Spaces should be preferred over tabs. To be clear, this is in reference to the character itself, not the keys on a keyboard. Your editor/IDE should be configured to insert spaces when the TAB key is pressed. The amount of spaces should be a multiple of 4, except optionally in the case of continuation lines.

Example

def foo():
    bar = 'baz'  # indented one level
    if bar == 'baz':
        print('ham')  # indented two levels
    return bar  # indented one level

The first line is not indented. The next two lines are indented to be inside of the function definition. They will only run when the function is called. The fourth line is indented to be inside the if statement, and will only run if the if statement evaluates to True. The fifth and last line is like the 2nd and 3rd and will always run when the function is called. It effectively closes the if statement above as no more lines can be inside the if statement below that line.

Indentation is used after:
1. Compound statements (eg. if, while, for, try, with, def, class, and their counterparts)
2. Continuation lines

More Info
1. Indentation style guide
2. Tabs or Spaces?
3. Official docs on indentation

quick kindle
#

why did the code have to be dependent on indentation

quick kindle
boreal ravine
#

I mean it isnt even that hard

def func():
      ...

class Cog:
    def __init___(self):
        self.arg = ...

    async def do_stuff(self):
        ...
boreal ravine
slate swan
#

f?

quick kindle
boreal ravine
#

!resources

unkempt canyonBOT
#
Resources

The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.

boreal ravine
#

^^

slate swan
#

!pep8

unkempt canyonBOT
#

PEP 8 is the official style guide for Python. It includes comprehensive guidelines for code formatting, variable naming, and making your code easy to read. Professional Python developers are usually required to follow the guidelines, and will often use code-linters like flake8 to verify that the code they're writing complies with the style guide.

More information:
โ€ข PEP 8 document
โ€ข Our PEP 8 song! :notes:

quick kindle
#

ยฏ_(ใƒ„)_/ยฏ

slate swan
#

This will be useful to

maiden fable
#

Just use Flakes8 or Black. It will make u follow PEP8

slate swan
#

Does pylance make you follow pep8?

maiden fable
#

It's just a type checker

slate swan
#

I think it doesnt let you do 2spaces

#

Idk im not sure

maiden fable
slate swan
#

An in a comment i always use 1 lol

tawdry perch
#

I forgot again.. what is Flake8?

boreal ravine
#

!ot

unkempt canyonBOT
maiden fable
#

!pypi flake8

unkempt canyonBOT
slate swan
tawdry perch
#

ty

maiden fable
slate swan
quick kindle
#

hmm

#

unless

slate swan
#

Like my bad for getting a bit off topic

unkempt canyonBOT
maiden fable
#

Why pypi command uselessly

tiny ibex
maiden fable
#

Ah cool

#

Thought someone wanted to advertise Disnake lol

tiny ibex
maiden fable
#

Haha cool

boreal ravine
#

!ot

unkempt canyonBOT
maiden fable
#

.....

slate swan
#

Smh

#

Chill with it

boreal ravine
tiny ibex
slate swan
#

No need

boreal ravine
#

its ok just asking

quick kindle
#

Why did repl.it change its .env storing system tho, I just has this thought

quick kindle
#

i dunno, the tutorial guy was using replit

tiny ibex
#

And do not watch tutorials

quick kindle
#

then how will i make the programs

#

it was just a one time bot making program

tiny ibex
#

Do not watch those rubbish youtube tutorials

#

Specially not that guy who uses replit

boreal ravine
quick kindle
#

can we make the bot in pycharm?

tiny ibex
tiny ibex
quick kindle
#

oh ok

maiden fable
tiny ibex
boreal ravine
quick kindle
#

Bandwidth is a range of frequencies within a given band, in particular that used for transmitting a signal.

tiny ibex
boreal ravine
#

ยฏ\_(ใƒ„)_/ยฏ

tiny ibex
quick kindle
#

out of curiousity, is anyone a hacker here? White hat one?

tiny ibex
boreal ravine
tiny ibex
#

But off topic

tiny ibex
boreal ravine
#

No idea what selenium is

tiny ibex
boreal ravine
#

?

tiny ibex
#

!pypi selenium

unkempt canyonBOT
tiny ibex
#

!ot BTW

unkempt canyonBOT
boreal ravine
quick kindle
tiny ibex
tiny ibex
quick kindle
#

k

boreal ravine
quick kindle
#

lol

tiny ibex
boreal ravine
#

it isnt a local ide

tiny ibex
boreal ravine
#

yes

#

sure why not

quick kindle
#

this some big brain conversation

tiny ibex
boreal ravine
#

i mean i get good uptime

sullen shoal
#

damn these guys

quick gust
tiny ibex
boreal ravine
sullen shoal
#

also you can use selenium on replit but its slow asf and you cant run a webserver with it so its kinda useless most of the time

tiny ibex
sullen shoal
#

you get it when you select bash

tiny ibex
sullen shoal
#

then you gotta do some shit to run python that i forgot

sullen shoal
tiny ibex
#

Why instead of using these rubbish hacks just switch to a lot better platform

boreal ravine
#

and some python modules (webbrowser) arent even usable on replit because its an ONLINE
IDE and that isnt even a con about using replit, its just because its an online IDE and not a local one

tiny ibex
#

And how can we forget these

tiny ibex
#

It has went a bit too off-topic now

sullen shoal
boreal ravine
#

lmao

tough lance
#

Heh

dusk dock
#

So I've been away from the discord bot development scene for a bit, and with the cease of maintenance of the discord.py, I have a couple of questions I hope some of you guys could answer:

  1. What is the urgent drawback of this lack of maintenance? I've heard some information regarding an April 2022 deadline where bots in >75 servers need to an apply for a message intent and your bot needs to make a gateway request which discord.py hasn't handled, but I wanted to verify this information and maybe get some more if there is.

  2. What are some good alternatives to discord.py? I've heard that disnake and pycord are pretty good and have similar syntax to discord.py. Which do you guys prefer of the two? Are there better alternatives that you guys prefer more than these?

P.S I understand I am answering these questions at the risk of causing repetition. If there is somebody who has already answered these questions, could you please link me the message where they answered? It would be greatly appreciated. Also it would be awesome if you could ping when responding.

dusk dock
#

Yeah in regards to (2) I was asking based on preference, its hard to identify the objectively better alternative. Thanks for your response!

oak warren
#

yea 2 i like disnake too

tiny ibex
#

I just feel disnake is easy to use and more stable than others

oak warren
#

yea its almost like dpy v2

#

but the support server is ded af

tiny ibex
tiny ibex
oak warren
#

indents

oak warren
#

its in a if statement

dusk dock
tiny ibex
#

Can you even do that

oak warren
#

so that command wont register for will the onready work

dusk dock
tiny ibex
oak warren
#

is cmd always = "5" ?

tiny ibex
#

I don't think you can create commands inside an if statement

oak warren
#

^^

#

then ofc it wont work

#

you need to unindent the command nuke and the onready outside the if statement

oak warren
#

no

tiny ibex
dusk dock
#

Also, for disnake users: Does disnake have cogs like discord.py?

oak warren
#

it should work idk about same

boreal ravine
#

Is this a nuke bot?

tiny ibex
oak warren
boreal ravine
dusk dock
#

oh nice thanks

oak warren
boreal ravine
#

But be command name is nuke

dusk dock
tiny ibex
cobalt jacinth
#

any module that i can use to upload image and then send in the webhook using image url ?

unkempt canyonBOT
#

await send(content=..., *, username=..., avatar_url=..., tts=False, ephemeral=False, file=..., files=..., embed=..., embeds=..., allowed_mentions=..., view=..., thread=..., wait=False)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Sends a message using the webhook.

The content must be a type that can convert to a string through `str(content)`.

To upload a single file, the `file` parameter should be used with a single [`File`](https://discordpy.readthedocs.io/en/master/api.html#discord.File "discord.File") object.

If the `embed` parameter is provided, it must be of type [`Embed`](https://discordpy.readthedocs.io/en/master/api.html#discord.Embed "discord.Embed") and it must be a rich embed type. You cannot mix the `embed` parameter with the `embeds` parameter, which must be a [`list`](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.9)") of [`Embed`](https://discordpy.readthedocs.io/en/master/api.html#discord.Embed "discord.Embed") objects to send.
oak warren
cobalt jacinth
#

i wanna send image from webhook

tiny ibex
boreal ravine
tiny ibex
#

!d discord.Embed

unkempt canyonBOT
#

class discord.Embed(*, colour=Embed.Empty, color=Embed.Empty, title=Embed.Empty, type='rich', url=Embed.Empty, description=Embed.Empty, timestamp=None)```
Represents a Discord embed.

len(x) Returns the total size of the embed. Useful for checking if itโ€™s within the 6000 character limit.

bool(b) Returns whether the embed has any data set.

New in version 2.0.

Certain properties return an `EmbedProxy`, a type that acts similar to a regular [`dict`](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.9)") except using dotted access, e.g. `embed.author.icon_url`. If the attribute is invalid or empty, then a special sentinel value is returned, [`Embed.Empty`](https://discordpy.readthedocs.io/en/master/api.html#discord.Embed.Empty "discord.Embed.Empty").

For ease of use, all parameters that expect a [`str`](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.9)") are implicitly casted to [`str`](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.9)") for you.
cobalt jacinth
#

no...not using discord api...but requests

boreal ravine
tiny ibex
boreal ravine
cobalt jacinth
#

yes lib

tiny ibex
#

And making raw requests is hard

oak warren
#

that is blocking

boreal ravine
oak warren
#

i mean

boreal ravine
#

@oak warren bruh

oak warren
#

aiohttp

#

my bad

tiny ibex
#

You prolly meant use async functions

oak warren
#

yes

#

for which aiohttp

#

what dpy uses

cobalt jacinth
tiny ibex
dusk dock
#

Essentially if your bot is operating in less than 100 servers, the change in April won't affect the bot?

oak warren
#

yes

dusk dock
#

ok cool

oak warren
#

or else you can apply for message content intent

dusk dock
#

yeah

boreal ravine
#

not the file yet

dusk dock
#

but I don't think discord.py can make the gateway request anyway

#

so the change in april will still affect the bot even if you apply for the message intent

oak warren
dusk dock
#

thats the reason people are shifting over to disnake and pycord right?

tiny ibex
oak warren
#

idk honestly

cobalt jacinth
#

i am talking about taking a screenshot on my pc and then using requests to send webhook to a channel .

boreal ravine
#

they wanna send a file bruh

oak warren
tiny ibex
boreal ravine
oak warren
#

i forked it and edited disnake to discord

tiny ibex
oak warren
#

too lazy to write import disnake as discord in everyfile

dusk dock
tiny ibex
oak warren
boreal ravine
dusk dock
#

aah thanks

tiny ibex
oak warren
#

its mostly slash commands

tiny ibex
oak warren
#

idk if anyone uses user commands

#

slash commands = message commands

tiny ibex
oak warren
#

smh ok

tiny ibex
boreal ravine
#

slash commands are called slash for a reason lmao

oak warren
#

oh its app commands

boreal ravine
#

yes

oak warren
#

wow discord being discord

dusk dock
#

I've been out of the discord bot loop for too long

tiny ibex
dusk dock
#

lol I want to

lost wolf
#
    at Timeout.onTimeout (/home/runner/akinator/node_modules/discord.js/src/sharding/Shard.js:163:16)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7) {
  [Symbol(code)]: 'SHARDING_READY_TIMEOUT'
}```
#

wrong server

brave moth
#

if there is anyone here using the nextcord library, did they bring support for slash commands?

loud junco
#

what does this means

boreal ravine
# loud junco what does this means

The UnboundLocalError is raised when you try to assign a value to a local variable before it has been declared. You can solve this error by ensuring that a local variable is declared before you assign it a value. (or you could use the global keyword)

>>> number = 0
>>> def increase():
>>>   number += 1
>>> increase()

UnboundLocalError: local variable 'number' referenced before assignment
unkempt canyonBOT
#

When adding functions or classes to a program, it can be tempting to reference inaccessible variables by declaring them as global. Doing this can result in code that is harder to read, debug and test. Instead of using globals, pass variables or objects as parameters and receive return values.

Instead of writing

def update_score():
    global score, roll
    score = score + roll
update_score()

do this instead

def update_score(score, roll):
    return score + roll
score = update_score(score, roll)

For in-depth explanations on why global variables are bad news in a variety of situations, see this Stack Overflow answer.

loud junco
#
> >>> def increase():
> >>>   number = 0
> >>>   number += 1
> >>> increase()
> ```
boreal ravine
#

wut

loud junco
#

like this?

#

oo global blah blah

#

or return blah blah

#

but how do i make ctx.author.id global

#

it will tell ctx not defined

maiden fable
#

๐Ÿ˜ What's happening

loud junco
#

i wanna do this

#

i wanna make it global

#

but ctx will not be defined

slate swan
loud junco
upbeat otter
loud junco
slate swan
upbeat otter
loud junco
#

how to global it

#

global userid?

upbeat otter
loud junco
#

ok

rocky mist
#

aaaaaaaaaaAAAAAAAAAAAAAAAA

Can some1 explain??

upbeat otter
#
@client.command()
async def this_command_is_so_so_secretive_that_no_one_will_ever_use_it_in_fact_never_try_to_type_it_out(ctx):
  global userid
  userid = str(ctx.author.id)

@loud junco

upbeat otter
unkempt canyonBOT
#

Indentation

Indentation is leading whitespace (spaces and tabs) at the beginning of a line of code. In the case of Python, they are used to determine the grouping of statements.

Spaces should be preferred over tabs. To be clear, this is in reference to the character itself, not the keys on a keyboard. Your editor/IDE should be configured to insert spaces when the TAB key is pressed. The amount of spaces should be a multiple of 4, except optionally in the case of continuation lines.

Example

def foo():
    bar = 'baz'  # indented one level
    if bar == 'baz':
        print('ham')  # indented two levels
    return bar  # indented one level

The first line is not indented. The next two lines are indented to be inside of the function definition. They will only run when the function is called. The fourth line is indented to be inside the if statement, and will only run if the if statement evaluates to True. The fifth and last line is like the 2nd and 3rd and will always run when the function is called. It effectively closes the if statement above as no more lines can be inside the if statement below that line.

Indentation is used after:
1. Compound statements (eg. if, while, for, try, with, def, class, and their counterparts)
2. Continuation lines

More Info
1. Indentation style guide
2. Tabs or Spaces?
3. Official docs on indentation

loud junco
#

ur spacing

rocky mist
upbeat otter
loud junco
#

its the tab spacing

rocky mist
loud junco
#

like this
and this
and this

upbeat otter
unkempt canyonBOT
#
Resources

The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.

upbeat otter
#

learn python first

loud junco
#

ya

loud junco
#

:D

rocky mist
#

[pyflakes] unindent does not match any outer indentation level

Still doesn't work (wait)

#

My previous codes are fine

upbeat otter
#

and please

#

try to code on a text/code editor

#

replit is meh

rocky mist
upbeat otter
#

100x better

loud junco
upbeat otter
loud junco
#

github good

upbeat otter
#

ikr

rocky mist
#

ok Merio

rocky mist
#

can we run codes on GitHub????

#

THAT WOULD BE INSANE

loud junco
rocky mist
loud junco
#

u cant run in github but

rocky mist
#

Replit kinda sucks

rocky mist
loud junco
heavy folio
#

live share

loud junco
#

that will work also

#

visible confusion

sinful pasture
#

ok i feel like a dumb fuck but when doing embeds

value = "Shrek
Donkey"

I need them to be on 2 separate lines but they appear in the same line.

lyric tusk
#

this is a logger code ```py
@client.event
async def on_message_delete(message):
embed = nextcord.Embed(title=f"{message.author.name} has deleted a message | {message.author.id}", description=f"{message.content}")
channel = client.get_channel()
await channel.send(embed=embed)

@client.event
async def on_message_edit(message_before, message_after):
embed = nextcord.Embed(title=f"{message_before.author.name} has edited a massege | {message_before.author.name}")
embed.add_field(name="before Massage", value=f"{message_before.content}", inline=False)
embed.add_field(name="After Massage", value=f"{message_after.content}", inline=False)
channel = client.get_channel()
await channel.send(embed=embed) ```
how can i make it so it can be in more then 1 server and log and admins have perms that they can chance what chat it going to log in?

sinful pasture
#

what

full valley
#

Basic python

#

new line character

sinful pasture
#

ive got a very basic brain

#

oh ok

sinful pasture
#

is it / or \

upbeat otter
lyric tusk
sinful pasture
#

k

boreal ravine
upbeat otter
graceful verge
#

how to make verify??

upbeat otter
graceful verge
#

1

upbeat otter
graceful verge
#

with button

upbeat otter
#

depends on your dpy version

graceful verge
#

?

upbeat otter
#

?

graceful verge
#

how to make a button and verifications

upbeat otter
graceful verge
#

idk pyton or python3

upbeat otter
graceful verge
#

sorry for my English

#

3

#

I guess

graceful verge
#

sorry bro

upbeat otter
graceful verge
#

I do not remember

#

wait

upbeat otter
#

......

tawdry perch
full valley
#

Sorry I literally just saw u said the same @upbeat otter

upbeat otter
graceful verge
#

i use vps

upbeat otter
full valley
#

Vps doesnโ€™t just come with d py

loud junco
full valley
graceful verge
#

1.7.3

loud junco
#

i swear to god i make that global

graceful verge
#

@upbeat otter

upbeat otter
graceful verge
#

what?

upbeat otter
#

!pypi discord_components

unkempt canyonBOT
loud junco
#

help me

graceful verge
#

dm

loud junco
#

:/

graceful verge
#

I sent the picture on dm

gloomy pewter
#

How to insert dictionary python using asyncpg?

full valley
#

@loud junco Why can u just define the variables normally outside a function

tough lance
full valley
#

and see if that works

gloomy pewter
# gloomy pewter How to insert dictionary python using asyncpg?
    def __init__(self, bot):
        self.bot = bot
        self.bot.loop.run_until_complete(self.create_db_pool())

    @commands.Cog.listener()
    async def on_ready(self):
        await self.db.execute(
            """CREATE TABLE IF NOT EXISTS coba (author_id BIGINT, data TEXT[])"""
        )

    async def create_db_pool(self):
        self.db = await asyncpg.create_pool(
            database="kamus", user="postgres", password="083806637610"
        )

    async def add_kamus(self, author_id, key, value):
        if akun := await self.dapat_kamus(author_id):
            hasil = akun[1]
            a_kamus = {key: value}
            hasil.append(a_kamus)
            update = await self.db.execute('UPDATE coba SET data = $1 WHERE author_id = $2', hasil, author_id)
            return update
        else:
            hasil = {key: value}
            coba = await self.db.execute('INSERT INTO coba (author_id, data) VALUES ($1, $2)', author_id, [hasil])
            return coba
    
    async def dapat_kamus(self, id):
        akun = await self.db.fetchrow('SELECT * FROM coba WHERE author_id = $1', id)
        return akun
    
    @commands.command()
    async def tambahkamus(self, ctx, key, value):
        await self.add_kamus(ctx.author.id, key, value)โ€Š
#

error

full valley
#

I donโ€™t see the point of defining global variables in a function

tough lance
#

Yup

gloomy pewter
#
Traceback (most recent call last):
  File "asyncpg\protocol\prepared_stmt.pyx", line 168, in asyncpg.protocol.protocol.PreparedStatementState._encode_bind_msg
  File "asyncpg\protocol\codecs/base.pyx", line 206, in asyncpg.protocol.protocol.Codec.encode
  File "asyncpg\protocol\codecs/base.pyx", line 111, in asyncpg.protocol.protocol.Codec.encode_scalar
  File "asyncpg\protocol\codecs/array.pyx", line 853, in asyncpg.protocol.protocol.arraytext_encode
  File "asyncpg\protocol\codecs/array.pyx", line 134, in asyncpg.protocol.protocol.array_encode
ValueError: invalid array element at index 0: expected str, got dictโ€Š
upbeat otter
#

coughs

full valley
#

bruh

tough lance
upbeat otter
#

thats why my dms are always closed ;-;

full valley
#

@graceful verge Iโ€™d suggest you learn python first, and get familiar with what libraries are.

graceful verge
#

๐Ÿ˜ฆ

full valley
#

You arenโ€™t going to learn just asking for code

#

disappointing

upbeat otter
unkempt canyonBOT
#
Resources

The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.

graceful verge
#
-bash: !resources: event not found
tough lance
#

WHAT

tiny ibex
#

How can I set the button size?

upbeat otter
tough lance
tiny ibex
tough lance
#

Otherwise you can't

tiny ibex
#

I created a button and it's just the normal size

#

But in this

#

It's fcking long

tough lance
graceful verge
#

just give me the source code

tiny ibex
tough lance
quick gust
heavy folio
#

!d discord.ui.Button

unkempt canyonBOT
#

class discord.ui.Button(*, style=<ButtonStyle.secondary: 2>, label=None, disabled=False, custom_id=None, url=None, emoji=None, row=None)```
Represents a UI button.

New in version 2.0.
heavy folio
#

discord-components breaks dpy

graceful verge
#

I'm just learning python

tough lance
#

Something like that

tiny ibex
quick gust
tiny ibex
#

Understood

heavy folio
upbeat otter
tiny ibex
tough lance
#

Then tell them to update

tiny ibex
#

lol

loud junco
loud junco
heavy folio
upbeat otter
tacit horizon
#

help shipit

tough lance
#

Yes?

full valley
# loud junco oo wait

youโ€™re defining global variables inside a function, iโ€™m saying just do it outside of the function

heavy folio
#

not code i mean pip install statement

upbeat otter
boreal ravine
#

I get "cant set attribute" when im trying to set a dict to bot.cogs. Why?

loud junco
tacit horizon
#
if message.content == 'c':
        await message.add_reaction("\U0001F60E")
```why this is not working
boreal ravine
full valley
# loud junco this

that makes no sense, you canโ€™t have a global variable of an author

#

I mean u could but why

tacit horizon
tough lance
#

Is the message actually c?

tacit horizon
#

ya

slate nymph
#
@commands.command()
    @commands.cooldown(1,5,commands.BucketType.user)
    async def gamble(self,ctx,amount):
        try:
            amount = int(amount)
        except ValueError:
            self.bot.get_command("gamble").reset_cooldown(ctx)
            return await ctx.send("You have to give an integer small brain")
        
        if amount < 100:
            self.bot.get_command("gamble").reset_cooldown(ctx)
            return await ctx.send("At least gamble 100 coins")```

how to code it so if the amount is "all" it becomes an int
wide tartan
#

the channel variable isnt working. I'm trying to get it to create a channel.

#

this is my guild variable

#

guild = self.bot.get_guild(self.guild_id)

#

self.guild_id has the guild ID

full valley
slate nymph
#
@commands.command()
    @commands.cooldown(1,5,commands.BucketType.user)
    async def gamble(self,ctx,amount):
        try:
            amount = int(amount) or "all"
            if amount == "all":
                amount = await current_balance(ctx.author)
            else:
                amount = amount
        except ValueError:
            self.bot.get_command("gamble").reset_cooldown(ctx)
            return await ctx.send("You have to give an integer small brain")
        
        if amount < 100:
            self.bot.get_command("gamble").reset_cooldown(ctx)
            return await ctx.send("At least gamble 100 coins")```
#

tried this but didnt work

slate nymph
full valley
unkempt magnet
#

How do I make a discord bot command that takes a text argument?

slate nymph
#

the indents are wrong

full valley
#

and what exactly u are typing for the command

unkempt magnet
#

a command that would be "/message {{any string text}} {{channel}}

slate nymph
full valley
#

right

slate nymph
#

if not then the amount should be an int

full valley
#

Any errors?

tacit horizon
#
client = commands.Bot(command_prefix= "!")


@client.event 
async def on_ready():
    await client.change_presence(status=discord.Status.idle, activity= discord.Activity(type = discord.ActivityType.listening, name = 'EggyinIt'))
    print('logged in {0.user}'.format(client))

@client.event
async def on_message(message):
    await client.process_commands(message)
    if message.author == client.user:
        return
    if message.content == 'what':
        await message.add_reaction("\U0001F60E")
        print("REACT")
slate nymph
#

wait

quick gust
#

u have 2 if statements

slate swan
unkempt magnet
slate swan
slate nymph
unkempt magnet
slate swan
#

by default all received arguments would be string

quick gust
unkempt magnet
#

ok

slate swan
tacit horizon
slate nymph
unkempt magnet
#

and how would i collect this data and make the bot message the string in the appropriate channel?

slate swan
#

arg being the received string argument and channel being a discord.TextChannel object

full valley
tough lance
# slate nymph this one
@commands.command()
    @commands.cooldown(1,5,commands.BucketType.user)
    async def gamble(self,ctx,amount):
        try:
            if amount == "all":
                amount = await current_balance(ctx.author)
            else:
                amount = int(amount)
        except ValueError:
            self.bot.get_command("gamble").reset_cooldown(ctx)
            return await ctx.send("You have to give an integer small brain")
        
        if amount < 100:
            self.bot.get_command("gamble").reset_cooldown(ctx)
            return await ctx.send("At least gamble 100 coins")โ€Š
quick gust
unkempt magnet
slate swan
slate nymph
#

okay

quick gust
unkempt magnet
rapid walrus
#

guys is there anyway to load script from raw website?

slate swan
unkempt magnet
# slate swan the discord.py library

alright would this code work? ```py
@client.command()
async def messahe(ctx):
arg: str
channel: discord.TextChannel
await ctx.channel.send(arg)

slate swan
unkempt magnet
#

is it?

full valley
slate swan
#

put it after ctx, e.g.

async def message(ctx, arg: str, channel: discord.TextChannel):
wide tartan
slate nymph
#
File "C:\Users\sony\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 173, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\Users\sony\Desktop\Bot2\cogs\economy.py", line 105, in gamble
    if amount < 100:
TypeError: '<' not supported between instances of 'str' and 'int'
full valley
slate nymph
slate swan
#

showcode

slate nymph
#
@commands.command()
    @commands.cooldown(1,5,commands.BucketType.user)
    async def gamble(self,ctx,amount):
        if amount == "all":
            amount = await current_balance(ctx.author)
        if amount < 100:
            self.bot.get_command("gamble").reset_cooldown(ctx)
            return await ctx.send("At least gamble 100 coins")```
unkempt magnet
#
@client.command()
async def message(ctx, arg: str, channel: discord.TextChannel):
   

client.run(TOKEN)
#

so that?

tawdry perch
slate swan
visual island
slate nymph
slate swan
loud junco
slate swan
loud junco
#

ok

tiny ibex
full valley
#

does current_balance return an integer or string @slate nymph

tiny ibex
#
class Nitro(disnake.ui.View):
    def __init__(self):
        super().__init__()

    @disnake.ui.button(style=disnake.ButtonStyle.blurple, label="\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200bACCEPT\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b\u200b", row=0)
    async def rickroll(self, button: disnake.ui.Button, interaction: disnake.Interaction):
        await interaction.response.send_message("https://c.tenor.com/Z6gmDPeM6dgAAAAC/dance-moves.gif", ephemeral=True)```
tawdry perch
loud junco
slate nymph
#
@commands.command()
    @commands.cooldown(1,5,commands.BucketType.user)
    async def gamble(self,ctx,amount):
        try:
            amount = int(amount) or "all"
            if amount == "all":
                amount = await current_balance(ctx.author)
            else:
        except ValueError:
            self.bot.get_command("gamble").reset_cooldown(ctx)
            return await ctx.send("You have to give an integer small brain")```
loud junco
#

and userid will be undefined :/

slate nymph
#

dw about indent

tough lance
tawdry perch
finite flower
#

!resources

slate swan
#

me when terrible code logic

slate nymph
#

Yes

full valley
#

@slate nymph Well firstly, donโ€™t redefine amount, use a difference variable

finite flower
#

!resources

loud junco
full valley
#

since amount is a argument

finite flower
#

!resources

slate nymph
#

ok

slate swan
tawdry perch
finite flower
#

okay

wide tartan
tiny ibex
#

Not working as well

tough lance
visual island
tiny ibex
loud junco
#

!global

unkempt canyonBOT
#

When adding functions or classes to a program, it can be tempting to reference inaccessible variables by declaring them as global. Doing this can result in code that is harder to read, debug and test. Instead of using globals, pass variables or objects as parameters and receive return values.

Instead of writing

def update_score():
    global score, roll
    score = score + roll
update_score()

do this instead

def update_score(score, roll):
    return score + roll
score = update_score(score, roll)

For in-depth explanations on why global variables are bad news in a variety of situations, see this Stack Overflow answer.

wide tartan
tiny ibex
loud junco
#

i literally pressed on the accept ๐Ÿคฃ

tiny ibex
#
class Nitro(disnake.ui.View):
    def __init__(self):
        super().__init__()

    @disnake.ui.button(style=disnake.ButtonStyle.blurple, label="             ACCEPT              ", row=0)
    async def rickroll(self, button: disnake.ui.Button, interaction: disnake.Interaction):
        await interaction.response.send_message("https://c.tenor.com/Z6gmDPeM6dgAAAAC/dance-moves.gif", ephemeral=True)```
tiny ibex
loud junco
#

rickroll :/

tiny ibex
#

But spaces not working

loud junco
#

what spaces

#

oo

tiny ibex
loud junco
#

discord will auto remove too long spaces ig

tiny ibex
slate swan
#

u/200b

tiny ibex
#

Doesn't work

slate nymph
#

works perfectly now tysm!

slate swan
#

elaborate

tiny ibex
#

In the button

mortal thistle
#

hello

slate swan
mortal thistle
#

how do I make my bot log invite creation

slate swan
tiny ibex
slate swan
tiny ibex
#

Cool

slate swan
#

spaces

tiny ibex
#

Lemme try

mortal thistle
#

life if someone creates an invite, bot will send msg exampls: user created invite

#

any help?

tiny ibex
tough lance
tiny ibex
tough lance
#

I just did accept

slate swan
tiny ibex
#

The full code please

tough lance
tiny ibex
mortal thistle
#

...

tiny ibex
#

So?

tough lance
tiny ibex
#

Literally fck

boreal ravine
#

why cant i edit bot.cogs to another value

tough lance
#

Wdym?

upbeat otter
boreal ravine
tiny ibex
tough lance
#

I usually change the methods like that

boreal ravine
#

ok brb

tiny ibex
#

Doesn't solve

upbeat otter
loud junco
#

\t

tiny ibex
tough lance
upbeat otter
#

example

boreal ravine
tough lance
maiden fable
tough lance
#

Why tho

slate swan
#

Viva JavaScript

tough lance
maiden fable
#

It's possible that the library can break just cz u overwrote a variable u weren't supposed to sadcat

maiden fable
boreal ravine
#

but like i wanna make my cogs lowercase too and idk any other method to do this

tiny ibex
#

Doesn't work

tiny ibex
maiden fable
#

@slate swan ignore the ping

maiden fable
#

Copy this emoji

tiny ibex
maiden fable
tough lance
#

Unicode

tiny ibex
maiden fable
#

๓ €  U+E0020 This is the unicode for the emoji tho

tiny ibex
#

And I don't think I can even paste that in IDE

#

I caan't

maiden fable
#

Wym?

#

Just click on the Copy button

tiny ibex
maiden fable
#

Rip

tough lance
#

Lol

upbeat otter
tiny ibex
#

NVM I can see some yellow boxes in IDE something I never saw before

#

But doesn't work

upbeat otter
#

try this emoji

#

nvm

tiny ibex
maiden fable
upbeat otter
tiny ibex
tiny ibex
upbeat otter
tiny ibex
#

Emoji buttons should work maybe?

upbeat otter
maiden fable
#

@tiny ibex which unicodes have u tried?

upbeat otter
#

idk, ask hunter, igtg

tiny ibex
maiden fable
#

\u2800

tiny ibex
boreal ravine
#

@tiny ibex what are you tryna do

tiny ibex
#

It worked

#

Finally

tiny ibex
maiden fable
tiny ibex
maiden fable
loud junco
#

why is it still not defined

#

:/

tawdry perch
#

use botvar instead of global ones

loud junco
#
botvar userid, pogchop, cooked_pogchop, beef, steak, hp, level, highestArea, atk, defend
```like this?
#

or what

tawdry perch
#

!botvar

unkempt canyonBOT
#

Python allows you to set custom attributes to most objects, like your bot! By storing things as attributes of the bot object, you can access them anywhere you access your bot. In the discord.py library, these custom attributes are commonly known as "bot variables" and can be a lifesaver if your bot is divided into many different files. An example on how to use custom attributes on your bot is shown below:

bot = commands.Bot(command_prefix="!")
# Set an attribute on our bot
bot.test = "I am accessible everywhere!"

@bot.command()
async def get(ctx: commands.Context):
    """A command to get the current value of `test`."""
    # Send what the test attribute is currently set to
    await ctx.send(ctx.bot.test)

@bot.command()
async def setval(ctx: commands.Context, *, new_text: str):
    """A command to set a new value of `test`."""
    # Here we change the attribute to what was specified in new_text
    bot.test = new_text

This all applies to cogs as well! You can set attributes to self as you wish.

Be sure not to overwrite attributes discord.py uses, like cogs or users. Name your attributes carefully!

loud junco
#

:/

#

bot.var?

#

i wanna make it global

#

so i dont need to repeat them

tawdry perch
#
bot.whatever = "hello"
#usage eg
await ctx.send(bot.var) #in theory it should work
loud junco
#

oo

#

lemme try

tawdry perch
#

you store them to bot variables and can use them like bot.<variable_or_whatever_you_named_this> and do what ever you want

#

they will be usable all over that file (or if you would use cogs it would be usable in those cogs)

loud junco
#

alright forget it

#

it wont work

tawdry perch
#

why not?

loud junco
#

just do the global thing

tawdry perch
#

ยฏ_(ใƒ„)_/ยฏ

loud junco
#

then i need to define userid everywhere

#

that is what i dont want to

boreal ravine
#

literally everyone does that though

#

theres no way you could make a variable containing ctx.author.id since ctx is gonna be undefined

loud junco
#

thats the problem

#

but all my variable is like this

  pogchop = db[userid + 'pogchop']
  cooked_pogchop = db[userid + 'cooked_pogchop']
  beef = db[userid + 'beef']
  steak = db[userid + 'steak']
  hp = db[userid + 'hp']
  level = db[userid + 'level']
  highestArea = db[userid + 'highestArea']
  atk = db[userid + 'atk']
  defend = db[userid + 'defend']
#

so userid is going to be undefined as well

tawdry perch
#

I don't think global is the way to go

loud junco
#

:/

#

then what can i do

loud junco
#

no

#

i mean

#
userid = str(ctx.author.id)
boreal ravine
#

uh

tawdry perch
#

could you explain again what you want to do @loud junco

loud junco
#

i dont wanna repeat to call the variable

#

so i wanna make them global variable

tawdry perch
#

!global

unkempt canyonBOT
#

When adding functions or classes to a program, it can be tempting to reference inaccessible variables by declaring them as global. Doing this can result in code that is harder to read, debug and test. Instead of using globals, pass variables or objects as parameters and receive return values.

Instead of writing

def update_score():
    global score, roll
    score = score + roll
update_score()

do this instead

def update_score(score, roll):
    return score + roll
score = update_score(score, roll)

For in-depth explanations on why global variables are bad news in a variety of situations, see this Stack Overflow answer.

loud junco
#

???

tawdry perch
#

so you just have global foo, bar, foobar and add the values you want?

loud junco
#

this is what i did

tawdry perch
#

I don't ever use global so I can't really help

slate swan
#

so

#

global wasd

wasd=4

loud junco
#

wdym

#

:/

tawdry perch
#

global variables above function

loud junco
#

=.=

loud junco
#

:/

violet nymph
#

Why not just tell it to return x?

loud junco
#

wdym

full valley
violet nymph
#

In the first function, just add return x...

loud junco
#

ok

violet nymph
#

In 2nd do x = myfunc()

loud junco
#

forget it

#

it will just make things messier than before

violet nymph
#

Don't see how...

unkempt magnet
#
from discord.ext.commands import bot
from discord.ext.commands.bot import Bot
from discord_slash import SlashCommand
from discord.ext import commands, tasks
import discord
from discord import message
from discord import channel

client = commands.Bot(command_prefix='!')
slash = SlashCommand(client, sync_commands=True)


TOKEN = 'Secret Token'

@client.command()
async def message(ctx, arg: str, channel: discord.TextChannel):
    await channel.send(arg)

client.run(TOKEN)
#

anyone know why its not working?

#

it doesnt even show up in the command menu as a command

upbeat otter
unkempt magnet
#

so it needs to run that long?

slate swan
#

It's just a normal command....

#

Did you rerun the bot?

unkempt magnet
#

wait its not a slash command?!

#
@slash.slash(name="Message", description="Send a message in a channe;")
async def message(ctx, arg: str, channel: discord.TextChannel):
    await channel.send(arg)
#

would that work?

slate swan
#

don't know tbh , never used the discord_slash library

unkempt magnet
#

does anyone else know

unkempt magnet
slate swan
#

never used discord_slash

tawdry perch
unkempt magnet
slate swan
#

I set the banner color to be the same as the bar below and the color changes to a different one. Who knows what color you need to set

unkempt magnet
#

either

slate swan
#

show code

#

elaborate on "doesn't work"

unkempt magnet
#
from discord.ext.commands import bot
from discord.ext.commands.bot import Bot
from discord_slash import SlashCommand
from discord.ext import commands, tasks
import discord
from discord import message
from discord import channel

client = commands.Bot(command_prefix='!')
slash = SlashCommand(client, sync_commands=True)


TOKEN = 'secret'

@client.command()
async def message(ctx, arg: str, channel: discord.TextChannel):
    await channel.send(arg)

client.run(TOKEN)
slate swan
#

cover it please

#

in three backticks

#

any error

unkempt magnet
#

nothing until i try use the command

slate swan
#

then what happens

#

after you use the command

craggy cloak
#
@client.command()
async def test(ctx):
  msg = await ctx.send("The game has ended, thanks for playing!")
  await msg.add_reaction('โœ…')
  await ctx.message.delete()

How can i add when someone press the button it give a role to the member that pres the button?

unkempt magnet
#

too long to send here

#

it wont let me

slate swan
#

just send the last part

unkempt magnet
#
RuntimeError: Event loop is closed
cobalt jacinth
#

is it possible make command flexible like
?power ,?po, ?pow all work the same

unkempt magnet
#

aliases i think

slate swan
craggy cloak
cobalt jacinth
slate swan
#

do you have intents on @unkempt magnet

unkempt magnet
#

is how the command is sent

slate swan
#

and are you sure you aren't trying to execute code after the client.run()

slate swan
unkempt magnet
#

yes 100%

unkempt magnet
cobalt jacinth
tawdry perch
unkempt magnet
tawdry perch
#

!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.

slate swan
# unkempt magnet how would i do that?

go to the dev portal, your application, bot, enable all intents you can find, later make a variable intents = discord.Intents.all() and pass it to the client constructor

#

the runtimeerror can be caused by lack of intents

unkempt magnet
#

where do i pass intents?

slate swan
#

client variable

#

put intents=intents inside the brackets, after command_prefix

unkempt magnet
#

ok

slate swan
#
intents = discord.Intents.all()
client = commands.Bot(command_prefix='!', intents=intents)```
unkempt magnet
#

yup I have that now

#

alright rerun it, same errors

slate swan
#

did you enable intents on the dev portal?

unkempt magnet
#

yes,

slate swan
#

give full traceback

unkempt magnet
#

message intents, member intents

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.

unkempt magnet
#

alright but unfortunately the traceback included sensitive info

slate swan
#

remove the sensitive info

unkempt magnet
#

its in every line

#

its my full name

slate swan
#

either dm me the traceback or make a text editor replace all the sensitive info with something else

unkempt magnet
#

ok

#

how do i find and replace in vsc?

slate swan
unkempt magnet
#

i got it

#

there you go

tawdry perch
#

You passed wrong token

slate swan
#

improper token

unkempt magnet
#

alright, i have now fixed such error

#

thank you!

craggy cloak
#
# TEST
@client.command()
async def end(ctx):
  guild = ctx.guild
  msg = await ctx.send("The game has ended, thanks for playing!")
  await msg.add_reaction('โœ…')
  await ctx.message.delete()


  discord.Client.wait_for(msg.add_reaction)
  role = guild.get_role(880511595464249374)
  await ctx.add_roles(role)

it is not giving the role?

slate swan
#

error?

craggy cloak
#

no error

slate swan
#

also it's user.add_roles() iirc

craggy cloak
#

but user = not ctx.author how can i define that then?

slate swan
#

also you should pass a timeout and check kwarg to wait_for

#

it's instance.wait_for(), so you'd do client.wait_for() instead of discord.Client.wait_for()

slate swan
craggy cloak
#

Nobody plays the game, the intention is that everyone should press the emoji and that the bot ensures after 2 minutes, for example, that everyone has received the role

#

So i don't know how i can define user because anyone can press the button

slate swan
#

wait_for takes a string argument iirc

loud junco
#

what is this error

slate swan
#

can't compare int and str

craggy cloak
#

I need to use await client.wait_for("reaction_add", check=check)

loud junco
slate swan
slate swan
loud junco
#

ok

#

oof

#

i added ' ' in highestArea

#

idk why did i does it

#

aw man

#

here we go again

slate swan
#

define it

loud junco
loud junco
#

:/

slate swan
#

in another function

loud junco
#

how

slate swan
#

learn about scopes

loud junco
#

ok

slate swan
#

also, you're calling variable() without await

loud junco
#

oo

#

ok its working

slate swan
#

and you aren't saving the returned values in anything

loud junco
#

lemme remove that

#

i added and remove tons of stuff to make that global func

unkempt magnet
#

if I want to send a sentence it doesnt recognize it

#

for some reason it looks for the second word in the message and tries to use that as the channel

#

causing an error

slate swan
#

put the sentence in quotes

unkempt magnet
slate swan
#

no problem

loud junco
#

what does this error means

#

=.=

slate swan
#

you tried to use the variable before you defined it

loud junco
#

oo

#

lemme show u

unkempt canyonBOT
#

Hey @loud junco!

Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:

โ€ข If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)

โ€ข If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:

https://paste.pythondiscord.com

loud junco
#

@slate swan

#

i dont understand

slate swan
#

which line throws the error

#

also instead of building an elif chain you could just use a formula to calculate everything

loud junco
#

its not adding evenly

slate swan
#

why are there two return statements

loud junco
#

ignore that

#

๐Ÿคฃ

slate swan
#

which line throws the error

loud junco
#

thats not the error

tiny ibex
#

Can someone give me an example of the timeout kwarg in buttons?

slate swan
#

what lib

loud junco
tiny ibex
loud junco
slate swan
# loud junco

you prob failed to pass an arg that the elif chain detects, hence the error

dapper cobalt
# loud junco

modef might have failed to be defined, and does not have a default value.

loud junco
#

there is a red thing on the sliding thing

#

but it is not in my codes :/

dapper cobalt
dapper cobalt
slate swan
tiny ibex
#

They both are the same

loud junco
tiny ibex
loud junco
#

i have an idea

dapper cobalt
tiny ibex
loud junco
dapper cobalt
# tiny ibex disnake
import asyncio
try:
  inter = await bot.wait_for("button_click", timeout=60.0) # This   will set a timeout for 60 seconds
except asyncio.TimeoutError:
  return
tiny ibex
dapper cobalt
#

That's how you set a timeout for a wait_for.

tiny ibex
dapper cobalt
#

Then don't pass a kwarg.

tiny ibex
dapper cobalt
#

Ah, show me your code.

#

You have to respond to the interaction. Not just reply.

tiny ibex
#

If you don't pass anything