#discord-bots

1 messages · Page 668 of 1

ebon island
#

that will properly catch/handle it?

slate swan
#

You can install it through the command tool, but I’d not think that is in the chrome book version

manic wing
#
try:
      await ctx.send(…)
except discord.HTTPException:
      pass```
lost wolf
#

what one

velvet tinsel
#

Hello Caeden

slate swan
velvet tinsel
#

correct

ebon island
#

Thanks Caeden, I will try it 🙂

lost wolf
slate swan
#

Learn to have some patience

lost wolf
#

i cant

slate swan
#

Why?

velvet tinsel
#

you cant have patience?

#

😭

slate swan
#

lol

velvet tinsel
#

I thought you were a discord dev

slate swan
#

Average python user

#

How can i fix this?

#

You are a discord bot developer yet your having trouble event downloading python

#

Good one

velvet tinsel
#

bruh

#

my old user was downloadpython

slate swan
#

I’ve seen on_message and bot.command() but yield from?

#

@client.command()

#

Send whole command

#

So I can get some context from what your doing

slate swan
#

Are you trying to send a message from the on_message event

slate swan
#

If so message.channel.send(“text”) should work

slate swan
#

Idk where your getting “yield from” from

final iron
slate swan
#

Open() is async right

#

🕴️

velvet tinsel
#

🕴️

slate swan
#

That emoji scares me

velvet tinsel
#

You use aiofiles

slate swan
#

It’s so confusing

velvet tinsel
#

I think yert

slate swan
#

Screaming rn

velvet tinsel
#

I think you use aiofiles

slate swan
#

Contacting my lawyer

#

how can i create an error handler for IndexError's?

velvet tinsel
velvet tinsel
slate swan
#

would i still use that?

slate swan
velvet tinsel
velvet tinsel
slate swan
#
except Exception for IndexError:
    blah```
#

right?

velvet tinsel
#

no

#

except IndexError

slate swan
#

oh alright

#

thanks

manic wing
#

no

final iron
slate swan
#

And don't use a bare except lol

manic wing
#

you would make an event error handler

velvet tinsel
#

Caeden gonna go god mode

#

yert this is my favourite part

slate swan
#

Is there a way I can check if a User has the 10$ version of Nitro?

velvet tinsel
#

I like it when Caeden says some cool sounding words jam_cavedude and becomes hella smart

lost wolf
slate swan
velvet tinsel
slate swan
velvet tinsel
#

Oh

manic wing
#

!d discord.on_error || but you also need to edit your discord.py sourcecode because danny kinda fucked it up

unkempt canyonBOT
#

discord.on_error(event, *args, **kwargs)```
Usually when an event raises an uncaught exception, a traceback is printed to stderr and the exception is ignored. If you want to change this behaviour and handle the exception for whatever reason yourself, this event can be overridden. Which, when done, will suppress the default action of printing the traceback.

The information of the exception raised and the exception itself can be retrieved with a standard call to [`sys.exc_info()`](https://docs.python.org/3/library/sys.html#sys.exc_info "(in Python v3.9)").

If you want exception to propagate out of the [`Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") class you can define an `on_error` handler consisting of a single empty [raise statement](https://docs.python.org/3/reference/simple_stmts.html#raise "(in Python v3.9)"). Exceptions raised by `on_error` will not be handled in any way by [`Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client").
slate swan
velvet tinsel
#

It’s Caeden

slate swan
#

Use an online service for running your python code

slate swan
velvet tinsel
#

😳

#

Stack overflow wtf

velvet tinsel
slate swan
#

this code wants to murder my terminal

#

i get so many errors

#

what im trying to do is get a token from a list of bot tokens and get the username and id of it and print it to the console

#

then running the main bot

velvet tinsel
#

What’s wrong

slate swan
#

everything

velvet tinsel
#

Everything doesn’t specify

slate swan
#

its returning the name and id of the bots in the list

#

but then it throws an error when trying to run the main bot

#

i assume its because im using bot.close()

#

which is throwing off something

velvet tinsel
#

Which error

slate swan
#

ill send teh traceback

velvet tinsel
#

ok

slate swan
velvet tinsel
#

I think

#

You ran the token twice

#

And it threw an error

#

It’s something to do with the run() function ig

slate swan
#

i figured that

#

the tokens it is running are two seperate bots

#

(memer and memer2)

#

you leaked your token

#

😢

#

did I

#

refresh it in the dev portal quickly

#

Is this how I change a channels permission for a specific role?

member_role = ctx.channel.overwrites_for(918955830810923049)
member_role.send_messages = False
slate swan
#

i did not

#

what should I do to prove it to you

#

I sent it to you

#

nvm i did

#

indeed you did thinkmon

#

refreshed

#

it wasnt in any servers anyway

leaden jasper
#

how to make a clear command

slate swan
#

!d discord.TextChannel.purge

unkempt canyonBOT
#

await purge(*, limit=100, check=..., before=None, after=None, around=None, oldest_first=False, bulk=True)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).

Purges a list of messages that meet the criteria given by the predicate `check`. If a `check` is not provided then all messages are deleted without discrimination.

You must have the [`manage_messages`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.manage_messages "discord.Permissions.manage_messages") permission to delete messages even if they are your own. The [`read_message_history`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.read_message_history "discord.Permissions.read_message_history") permission is also needed to retrieve message history.

Examples

Deleting bot’s messages...
slate swan
#

use this method

#

on ctx.channel for example

leaden jasper
#

ok

#

i wanna clear all how do i do that

slate swan
#

I don't think nuking a channel is something I'm gonna help you with

leaden jasper
#

huh

slate swan
#

i wouldn't call that nuking

#

I would

#

how

#

deleting every message from a channel

#

is called nuking it

leaden jasper
#

yep i need to to start my channel message history from fresh

slate swan
#

just because he wants to clear all the messages in a channel doesn't mean he is doing it for a bad purpose

#

it makes as many API calls as possible aswell

ebon island
slate swan
slate swan
leaden jasper
slate swan
#

well store the id

leaden jasper
#

too much work for one thing

#

i need a clear command anyway

slate swan
#

you're gonna get rate limited

#

less work make bot no work

leaden jasper
#

what is the max number to clear in one request

slate swan
#

hm

#

I don't think there's something like that

#

and you can set the limit to none which actually nukes the channel

#

but you should be a lil bit aware of that

leaden jasper
#

or all the messages in it

slate swan
#
  1. discord crashes
  2. bot will get rate limited eventually
slate swan
leaden jasper
#

ok then perfect

#

thats what i need

slate swan
#

well you'll see

final iron
slate swan
#

id changes

#

"too much work to store it"

leaden jasper
#

yep

slate swan
#

so we're nuking the channel

#

API calls: 8 sideways

leaden jasper
slate swan
#

infinite api calls

leaden jasper
#

setting limit to None runs forever?

slate swan
#

no

#

it deletes all messages in a channel

#

which is a lot of api calls

#

especially when you have a lot of messages

#

above 10000, I'd rather just delete the channel

#

maybe above a couple thousands aswell

leaden jasper
#

no i have less than 1k messages in the channel

#

this is correct right

  @commands.command()
  async def clear(self, ctx):
    await ctx.channel.purge(limit = None)
pliant gulch
#

If you want to "nuke" a channel, safest way is to clone the channel, delete it. Then add the clone back

slate swan
#

I think so

leaden jasper
#

so deleting all messages is the best way

final iron
leaden jasper
#

for a little task no need

slate swan
#

well

#

yes need

leaden jasper
#

but thanks

final iron
#

Your bot is going to get rate limited

pliant gulch
#

Limit has to be passed as an int, or not passed at all

#

Because purge checks the channel's history, that requires an integer

slate swan
#

it would work

pliant gulch
#

No it won't

slate swan
#

I know, cuz I already messed that up

leaden jasper
slate swan
#

got a channel nuked

leaden jasper
#

None means all

unkempt canyonBOT
#

discord/iterators.py lines 297 to 298

if self.limit is None:
    raise ValueError('history does not support around with limit=None')```
pliant gulch
#

No it does not kek

slate swan
#

how

leaden jasper
#

:o

slate swan
#

so how did somebody tell me

#

in the dpy server

#

that his channel got nuked

#

when I told him to set it to None by accident

pliant gulch
#

Not sure how that is possible ¯_(ツ)_/¯

#

I quite literally just read the source code for purge just barely

#

It won't work if None is passed to limit

#

Even checks for it, and raises an error if it is

leaden jasper
#

ill write 100million then

slate swan
pliant gulch
#

The max for history iirc is 100 messages

leaden jasper
#

oh ok

#

thanks

slate swan
#

How to I edit a roles permission in a channel cause this won't work.

await ctx.channel.set_permissions(918955830810923049, send_messages=False)
#

How do I run 2 bots at once then close one of them

final iron
final iron
slate swan
#

I’m trying to access a list of bots that I have saved in a text file

final iron
slate swan
#

I would just write the tokens in manually

#

But I prefer to have it in a text file

#

I’ll explain my full code

crystal cliff
slate swan
#

It gets all the tokens in a text file and checks if they are valid

#

Just in case I’ve typed a token in wrong

#

And to avoid some run errors

#

Then it runs that token and gets the username and ID of the bot

#

It closes the bot

final iron
#

Why do you have so many tokens?

slate swan
#

I have 2

crystal cliff
slate swan
#

Because I have 2 bots

final iron
slate swan
#

Because it’s supposed to be a program for ease of acces

cloud dawn
#

bro like i told you you need to do it differently

crystal cliff
#

are you running 2 bots on the same code?

cloud dawn
#

They are just going to tell you the same thing

slate swan
#

Then explains how to do it

cloud dawn
#

I did you just left

slate swan
#

Because you told me to go here for bot inquires

#

Idk how you spell it

cloud dawn
slate swan
#

I listened to him

#

Because it was about discord bots

crystal cliff
#

can you show the code without the tokens pls @slate swan

slate swan
#

this is the code im using

#

im opening and closing a bot

#

thats it

cloud dawn
#

How many tokens do you have?

slate swan
#

2

#

My bots

cloud dawn
#

okay if you got a list [1, 2] would you for loop this?

slate swan
#

There are more things in the list

#

There’s false tokens

cloud dawn
#

Then you will get errors??

slate swan
#

That’s why I’m checking for valid tokens

cloud dawn
#

Me=confusion

#

But.. why do you have none valid tokens?

slate swan
#

To test the valid token checker

cloud dawn
slate swan
#

And so I have a reason to loop it

#

how does discord secure tokens from people typing random tokens?

cloud dawn
slate swan
#

It’s 59 characters in a token

#

So there is a VERY low chance you will get a working one

slate swan
#

more than a billion i would guess

cloud dawn
#

Fact that you also know the exact length is very sus

slate swan
cloud dawn
unkempt canyonBOT
#

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

67600000000000000000000000000000000000000000000000000000000
slate swan
#

A lot

#

thats allot lol

#

So there would be no point to brute force tokens

#

Because it would take century’s

cloud dawn
#

@slate swanDo you know what try/except is?

slate swan
#

Yes

cloud dawn
#

Then why isn't that in the 'validator' if you are checking for wrong tokens?

slate swan
#

I’m just checking for 59 characters

#

I’m getting the base code down

#

I’ll add it later

cloud dawn
slate swan
#

Maybe if you would help me I would add it

slate swan
cloud dawn
#

Show the whole code and i agree

slate swan
#

every single bit of my code

cloud dawn
#

Yes.

#

single or multiple files?

slate swan
#

one file

#

and tokens.txt contains... tokens

cloud dawn
#

hmm

#

@slate swanShould i help him? I need a second opinion.

#

Validating tokens is kinda pythonamongus

slate swan
slate swan
#

So other people can use it

#

It’s a utility for discord bots, to make it easier to make one

cloud dawn
#

To check if a token is valid? What would that benefit?

slate swan
#

If people put in invalid tokens without knowing it

#

It helps the user

cloud dawn
#

How will it help the user?

slate swan
#

By telling them if it’s invalid

cloud dawn
#

I'm pretty active here and most issues here are not token related

#

Current code already does that..?

slate swan
#

Its nothing bad its just easy to make it against tos

#

Everything is easy to make against tos

cloud dawn
# slate swan

I'm asking the mods rn if they agree then i will help. It's not you i've helped some people b4 to later find out they just used it to break ToS.

slate swan
#

Ok

#

It can be malicious which is against tos and rules in this server

#

It’s really obscure. I understand why you would be suspect for something against TOS

#

This is correct isn't it?

slate swan
#
channel = await self.bot.fetch_channel(917238203101089832)
#

sorry forgot to send code lmao

cloud dawn
slate swan
# slate swan Yeah

This is why I’m not gonna post the source code for the program online because people are gonna use it for stuff against tos

cloud dawn
#

?????

slate swan
#

I’ll post the exe file

manic wing
slate swan
#

I don’t think it would be decompilable

manic wing
cloud dawn
#

😂

slate swan
#

Ok

#

!rule 5

unkempt canyonBOT
#

5. Do not provide or request help on projects that may break laws, breach terms of services, or are malicious or inappropriate.

cloud dawn
#

I'm still waiting for the mods.

slate swan
#

See what the mods say

cloud dawn
slate swan
#

Making it a exe makes it even better for users

slate swan
manic wing
#

yes.

slate swan
cloud dawn
slate swan
#

You don’t need to install python to run it

tight obsidian
#

@slate swan Why do you need to check tokens?

slate swan
#

Exactly

tight obsidian
#

That's not something you should ask for help here.

slate swan
#

My problem is running two bots at once

ashen notch
#

Nothing about this smells right

slate swan
ashen notch
#

I'm not sure I'm comfortable with us fielding this

cloud dawn
slate swan
#

I know how to validate them

#

I don’t need help with that

cloud dawn
ashen notch
#

Yeah, I'm shutting this down. We're not helping with this

slate swan
cloud dawn
#

Okay thanks for clarifying guys.

slate swan
#

I’m just gonna ask stack overflow

ashen notch
#

For clarification, regardless of whether or not the question is about having two bots in a file or not, it's clear that this is all rather sketchy and against ToS. I'm not having our server linked with anything like that.

#

There should never be a time that you need to "validate" a file full of tokens

slate swan
#

There’s 2 tokens

slate swan
#

And there both mine

cloud dawn
# slate swan And there both mine

And you got invalid token(s) inside it, therefor i responded why not keep the 2 valid ones. But you quite insisted on validating it.

manic wing
slate swan
ashen notch
#

Nothing about what your code says or what you just said is believable. If this question gets asked again here further moderative action will be taken. Okay? Okay

slate swan
#

Making it a exe and easier makes it even more suspicious

cloud dawn
#

Okay but considering the mods already shut it down let's get back on topic :)

slate swan
#

And I assume me asking further questions about discord.py will get no results

#

Like last time this happened

#

Is this how I add reactions?

cloud dawn
slate swan
#
        poll = await channel.send(embed=poll_embed)

        await poll.add_reaction(":arrow_up_small:")
        await poll.add_reaction(":arrow_down_small:")
cloud dawn
cloud dawn
#

Hmm i especially if i have been coding for an hour then decided to test it to see if i'm still doing it correct and it just passes all test owww

slate swan
manic wing
#

he's not.

#

!d discord.Message.add_reaction || you can just add a reaction onto any message

unkempt canyonBOT
#

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

Add a reaction to the message.

The emoji may be a unicode emoji or a custom guild [`Emoji`](https://discordpy.readthedocs.io/en/master/api.html#discord.Emoji "discord.Emoji").

You must have the [`read_message_history`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.read_message_history "discord.Permissions.read_message_history") permission to use this. If nobody else has reacted to the message using this emoji, the [`add_reactions`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.add_reactions "discord.Permissions.add_reactions") permission is required.
cloud dawn
#

Why would i what are you coding for if not result?

slate swan
#

Why do I receive this error when there is no other command called ping.

discord.ext.commands.errors.CommandRegistrationError: The command ping is already an existing command or alias.
cloud dawn
#

speaking from experience

#

Did you also try CTRL+F "ping" across all files?

slate swan
#

Yeah I am 100% running from the correct file and have tried multiple times but still receive the same error.

#

I thought ctrl + f only works within the file you are working in

manic wing
cloud dawn
slate swan
#

ah ok

manic wing
slate swan
#

Found it!

cloud dawn
slate swan
#

ctrl + shift + f found it, thanks

manic wing
#

yeah noone cares about pycharm anyway

cloud dawn
#

Mighty tool.

slate swan
#

i use vscode

cloud dawn
#

Pretty sure Pycharm has it too lemme check

#

Pycharm has way too many options for my liking i like a light build like atom or vim

cloud dawn
#

It does

manic wing
#

eh

#

what about nano

cloud dawn
#

Not that light i still need my github integration lol

dire folio
#

i have an array that looks like this [[userid, "username#0000", 0]] and i want to make it so you can add/ subtract from that number.
i have this

async def points(ctx, user: discord.User, method, points):
    userid = user.id
    if type == 0 and any([userid in elem for elem in points]):

idk what to put into the if statement

cloud dawn
#

!d any

unkempt canyonBOT
#
any

any(iterable)```
Return `True` if any element of the *iterable* is true. If the iterable is empty, return `False`. Equivalent to:

```py
def any(iterable):
    for element in iterable:
        if element:
            return True
    return False
cloud dawn
#

hehe

cloud dawn
manic wing
#

agreed

dire folio
#

i should

#

but i want to do smth later and i feel like it would be a lot easier in an array

slate swan
#

I get this error when running my poll command?

        poll = await channel.send(embed=poll_embed)

        await poll.add_reaction(":arrow_up_small:")
        await poll.add_reaction(":arrow_down_small:")

Command raised an exception: HTTPException: 400 Bad Request (error code: 10014): Unknown Emoji

cloud dawn
cloud dawn
dire folio
#

ye i thought about that. but i have zero clue how

cloud dawn
slate swan
#

wdym

dire folio
slate swan
#

it's a default discord emoji

cloud dawn
dire folio
#

oh

manic wing
#

!d discord.Message.add_reaction || the argument needs to be a unicode emoji.

unkempt canyonBOT
#

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

Add a reaction to the message.

The emoji may be a unicode emoji or a custom guild [`Emoji`](https://discordpy.readthedocs.io/en/master/api.html#discord.Emoji "discord.Emoji").

You must have the [`read_message_history`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.read_message_history "discord.Permissions.read_message_history") permission to use this. If nobody else has reacted to the message using this emoji, the [`add_reactions`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.add_reactions "discord.Permissions.add_reactions") permission is required.
cloud dawn
#

!d discord.PartialEmoji.from_str

unkempt canyonBOT
#

classmethod from_str(value)```
Converts a Discord string representation of an emoji to a [`PartialEmoji`](https://discordpy.readthedocs.io/en/master/api.html#discord.PartialEmoji "discord.PartialEmoji").

The formats accepted are...
cloud dawn
#

Or just this

#

!charinfo 🔼

unkempt canyonBOT
cloud dawn
#

Unicode

#
        poll = await channel.send(embed=poll_embed)

        await poll.add_reaction(u"0001f53c")
manic wing
slate swan
#

!charinfo 🔽

unkempt canyonBOT
cloud dawn
#

I just paste the actual emoji inside my script xD

manic wing
#

same lol

slate swan
manic wing
#

eh paste the emoji

slate swan
manic wing
#

idk how to do it

dire folio
#

just find it online

cloud dawn
#

I just ctrl-c it from discord

manic wing
manic wing
#

🔽

#

wait can you??

#

omfg you can

cloud dawn
#

yes lol

manic wing
#

i went to that website every fucking time lol

dire folio
#

wtf i swear it just gave the name

cloud dawn
cloud dawn
manic wing
dire folio
#

must have

manic wing
#

i swear it did that before

#

they definitely changed it

cloud dawn
manic wing
#

😢

cloud dawn
placid meadow
#

Hi , i'm trying to do a commands thats gonna has a user to a blacklist so prevent him to use my bot how?

cloud dawn
#

@slate swan Reason for Dm'ing invite?

dire folio
#

o:

unkempt canyonBOT
#

@discord.ext.commands.check(predicate)```
A decorator that adds a check to the [`Command`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Command "discord.ext.commands.Command") or its subclasses. These checks could be accessed via [`Command.checks`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Command.checks "discord.ext.commands.Command.checks").

These checks should be predicates that take in a single parameter taking a [`Context`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Context "discord.ext.commands.Context"). If the check returns a `False`-like value then during invocation a [`CheckFailure`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.CheckFailure "discord.ext.commands.CheckFailure") exception is raised and sent to the [`on_command_error()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.discord.ext.commands.on_command_error "discord.discord.ext.commands.on_command_error") event.

If an exception should be thrown in the predicate then it should be a subclass of [`CommandError`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.CommandError "discord.ext.commands.CommandError"). Any exception not subclassed from it will be propagated while those subclassed will be sent to [`on_command_error()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.discord.ext.commands.on_command_error "discord.discord.ext.commands.on_command_error").
manic wing
#

!d discord.ext.commands.Bot.check || you would use a check. it triggers before each command and if it returns True, then it activates, else it doesnt. py @bot.check async def bot_check(ctx): if ctx.author.id == blacklisted_id: return False #dont acctivate command. Raises GlobalCheckFailure return True

unkempt canyonBOT
#

@check```
A decorator that adds a global check to the bot.

A global check is similar to a [`check()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.check "discord.ext.commands.check") that is applied on a per command basis except it is run before any command checks have been verified and applies to every command the bot has.

Note

This function can either be a regular function or a coroutine.

Similar to a command [`check()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.check "discord.ext.commands.check"), this takes a single parameter of type [`Context`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Context "discord.ext.commands.Context") and can only raise exceptions inherited from [`CommandError`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.CommandError "discord.ext.commands.CommandError").

Example...
slate swan
manic wing
fresh kestrel
#

is it possible to display a jpg as an emoji inside of a message?

manic wing
#

no.

slate swan
#

I didn't mean to do that sorry @cloud dawn

manic wing
#

you need to make the jpg and emoji

fresh kestrel
#

ah ok, figured as much

cloud dawn
cloud dawn
manic wing
cloud dawn
manic wing
#

better.

fresh kestrel
potent light
#

Heroku pricing is a bit confusing. Does the hobby plan have 10M database rows?

cloud dawn
cloud dawn
potent light
cloud dawn
#

Lol that is a lot a lot

#

That is like groovy amount.

potent light
#

What I mean is whether I will get that amount of database rows by purchasing a hobby plan or not.

#

cause their pricing is confusing.

cloud dawn
#

Unless you make it really inefficient

#

Link?

potent light
#

@cloud dawn

cloud dawn
potent light
#

and that's why I was saying that it's confusing xD

cloud dawn
#

Oh

#

yeah hobby is 10m

#

Heroku is pretty damn expensive though jeez

#

250 bucks a month for 2.5gb ram

#

Then i can setup my own server in a year lol

placid meadow
#

whats the error , i'm trying to delete the guild id in servers.json.

cloud dawn
#

Okay you might not fully like this so i'll be the booman

#

!open

unkempt canyonBOT
#

Opening files

The built-in function open() is one of several ways to open files on your computer. It accepts many different parameters, so this tag will only go over two of them (file and mode). For more extensive documentation on all these parameters, consult the official documentation. The object returned from this function is a file object or stream, for which the full documentation can be found here.

See also:
!tags with for information on context managers
!tags pathlib for an alternative way of opening files
!tags seek for information on changing your position in a file

The file parameter

This should be a path-like object denoting the name or path (absolute or relative) to the file you want to open.

An absolute path is the full path from your root directory to the file you want to open. Generally this is the option you should choose so it doesn't matter what directory you're in when you execute your module.

See !tags relative-path for more information on relative paths.

The mode parameter

This is an optional string that specifies the mode in which the file should be opened. There's not enough room to discuss them all, but listed below are some of the more confusing modes.

'r+' Opens for reading and writing (file must already exist)
'w+' Opens for reading and writing and truncates (can create files)
'x' Creates file and opens for writing (file must not already exist)
'x+' Creates file and opens for reading and writing (file must not already exist)
'a+' Opens file for reading and writing at end of file (can create files)

desert heart
desert heart
#

Notice how line 62 is at the same indentation level as line 63. That's incorrect.

placid meadow
potent light
#

@cloud dawn my internet isn't the best so I can't rely on it now. Do you have any better alternative than Heroku?
I need to host 2 bots and I need a Postgres database.

potent light
cloud dawn
#

Then AWS but you will need a credit card

desert heart
potent light
desert heart
#

There are so many options for hosting and they all have competitive pricing.

potent light
cloud dawn
desert heart
#

Oh you want a managed db instance?

#

Cause yeah, you can run pg yourself in the server

slate swan
#

!invite

#

Hmm

#

!open

unkempt canyonBOT
#

Opening files

The built-in function open() is one of several ways to open files on your computer. It accepts many different parameters, so this tag will only go over two of them (file and mode). For more extensive documentation on all these parameters, consult the official documentation. The object returned from this function is a file object or stream, for which the full documentation can be found here.

See also:
!tags with for information on context managers
!tags pathlib for an alternative way of opening files
!tags seek for information on changing your position in a file

The file parameter

This should be a path-like object denoting the name or path (absolute or relative) to the file you want to open.

An absolute path is the full path from your root directory to the file you want to open. Generally this is the option you should choose so it doesn't matter what directory you're in when you execute your module.

See !tags relative-path for more information on relative paths.

The mode parameter

This is an optional string that specifies the mode in which the file should be opened. There's not enough room to discuss them all, but listed below are some of the more confusing modes.

'r+' Opens for reading and writing (file must already exist)
'w+' Opens for reading and writing and truncates (can create files)
'x' Creates file and opens for writing (file must not already exist)
'x+' Creates file and opens for reading and writing (file must not already exist)
'a+' Opens file for reading and writing at end of file (can create files)

cloud dawn
#

It will be a bit slower than having an actual server handling all the connections but still for starters. Will also save the hassle.

potent light
cloud dawn
potent light
cloud dawn
#

24GB for 16 bucks a month jeez next time i'm hosting my minecraft server there lol

#

If they allow port forwarding that is.

#

Prob not lol

potent light
#

@cloud dawn they don't have a good documentation tho.

#

I can't see a tutorial on how to set up a Discord bot on Netcup.

potent light
cloud dawn
#

you need to setup the vps first?

#

It's not as straight forwards as Heroku.

#

vps is basically a remote virtual machine

#

best is to use unix based since windows is a bit heavy

ebon island
#

What is the best package for Asynchronous HTTP Requests to an API within a DPY project for things like user data storage etc?

pliant gulch
#

Aiohttp

#

Err

#

I understand what you mean now

#

Prob quart or fastapi

ebon island
#

So aiohttp to send the HTTP request and fast API for the actual API? Sounds like something I can definitely make happen!

cloud dawn
#

quart has a build in discord module

#

!pypi Quart-Discord

unkempt canyonBOT
cloud dawn
#

!pypi discord-ext-ipc

unkempt canyonBOT
ebon island
#

Really? That's awesome! What does the built in module intended to handle?

cloud dawn
lost wolf
#
AttributeError: 'Client' object has no attribute 'Command'```
lost wolf
#

how to fix?

cloud dawn
#

Use bot

#

!d discord.ext.commands.Bot

unkempt canyonBOT
#

class discord.ext.commands.Bot(command_prefix, help_command=<default-help-command>, description=None, **options)```
Represents a discord bot.

This class is a subclass of [`discord.Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") and as a result anything that you can do with a [`discord.Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") you can do with this bot.

This class also subclasses [`GroupMixin`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.GroupMixin "discord.ext.commands.GroupMixin") to provide the functionality to manage commands.
lost wolf
#

so discord.Bot() instead of discord.Client()?

potent light
#

@cloud dawn I will probably end up using ElephantSQL and netcup.

cloud dawn
cloud dawn
lost wolf
#
client = class discord.ext.commands.Bot(command_prefix=".", help_command="help", description=None)

lost wolf
#

sorry im new to dpy

slate swan
#
bot = commands.Bot(**kwargs)
cloud dawn
slate swan
#

But first learn oop and python basics if you havent

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.

verbal cairn
#

Anyone have any tips with ui.view for pagination

slate swan
#

Disnake has git examples

slate swan
jade tartan
#

Heyy i am not sure what this might be called but when a member gets verified or like reacts to a role to be verified in the server can it send a message to where itll say that this member has been verified?

sick birch
#

Sure

#

You can send any message to a discord.Messagable subclass

fresh kestrel
#

how can i use a PIL image in an embed?

sick birch
#

discord.Member, discord.TextChannel are common subclasses of discord.Messagable

sick birch
#

all discord.Messagable subclasses have a send() method

#

Which, as you may have guessed, can be used to send a message to that channel/user

slate swan
jade tartan
sick birch
#

No it's a coroutine

slate swan
jade tartan
#

Can you walk me through it?

slate swan
#

I think it has a author attr

slate swan
sick birch
#

A DM or a channel?

jade tartan
#

A channel

#

and dm

#

both

sick birch
#

Right, do you have access to the discord.TextChannel object and the discord.Member object?

#

You should if you have the ctx

jade tartan
#

ohh wait hang on ill do that now

covert igloo
#

@sick birch how do i get all the messages from a channel

jade tartan
#

Can i like choose any name on the async def?

#

part

sick birch
#

Why are you making an async def

#

Are you trying to make a command?

slate swan
sick birch
#

Well

jade tartan
#

no just a client.event?

slate swan
#

If a event depends what your waiting for

sick birch
#

Personally naming a command ban, kick, etc... causes issues

sick birch
#

Try to avoid naming your commands after the library's method

jade tartan
sick birch
#

If you absolutely must, you can prefix the command with an underscore, and pass in the name= kwarg into the decorator with the actual name that you'd use on discord

jade tartan
#

tho

slate swan
#

Naming a function methods will give you naming errors

jade tartan
sick birch
#

Odd

jade tartan
#

yeah

#

Any way so i dont do async def ?

slate swan
jade tartan
slate swan
royal jasper
#

how can I make a command only usable once and never again?

slate swan
#

Might be wrong but i dont think i am

sick birch
#

you can then use the @before_invoke decorator to define if the function should be called or not

slate swan
sick birch
#

Or, alternatively, after the command is called, disable it

slate swan
#

Can you do that?

jade tartan
slate swan
jade tartan
#

For the verified message?

#

for both dm and channel

covert igloo
#
async def get1(ctx, channel : discord.TextChannel):

    async for message in ctx.channel.history(limit=200):

        print(message)```
jade tartan
#

in a class.event

slate swan
jade tartan
#

plz bear with me as my english is my 2nd langauge

slate swan
slate swan
covert igloo
slate swan
jade tartan
slate swan
#

Aka the channel obj

jade tartan
#

and if that does not happen

covert igloo
#

just add channel as a param?

jade tartan
#

it sends a message to a member that u would need to get verified to be able to see the rest of the server channels

slate swan
jade tartan
#

or sorry def

covert igloo
slate swan
lost wolf
#
discord.ext.commands.errors.MissingRequiredArgument: ctx is a required argument that is missing.
#
@bot.command(name="snipe")
async def snipe(self, ctx):
        """A command to snipe delete messages."""
        if not self.last_msg:  # on_message_delete hasn't been triggered since the bot started
            await ctx.send("There is no message to snipe!")
            return

        author = self.last_msg.author
        content = self.last_msg.content

        embed = discord.Embed(title=f"Message from {author}", description=content)
        await ctx.send(embed=embed)
broken plinth
#

hello

covert igloo
slate swan
lost wolf
#

but i need self

slate swan
#

Is it in a cog?

jade tartan
#

So

lost wolf
slate swan
#

No need for it

#

self is used to acces the class the command is in

lost wolf
#

then what do i use for self?

slate swan
#

Delete it

visual island
#

you can use botvar for it

covert igloo
visual island
#

for replacing self

broken plinth
#

umm hello?

lost wolf
#
@bot.command(name="snipe")
async def snipe(ctx):
        """A command to snipe delete messages."""
        if not last_msg:  # on_message_delete hasn't been triggered since the bot started
            await ctx.send("There is no message to snipe!")
            return

        author = last_msg.author
        content = last_msg.content

        embed = discord.Embed(title=f"Message from {author}", description=content)
        await ctx.send(embed=embed)

lost wolf
broken plinth
#

I'm currently new to python and i whant to know how to code?

#

hello?

visual island
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!

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.

broken plinth
visual island
broken plinth
#

thanks

#

ok

jade tartan
# slate swan After a join add a role and on reaction you remove the role
async def on_raw_reaction_remove(payload):
    ourMessageID = 914720242297630750

    if ourMessageID == 914720242297630750:
        member = payload.member
        guild = member.guild

        emoji = payload.emoji.name
        if emoji == '✅':
            role = discord.utils.get(guild.roles, name="Unverified")
            await member.add_roles(role)


@client.event
async def on_raw_reaction_remove(payload):
    if payload.member.bot:
        pass

    else:
        with open('reactrole.json') as react_file:
            data = json.load(react_file)
            for key, value in data.items():
                        emoji = payload.emoji
                        role = discord.utils.get(client.get_guild(payload.guild_id).roles, id=832120561848156180)
                        await payload.member.add_roles(role)
whole sparrow
#

is payload context?

slate swan
#

Iirc raw reaction makes a call as the msg isnt cached

cloud dawn
#

yep so best case

slate swan
#

Alr

whole sparrow
#

Anyone know how to prevent database locking due to async in dsicord bots?

slate swan
#

^

jade tartan
#

Well idk ur saying like

whole sparrow
jade tartan
#

like making me do

jade tartan
#

and telling u which module to use

slate swan
whole sparrow
#

ohh

slate swan
#

Dont think you need to type hint it tho

jade tartan
#

ohh well i have it right here

slate swan
#

you don't need to typehint it , but it's more readable and efficient to do that

jade tartan
#
async def on_member_join(member: discord.Member):
        guild = client.get_guild(730651046459998218)
        channel = client.get_channel(885464532959526913)
        Myembed = discord.Embed(title= f"Welcome",
        description=(f"Welcome {member.mention}, You are member {guild.member_count}. \n Please enjoy your stay here and dont forget to read the await [#904279966693355550](/guild/267624335836053506/channel/904279966693355550/)"))

        Myembed.add_field(name="Account Created at:", value=f"{member.created_at(datetime)}", inline=True)
        await channel.send(embed=Myembed)
        await member.send(embed=Myembed)
        roles_list = ["Unverified","•.¸¸.•:Colours:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•","•.¸¸.•:Verification:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•","•.¸¸.•:Age:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•","•.¸¸.•:Gender:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•","•.¸¸.•:Sexuality:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•",
        "•.¸¸.•:Distance:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•","•.¸¸.•:Ethnicity:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•","•.¸¸.•:Hobbies:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•","•.¸¸.•:Relationship:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•","•.¸¸.•:Location:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•",
        "•.¸¸.•::•.¸¸.•`Seeking`•.¸¸.•``•.¸¸.•``•.¸¸.•","•.¸¸.•:DM:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•","•.¸¸.•:Levels:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•","•.¸¸.•:Games:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•"]
        for roles in roles_list:
            role = discord.utils.get(member.guild.roles, name=roles)
            await member.add_roles(role)```
slate swan
slate swan
jade tartan
#

How?

#

Do you get what am trying to do?

slate swan
#

bot.wait_for("reaction")
iirc

#

gangster , you trying to do something like -> member joins -> unverified and other roles get added -> when the user reacts on some message , the unverified role gets removed?

visual island
slate swan
hybrid fjord
#

is there any possible way to make a bot listen to other bots?

slate swan
slate swan
hybrid fjord
slate swan
#

Please elaborate

jade tartan
#

ok hold up

slate swan
#

Some bots can but i dont think you can with dpy

hybrid fjord
#

damn

slate swan
#

As mee6 does take commands but those are private wrappers

#

I think with discord client you can

#

And not the bot instance

jade tartan
#

When a member reacts to this i want it to where itll send a message to DM and channel to when this member has go verified and is able to talk in channel now

#

And if it has failed

#

it either sends his another message saying to either verify again or kicks him from the server

#

Make sense?

slate swan
#

You can add a timeout and after that it will send a msg if not verified it will kick the member

jade tartan
#

ok can you walk me through it?

jade tartan
#

is DM await member.send(embed=Myembed) RIght?

slate swan
#

The member obj on join

jade tartan
#
async def on_member_join(member: discord.Member):
        guild = client.get_guild(730651046459998218)
        channel = client.get_channel(885464532959526913)
        Myembed = discord.Embed(title= f"Welcome",
        description=(f"Welcome {member.mention}, You are member {guild.member_count}. \n Please enjoy your stay here and dont forget to read the await [#904279966693355550](/guild/267624335836053506/channel/904279966693355550/)"))

        Myembed.add_field(name="Account Created at:", value=f"{member.created_at(datetime)}", inline=True)
        await channel.send(embed=Myembed)
        await member.send(embed=Myembed)
        roles_list = ["Unverified","•.¸¸.•:Colours:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•","•.¸¸.•:Verification:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•","•.¸¸.•:Age:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•","•.¸¸.•:Gender:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•","•.¸¸.•:Sexuality:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•",
        "•.¸¸.•:Distance:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•","•.¸¸.•:Ethnicity:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•","•.¸¸.•:Hobbies:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•","•.¸¸.•:Relationship:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•","•.¸¸.•:Location:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•",
        "•.¸¸.•::•.¸¸.•`Seeking`•.¸¸.•``•.¸¸.•``•.¸¸.•","•.¸¸.•:DM:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•","•.¸¸.•:Levels:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•","•.¸¸.•:Games:•.¸¸.•``•.¸¸.•``•.¸¸.•``•.¸¸.•"]
        for roles in roles_list:
            role = discord.utils.get(member.guild.roles, name=roles)
            await member.add_roles(role)```
#

This is my code

slate swan
#

Yes

#

It will add the unverified role

#

Then send a msg and wait for a reaction after the reaction it will remove the roles

jade tartan
gaunt wedge
#

👍

slate swan
jade tartan
# slate swan Wdym?

The message part do i add await ctx.send(You will need to react to the emoji in 5 more minutes. Or action consequence will occur.)

#

something like that

slate swan
#

Just send a msg with the channel obj

jade tartan
#

Message = discord.Message(description= f"Please pick your gender role by reacting to the emoji"

#

idk

slate swan
#

No?

jade tartan
#

plz guide me through?

slate swan
#

You use the channel obj you got

#

In this case the channel you got is in the channel var which channel has the .send attr

jade tartan
#

await channel.send(embed=Myembed)

slate swan
#

Yes

jade tartan
#

Ohh and i just replace it with? You will need to react to the emoji in 5 more minutes. Or action consequence will occur.

slate swan
#

If thats what you want to send yes

#

And after everything you can clear the channel if that is what you want

jade tartan
#

Ok then and how do i make it to where itll kick a member when he/she doesnt react to a certain timeframe?

slate swan
#

I think wait_for has a kwarg for timeout

jade tartan
slate swan
jade tartan
# slate swan Where you want to wait for a reaction
async def reaction_test(ctx):
    await ctx.send(f"**{ctx.author}**, please react with :white_check_mark: or :x: on this message in 60 seconds")
    
    def check(r: discord.Reaction, u: Union[discord.Member, discord.User]):
        return u.id == ctx.author.id and r.message.channel.id == ctx.channel.id and \
               str(r.emoji) in ["\U00002705", "\U0000274c"]
    try:
        reaction, user = await client.wait_for(event = 'reaction_add', check = check, timeout = 60.0)
    except asyncio.TimeoutError:
        await ctx.send(f"**{ctx.author}**, you didnt react with a ✅ or ❌ in 60 seconds.")
        return
    else:
        if str(reaction.emoji) == "\U00002705":
            return await ctx.send(f"{ctx.author} reacted with a ✅")
``` Will this work?
slate swan
#

Run the code.

jade tartan
#

Well before this is this how it can work when a member doesnt react to the emoji in a certain time frame? if "VALORANT" in message.content: await message.author.kick(reason = "He said the word")

slate swan
#

After the timeout just send a message

#

I think on timeout you can send a msg

jade tartan
slate swan
#

Dont know much about union but try lowercase

jade tartan
slate swan
#

Dont really know

#

About Type hinting something with 2 types or objs in this case

#

Aka union

slate swan
#

Union is used to type hint 2 types am i correct?

jade tartan
#

umm yea

#

Am confused?

slate swan
#

How exactly?

jade tartan
#

the command doesnt work

slate swan
#

I think its Union[type,type]

jade tartan
slate swan
jade tartan
#

Doesn't work still

#

ohh wait i didnt import the module

#

hold up

jade tartan
#

working

ocean leaf
#

how to get a list of all commands of my bot but not as object. I want it to be a list like this ['>ping', '>avatar'] with prefix.

slate swan
#

you would have to loop thru bot.commands which returns all command objects , and use .name attribute to get the command names

boreal ravine
boreal ravine
sage otter
ocean leaf
final iron
ocean leaf
#

dosent work

#

nvm i fixed

weary gale
#
    embed.add_field(inline = False, name="guild name:", value=member.display_name)```
how do i make the id and display name embedded with this code, to make them look like the times?
slate swan
#
import discord
from discord.ext import commands

Token = "The Token"

client = commands.Bot(command_prefix=".", owner_id=521325126722125874)

client.run(Token)
print("Launch successful")

doesn't print Launch successful even when bot goes online

maiden fable
slate swan
#

what do u recommend i do to print launch successful?

#

on_ready

#

?

final iron
slate swan
slate swan
maiden fable
slate swan
#

or use get_prefix method

#

!d discord.ext.commands.Bot.get_prefix

unkempt canyonBOT
#

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

Retrieves the prefix the bot is listening to with the message as a context.
final iron
final iron
slate swan
#

@final iron

final iron
quasi axle
#

const Discord = require('discord.js');

const client = new Discord.client();

client.once('ready', () => {
console.log('Twinnem is online!');
}

client.login('token');

#

what did i do wrong

slate swan
#

i think i've figured it out

#

ty

outer basalt
#
    @tasks.loop(seconds=5)
    async def dispatch_webhooks(self):
        await self.bot.wait_until_ready()

        if self.logging_batch:
            for webhook, embeds in self.logging_batch.items():
                if embeds:
                    to_send = embeds[:10]
                    print(to_send)

                    webhook_to_send = discord.Webhook.from_url(webhook, session=self.bot.session, bot_token=self.bot.http.token)
                    await webhook_to_send.send(embeds=to_send, username=f"LogRack Logging", avatar_url=self.bot.user.avatar.url)

                    self.logging_batch[webhook] = embeds[10:]

i have this task, this should send 2 embeds but it only sending 1 embed any reason for that? it prints [<discord.embeds.Embed object at 0x05ECF340>, <discord.embeds.Embed object at 0x05ECF148>] and send only the second 1

ocean leaf
desert heart
outer basalt
#

actually i dont know how to use debugger, if you can help me

desert heart
#

Are you using an IDE

outer basalt
#

vsc

maiden fable
outer basalt
maiden fable
#

Oops

desert heart
#

Not sure if that is a sufficient explanation but if you're willing to try go for it and I'll try to help more if I can.

slate swan
#

C:\Users\ADMIN\PycharmProjects\Fluxo>python main.py
Launch Successful!
Ignoring exception in on_ready
Traceback (most recent call last):
File "C:\Users\ADMIN\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "C:\Users\ADMIN\PycharmProjects\Fluxo\main.py", line 11, in on_ready
await self.client.change_presence(activity=Activity(name=f"branch {version}", type=2))
NameError: name 'self' is not defined

I know i'm supposed to define self but how do i do that? im new to discord.py

maiden fable
#

Remove self

sullen shoal
#

you type it as the first argument of the function

#

or method

#

also is that a cog

#

ugh

#

show code

slate swan
# maiden fable Remove self

C:\Users\ADMIN\PycharmProjects\Fluxo>python main.py
Launch Successful!
Ignoring exception in on_ready
Traceback (most recent call last):
File "C:\Users\ADMIN\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "C:\Users\ADMIN\PycharmProjects\Fluxo\main.py", line 11, in on_ready
await client.change_presence(activity=Activity(name=f"branch {version}", type=2))
NameError: name 'Activity' is not defined

do i also remove activity

outer basalt
slate swan
sullen shoal
#

looks like youre doing completely wrong stuff in it

slate swan
#

import discord
from discord.ext import commands
from discord import Activity

Token = ""

client = commands.Bot(command_prefix=".", owner_id=521325126722125874)

@client.event
async def on_ready():
print("Launch Successful!")
await client.change_presence(activity=Activity(name=f"branch {version}", type=2))
client.run(Token)

sullen shoal
#

dont name Bot instance as client its not what python devs do, dont do stuff on on_ready event, it is not the right thing to change presence

#

!d discord.ext.commands.Bot.activity

unkempt canyonBOT
#

property activity: Optional[Union[discord.activity.Activity, discord.activity.Game, discord.activity.CustomActivity, discord.activity.Streaming, discord.activity.Spotify]]```
The activity being used upon logging in.
sullen shoal
#

put it their

sullen shoal
slate swan
sullen shoal
slate swan
#

idk man but client.run looks way cooler then bot.run

slate swan
#

And not client🕴️

#

Im joking lmfao😭

sullen shoal
#

the thing is that, there is another thing called discord.Client and when you would ask for help, we would expect that you named that thing as client not Bot

slate swan
sullen shoal
#

both of you

slate swan
sullen shoal
#

and another reason is that

#

the class is called Bot

slate swan
#

I know about discords client 🕴️

sullen shoal
#

so the instance needs to be called something like that as well

#

alright i get it

#

looks like i ruined the joke

slate swan
#

I was joking🚶

slate swan
sullen shoal
#

😪

slate swan
#

C:\Users\ADMIN\PycharmProjects\Fluxo>python main.py
Traceback (most recent call last):
File "C:\Users\ADMIN\PycharmProjects\Fluxo\main.py", line 13, in <module>
property_activity: Optional[Union[
NameError: name 'Optional' is not defined

C:\Users\ADMIN\PycharmProjects\Fluxo>

sullen shoal
#

the reason is that you didnt import it

ocean leaf
#

yes t worked

#

thanks

slate swan
#

i probably should change my laptop username from ADMIN to something else cause if i join a hacked wifi it'll be easy as fuck to guess

slate swan
#

@sullen shoal
C:\Users\ADMIN\PycharmProjects\Fluxo>python main.py
Traceback (most recent call last):
File "C:\Users\ADMIN\PycharmProjects\Fluxo\main.py", line 13, in <module>
property_activity: Optional[Union[
NameError: name 'Optional' is not defined

C:\Users\ADMIN\PycharmProjects\Fluxo>

slate swan
outer basalt
#

i am here in the discord thing

desert heart
# outer basalt now?

Keep stepping into the code (F11) until you reach the point where it's created the HTTP request payload

slate swan
sullen shoal
desert heart
#

Then inspect that payload to see if it has both embeds in it

slate swan
outer basalt
#

debug the code

outer basalt
slate swan
desert heart
outer basalt
#

in 5-7min?

desert heart
#

ok

slate swan
#
import discord
from discord.ext import commands
from discord import Activity
from typing import Optional, Union

Token = ""

client = commands.Bot(command_prefix=".", owner_id=521325126722125874)

@client.event
async def on_ready():
 print("Launch Successful!")

property_activity: Optional[Union[
  discord.activity.Activity, discord.activity.Game, discord.activity.CustomActivity, discord.activity.Streaming, discord.activity.Spotify]]
client.run(Token)

doesn't have activity

weary gale
#

e/Desktop/vsc test/bot.py"
^
SyntaxError: invalid syntax

#

lmao what

slate swan
slate swan
#

something like
"Listening to Lofi"

sullen shoal
#

i linked the docs to Bot.activity and he straight up copy pasted the docs

slate swan
#

!d discord.ext.commands.Bot.change_presence , or activity kwarg in commands.Bot

unkempt canyonBOT
#

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

Changes the client’s presence.

Example

```py
game = discord.Game("with the API")
await client.change_presence(status=discord.Status.idle, activity=game)
```   Changed in version 2.0: Removed the `afk` keyword-only parameter.
weary gale
#

how does one fix this

slate swan
#

show code

weary gale
#

just trying to run my bot

#
from discord.ext import commands

client = commands.Bot(command_prefix = '$')

@client.event
async def on_ready():
    print('bot is online')

client.run('token')```
slate swan
#

is that all? i dont see e/Desktop/vsc test/bot.py" there

weary gale
#

ik that bruh

weary gale
#

no liek

slate swan
#

how do you run it?

weary gale
#

thats the error that comes up

sullen shoal
unkempt canyonBOT
#

bot.py lines 22 to 29

bot = commands.Bot(
    command_prefix=bot_prefix, 
    case_insensitive=True, 
    activity=discord.Activity(
        type=discord.ActivityType.watching,
        name=f"{bot_prefix}help"
    )
)```
slate swan
# unkempt canyon

just to clarify for discord.Game("") im supposed to add a api right?

weary gale
slate swan
#

run without debugging

weary gale
#

oh

#

wow

#

albert einstein over here

sullen shoal
#

tbh that thing is slow asf, should run it from the terminal

slate swan
#

yea

weary gale
#

how does one host a bot

#

keep it online

sullen shoal
#

run it 24/7

#

thats what a vps does

weary gale
#

*for free

sullen shoal
#

self host is the best option for free

slate swan
weary gale
sullen shoal
#

running it from the terminal takes 1

sullen shoal
jovial plover
#

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: Forbidden: 403 Forbidden (error code: 60003): Two factor is required for this operation

Im trying to create channel, but i get this error

weary gale
jovial plover
#

how to solve?

sullen shoal
weary gale
#

bruh

sullen shoal
#

just pay the electricity bills thats it

#

or buy some super cheap vps

jovial plover
#

get a aws ec2 instance, costs $1/month if u run 24/7

jovial plover
sullen shoal
#

idk looks like youre self botting

#

are you

jovial plover
#
async def test(ctx):
        await ctx.guild.create_text_channel('test-channel')```
final iron
sullen shoal
#

i dont think a bot user should get that error

final iron
jovial plover
#
from discord.ext import commands
import discord
from discord import Embed


intents = discord.Intents(messages=True, guilds=True, members=True)
intents.reactions = True
bot = commands.Bot(command_prefix='!', intents=intents)


@bot.command(name="test")
async def test(ctx):
        await ctx.guild.create_text_channel('test-channel')

bot.run('')```
sullen shoal
#

server owners can enable some shit to allow only people with two factor authentication unlocked to do the moderation stuff

#

but that doesnt apply to a bot iirc

final iron
#

Can you even enable 2 factor authentication for a bot?

sullen shoal
#

thats why i think theyre asking for help with a self bot

#

its a user account thing

final iron
#

I would be inclined to agree