#discord-bots
1 messages ยท Page 846 of 1
wait im gonan restart it
ok now theres a new paert
File "C:\Users\NAME\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "c:\Users\NAME\Documents\Python\discordbot.py", line 25, in contact
admin_role = guild.get_role.int(945326991526219848)# Replace with id of admin role
AttributeError: 'function' object has no attribute 'int'
admin_role = guild.get_role(945326991526219848)
thats the line ^
that's not weird .-. read better your admin_role assignment
admin_role = guild.get_role(945326991526219848)
not the line ^
admin_role = guild.get_role.int(945326991526219848)
the line ^
!d discord.Guild.get_role
get_role(role_id, /)```
Returns a role with the given ID.
guild.get_role**.int**
role = discord.utils.get(await ctx.guild.fetch_roles(), id='id you want here')
?
omg
you can also fetch roles like that
you're fecthin' members in that code D_D
^
oh yeah, i forgor
๐๐
that looks shit tbh
still getting the error, i did change it to admin_role = guild.get_role.int(945326991526219848) still nothing
Bro don't tell him directly hahaha
the method is get_role()
it's just an attr error, it's fine
lost patiance ๐
but thats what i put before?
thats whats wrong
why did you want to add the .int?
because of the error
what is the error?
another error?
that its an int
the id you passed is already an int
AttributeError: 'function' object has no attribute 'int'
exactly, the fuction doesn't have a .int
^
that's because you are adding an .int that is not an attribute of that class/method
oh.
@placid skiffits not moai
welcome to the realm of newbie xD
i like how this guy had easiest error, and all seems confused
either do role = discord.utils.get(await ctx.guild.fetch_roles(), id=945326991526219848) or role = ctx.guild.get_role(945326991526219848) pick one
he is doing the last one
alr
but he types get_role.int() for a reason
guild.get_role(int(945326991526219848)) ? but very unncesary
idk bro Iโm gettin off for a bit. Such a simple problem with a simple fix but my brain blew up
cya
some dude is bringing up discord.utils.get ๐ฟ
hey, leave fetching alone
@slim ibexyoung folks wanna do cool-bots but not learn to code ๐คท๐ปโโ๏ธ
deep down we all know we prefer api calls
why not :)

ikr
im
..channel?
what the fuck is that import
i have no focking idea
@silent erminewhat is ur goal even?
message and channel id, hmmm, like a DM message?
Look at the origin of the traceback
mhmm
He needs to update. Or re-install the lib.
What do you know, pycord sharing the same namespace as discord.py has fucked up already!
or just give up discord.py cause its outdated soon big time
This error is due to you having pycord and discord installed at the same time, I assume
its only gonna last 1 more year
As you were using pycord earlier, and also using discord.py
Pycord has PartialMessageable but not discord.py
yes confusing af, down with pycord!
200IQ andy
Pycord ๐
disnake > all
disnake is the final boss, only few can afford to face it
no one can anymore
no
people here be codin' bots, but THEY be the bots, not reading the documentation, using pycord, and immediately sending tracebacks to this channel when they get them.
tracebacks not even coming from the discord lib
why readin' the docs when there are some gentlemen that stupidly help them like us? ๐
cogs dogs
docs โ
HAHAHAHAHAHA
i'm workin' and writin' in this channel right know, my multitasking is not that good
wdym
why-
so what do i dooooo
do you know python?
yes
then you should know what you have to do D_D
o-o
@placid skiffbe carefull mods muted me for a week for not helping
and tell em to learn python
it's one of the simplest error of python D_D
bruh
cause he didnt know how to declare a variable
BRUH
๐ฆ was my fault telling him
i will never tell someone who's creating a bot how to declare a variable .-.
@placid skiffur banned!
wait hold on, if im using pycord why does discord need the dependency discord.py
i will face the ban hammer
๐
yo wait if im using pycord do I replace all import discord to import pycord?
cuz im confused
first thing first, it used discord namespace and poetry is treating it as the discord.py package
pycord is a fork of discord.py, so yes, you have to replace all discord namespace into pycord
they dont use the pycord namespace~
they're like, ok "we are the new discord.py" :bruh:
pycord != discord.py
but basicly i guess u can
i dont know when they forked discord.py and when they took their own path in the code
i would suggest ditch both and move to disnake
disnake is also a pain
what?
lol why?
PUHAHHAHAHAHAHAHHAHAรน
it took me 5min to convert my old discord.py bot to disnake xD and it runs nice
if you just "not" used replit, all pycord, discord.py and disnake would work perectly
i didn't convert cuz when i changed to disnake i changed the whole code xD
ah
well yeah i wanted to do something more professional
my new bot i workon on the side is from scratch with disnake
my old code was a shit in terms of enviroment
that's true
first bot are always like psudeo code
then when it grows u realise u should have done it prooperly first
like my new bot that is subclassed n uses disnake will be my template
Now i'm not codin' a lot on my project cuz first i'm searchin' for some API that no-one can't find and i'm workin for another bot xD
for future bots
api that dosnt use api-keys
REEEEE ๐
like twitch want u tomake account connect phone and all diffrent steps to get a shitty api-key
i rather just find a way to get the data i want without api
Well it will be something i can even found an API key
same with youtube with api i could check page like once 10min ........ i figured out a way without api and can check page in 2 seconds instead
not banned
scrapy scrapy 
I thought that google was older then python xD
when they started their garage-web-search
it may be even now for some parts

python came 91' google 96
Oh cool
probally
It used nearly half of Stanford's entire network bandwidth. LOL!
Btw a lot of company are using python now
why wouldn't they
it's a good language
ye python has grown alot
usally at "jobs" they try recruits here it was like c++ mostly or perl
now its python alot
But not in Italy, where I live
In Italy they only search for java and react ๐ ๐
haha
there are still js fanboys be like "**b-but python is slow **
"
so slow ๐
if want speed dont even do js
go to c/c++ and partly asm
for speed
I learned asm when i studied uC
tbh now i learn python as a hobby, maybe in the future i'll be able to get a job in this zamn
!ot thanks
Off-topic channel: #ot2-never-nesterโs-nightmare
Please read our off-topic etiquette before participating in conversations.

What causes the bot to throw an error when using this command? The bot has default rights
you can't just randomly come in here and throw an ot stuff
i learned little asm not to code but to understand little when doing C/c++ Bufferoverflows etc and learn cracking
maybe show traceback 
No, no errors, nothing. Just an interaction error when using the command
!ot thanks
Off-topic channel: #ot2-never-nesterโs-nightmare
Please read our off-topic etiquette before participating in conversations.
inter.owner.mention can be none
did you import ApplicationCommandInteraction as AppCmdInter?
async def mute(ctx,
member: disnake.Member,
*,
time: TimeConverter = None,
reason = None):
embed = disnake.Embed(
description=f"{ctx.author.mention} muted {member.mention} for {reason}",
colour=0x020000)
channel = bot.get_channel(928776378105614376)
await channel.send(embed=embed)
role = ctx.guild.get_role(874708561178034186)
if role not in ctx.author.roles:
return
await member.timeout(duration=time)
await ctx.send((
":BeFunkyphoto20220219T204302: Muted {} for {} seconds."
if time else "").format(member, time, reason))
if time == "s":
time = 1 * time
elif time == "m":
time = 60 * time
elif time == "h":
time = 3600 * time```
**Reason is always None** but time works ** can someone help me please**
stop
how could i fix it
time, *, reason
^
let me try, thanks
what ancient code are you using pass_context=True is not longer a thing
Let's start with this then .-.
I think I understand what is wrong, thanks
old code but await member.timeout has new stuff in it ๐
member: disnake.Member,
*,
time: TimeConverter = None,* ,
reason = None):``` invalid syntax
hope itll still work
and dont use spaces in ur time ๐
How to make it show how many people and bots are on the server?
async def mute(ctx, member: disnake.Member, time: TimeConverter=None,* ,reason=None): disnake.ext.commands.errors.CommandNotFound: Command "mute" is not found
iterate through all members of the guild and check which of them are bots
How
Do you have a command decorator on it
i dont know what you mean
@bot.command() or something like that
mb
guild.members returns a list of member object, iterate through that list and check if the member you are iterating returns true with member.bot
ancient with some new flavors

!d disnake.AutoShardedClient
class disnake.AutoShardedClient(*args, loop=None, **kwargs)```
A client similar to [`Client`](https://docs.disnake.dev/en/latest/api.html#disnake.Client "disnake.Client") except it handles the complications of sharding for the user into a more manageable and transparent single process bot.
When using this client, you will be able to use it as-if it was a regular [`Client`](https://docs.disnake.dev/en/latest/api.html#disnake.Client "disnake.Client") with a single shard when implementation wise internally it is split up into multiple shards. This allows you to not have to deal with IPC or other complicated infrastructure.
It is recommended to use this client only if you have surpassed at least 1000 guilds.
If no [`shard_count`](https://docs.disnake.dev/en/latest/api.html#disnake.ShardInfo.shard_count "disnake.ShardInfo.shard_count") is provided, then the library will use the Bot Gateway endpoint call to figure out how many shards to use.

One day i found something like a debuggin' mode which let you don't rerun the code to apply changes, was i drunk or it really exists?
it doesnt say whats causing it but wtf is this:DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternative from distutils import errors
just use reload_extension if you use cogs
so you wont need to run the bot again and again
just make a command which reloads the cogs
yeah i've it already
load reload unload, basic 3 commands for cog users
My bot is subclassed so sometimes i made changes on the bot too, and my checks and other stuff are set outside of cogs
It literally tells you...
ik but what is causing this?
DeprecationWarning
Did you read the warning
WTF IS THAT BRO IM STUPID
Bruh
i did thanks ๐ฟ
ok slab of meat
that is me
need more errors than disnake.ext.commands.errors.CommandNotFound: Command "mute" is not found
Its fixed ty anyways
I got a shit ton of snow a couple of days ago
Hey can I ask a newbie question. What's best practice according to pep8 while coding a class, drinking whiskey or vodka?
the answer is not included in options but beers, if not coke n rom, but i guess whiskey works vodka too vine too,
Oh, I didn't even realise I could use beer in a class
now am confused ๐
๐ป
aight then my answer stands
I may be breaking standards by drinking whiskey but old habits are hard to break
Please tell me what I need to add to the code to avoid this error?
(i think they should allow OT here when there is no help needed)
@rare saddlethat is 99% u forgot await
^
oh wiat it even sait it
๐
Read your tracebacks kids
first time i saw that error i was like malloc (RAM, memmory) WTF? ๐
memory allocation
mhmm
but for a first time it can be confusing with malloc
google, and its about memory ๐
c# actually has a stackalloc keyword to allocate memory on the stack. Kinda cool
!ot
Off-topic channel: #ot2-never-nesterโs-nightmare
Please read our off-topic etiquette before participating in conversations.
wow
if no help needed atm why cant we chat?
Ashley was lurking for the perfect moment
we help if need and can
not really, I just ended with my crying session and just opened the chat ;-;
๐ฟ
she just wanna look good -> chasing roles
no-
who was off topic
@lemon#0001
๐๐ป i was
lemon
Wait, where should await be here?
lmao
If this condition
if await managechannel(self)
look in ur code wherre u have await in the other places?
i would guess
wait u showed the ot command to him?
The fuck
what do you mean?
never seen if โฆ(self) before
^
you lost the : at the end
who even is that ยฏ_(ใ)_/ยฏ
@nimble plumenot my code lol
An old friend who was active in this channel before u
I see
ok.
i saw the worst indentation ever on a newbies help channel
it was like 3 spaces then 3 then 1
๐
^^
I'm trying to make an error output when clicking on a button if the bot does not have enough rights, I've never done this before. Maybe you know how to do it?
4 spaces* btw
im in vc )
return not is a thing?
do you not know what not does)
return return
yes
would that just return false
wow
return False*
idts?
It depends on the condition itโs returning
Someone's remembering me ๐
Oh u ๐
return True
Long time
xD
return 1
return not True returns False
indeed
return not False best
return True gonna take less resources 
return sys.exit()
!e
def func():
return not
print(str(func()))```
@dull terrace :x: Your eval job has completed with return code 1.
001 | File "<string>", line 2
002 | return not
003 | ^
004 | SyntaxError: invalid syntax
no it's not a thing
uh, no but yes
u know... I know the perfect channel for you. #esoteric-python
huh?
!e
def return_bool(x: int) -> bool:
if x > 10:
return not True
else:
return not False
print(return_bool(5))
@slim ibex :white_check_mark: Your eval job has completed with return code 0.
True
ok?
what even is that ๐ imagine
It exists @dull terrace, you just didnโt specify something to return
!e print(True + True)
@pliant gulch :white_check_mark: Your eval job has completed with return code 0.
2
woah
True and False are really just ints
i thought we were asking if literally return not was a thing
woah
0 is false
1 is true
woah
oh lmao
no
!e print(True + False)
@nimble plume :white_check_mark: Your eval job has completed with return code 0.
1
woah
andy do be flexing ๐
0 is 0, 1 is 1, True is True, False is False
!e print(False + False)
@nimble plume :white_check_mark: Your eval job has completed with return code 0.
0
Barely this is like widely known
!e print(1+0+True+False)
@honest vessel :white_check_mark: Your eval job has completed with return code 0.
2
it is github ๐คท
epic fail
I dont trust ghub
!e print ((True == True) == True)
@slim ibex :white_check_mark: Your eval job has completed with return code 0.
True
tell that to yr school
!e print("print")
@dull terrace :white_check_mark: Your eval job has completed with return code 0.
print
!e if 1 == True or False == 0:
print(True)
@honest vessel :white_check_mark: Your eval job has completed with return code 0.
True
U all do know that #bot-commands exists, right?
yeah
they dont even know what github is ๐ plus I dropped out of school for this year
Then why not use it
!e
!eval [code]
Can also use: e
*Run Python code and get the results.
This command supports multiple lines of code, including code wrapped inside a formatted code block. Code can be re-evaluated by editing the original message within 10 seconds and clicking the reaction that subsequently appears.
We've done our best to make this sandboxed, but do let us know if you manage to find an issue with it!*
!e
a = False + False
b = False + True
if a != b:
return not True
else:
return not False
@nimble plume :x: Your eval job has completed with return code 1.
001 | File "<string>", line 4
002 | SyntaxError: 'return' outside function
ah wait
They did tell u to upload the project to github ๐
๐ฟ
I meant git*
but as I said, I dropped out of school this year and currently dont belong to it ;-;
everyone knows what github is, i just dont know how to use it because im newbie coder ๐ฅบ
why tho
same
i just manually back up everything to google drive
!e
a = False + False
b = False + True
if a != b:
print(not True)
else:
print(not False)
@nimble plume :white_check_mark: Your eval job has completed with return code 0.
False
best thing tbh
#ot2-never-nesterโs-nightmare? is fine?
Sure
!e print((True == True) ^ False)
ok chill down chat ๐
woah
why are we doing 1 + 1 in eval
flex
do maff in head
XOR ๐ฟ
huh?
!e print((True & True) | (True ^ False) ^ False)
@slim ibex :white_check_mark: Your eval job has completed with return code 0.
True
yeye
wait wtf does the and symbol do
Bit wise and
both conditions on each side have to be true for the statement to evaluate to true
is it possible to integrate website with discord bot on server side..like...i use discord command to generate website page and both website and discord bot share same database
Sounds very complicated to create a web server from a command
!e
coding_skill = "shit"
cows_make = "shit"
if cows_make & coding_skill:
print("shit")
@dull terrace :x: Your eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "<string>", line 4, in <module>
003 | TypeError: unsupported operand type(s) for &: 'str' and 'str'
KEK WTF?
can i host website and discord bot on same server ?

you would use and there @dull terrace
moai u know who am i/????/
pip install os
@nimble plume :white_check_mark: Your eval job has completed with return code 0.
Hello World!
then why would you use &
๐
obfuscated code ๐คค
and and & are different
yeah i asked what & is for
!e
coding_skill = "shit"
cows_make = "shit"
if cows_make and coding_skill:
print("shit")
ive never seen it
@nimble plumethats what u give noobs here copy pasta this
lol
toatally not copied from #esoteric-python
!e
val = 1
print(str(val & val))```
@dull terrace :white_check_mark: Your eval job has completed with return code 0.
1
๐ค
&, |, ^, ~, <<, >> are all bitwise operators
@nimble plumekinda fun tho, just takes time figure out without run it ๐
!e
val = 2
print(str(val & val))```
@dull terrace :white_check_mark: Your eval job has completed with return code 0.
2
...
They are for comparing binary numbers
idk what bitwise means
and, or, not are logical operators
it means your wise with bits
so only 0,9 and comparing them
,import('collections').defaultdict(int),0,0,0,import("sys").st
,__import__('collections').defaultdict(int),0,0,0,__import__("sys").st
``` main worker
In computer programming, a bitwise operation operates on a bit string, a bit array or a binary numeral (considered as a bit string) at the level of its individual bits. It is a fast and simple action, basic to the higher-level arithmetic operations and directly supported by the processor. Most bitwise operations are presented as two-operand inst...
~e
Off-topic channel: #ot2-never-nesterโs-nightmare
Please read our off-topic etiquette before participating in conversations.
lol what that does?
ok no ot now
no idea
i will run it not
back to busniess now yall had 5min break
holy crap, when would that ever be practical to use
!e
__import__('collections').defaultdict(int),0,0,0,__import__("sys").stdin.read
@nimble plume :warning: Your eval job has completed with return code 0.
[No output]
hmm
no output cause no print
yes
duh
i didnt see any print smh there
!e
a = import('collections').defaultdict(int),0,0,0,import("sys").stdin.read
print(a)
@honest vessel :white_check_mark: Your eval job has completed with return code 0.
(defaultdict(<class 'int'>, {}), 0, 0, 0, <built-in method read of _io.TextIOWrapper object at 0x7f058aeccc70>)
!e
print("Keep it ON TOPIC NOW PLOX")
@honest vessel :white_check_mark: Your eval job has completed with return code 0.
Keep it ON TOPIC NOW PLOX
!ot
Off-topic channel: #ot2-never-nesterโs-nightmare
Please read our off-topic etiquette before participating in conversations.
u are not even in chat?
The rules and guidelines that apply to this community can be found on our rules page. We expect all members of the community to have read and understood these.
go to #bot-commands
nk
adding only 1 letter change meaning o
yeah, please stop
Good thing I was not here
How to draw conclusion for this error? Occurs in on_ready
Here I want to display the id of the server on which the rights were not granted
I wouldn't do that on_ready
^
If you're sending API requests on_ready there's a decent chance you're going to get disconnected, and also on_ready can happen multiple times and behave in unexpected ways
I wanted slash commands to launch the ticket system to be able to run only by the owner of the server
Oh Robin ๐
!d discord.ext.commands.is_owner
@discord.ext.commands.is_owner()```
A [`check()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.check "discord.ext.commands.check") that checks if the person invoking this command is the owner of the bot.
This is powered by [`Bot.is_owner()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Bot.is_owner "discord.ext.commands.Bot.is_owner").
This check raises a special exception, [`NotOwner`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.NotOwner "discord.ext.commands.NotOwner") that is derived from [`CheckFailure`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.CheckFailure "discord.ext.commands.CheckFailure").
Just use the check
That doesnโt check if they are the owner of the guild
property owner: Optional[discord.member.Member]```
The member that owns the guild.
I wanted commands that are available only to the owner of the server, for others were not available as the addblack command, you canโt even click on it
Just make a custom check with this, or use an if statement
You can probably create a custom check as @final iron said
how to ping a role in a embed
or in the command do,
if member not ctx.guild.owner:
return
?
!d discord.Role.mention
property mention: str```
Returns a string that allows you to mention a role.
how
get_role(role_id, /)```
Returns a role with the given ID.
how in my embed
you get the role in a variable and do variable.mention in the embed
color=11177686)```
no...
no lmao
^
If you are pinging s different role for the command, the role could be a param for the function
oh fuck not on_message commands
ok will try
^
btw, I suggest using the commands framework instead of commands in on_message
idk why but i dont get pingt
em = discord.Embed(description=f"Keyword match detected.{role_obj.mention}",
color=11177686)```
but i didnt got pingt and i have the role
It doesnโt actually ping you
you did not get pinged because its in an embed
bruh
ยฏ_(ใ)_/ยฏ
then i need to send in a normal message
โฌโโฌ ใ( ใ-ใใ)
you can send the embed, and the ping in the same message. .send() has a content and embed kwarg
^
ah ok it thx
content isn't a kwarg
!d discord.abc.Messageable.send
await send(content=None, *, tts=None, embed=None, embeds=None, file=None, files=None, stickers=None, delete_after=None, nonce=None, allowed_mentions=None, reference=None, mention_author=None, view=None)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Sends a message to the destination with the content given.
The content must be a type that can convert to a string through `str(content)`. If the content is set to `None` (the default), then the `embed` parameter must be provided.
To upload a single file, the `file` parameter should be used with a single [`File`](https://discordpy.readthedocs.io/en/master/api.html#discord.File "discord.File") object. To upload multiple files, the `files` parameter should be used with a [`list`](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.9)") of [`File`](https://discordpy.readthedocs.io/en/master/api.html#discord.File "discord.File") objects. **Specifying both parameters will lead to an exception**.
To upload a single embed, the `embed` parameter should be used with a single [`Embed`](https://discordpy.readthedocs.io/en/master/api.html#discord.Embed "discord.Embed") object. To upload multiple embeds, the `embeds` parameter should be used with a [`list`](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.9)") of [`Embed`](https://discordpy.readthedocs.io/en/master/api.html#discord.Embed "discord.Embed") objects. **Specifying both parameters will lead to an exception**.
it's before the star
star signifies everything after it is a kwarg
content is before the star, therefore, not a kwarg
content here can be either a kwarg or a pos-arg
* makes all args after it a kwarg ONLY argument
Andy has arrived
But, of course content still can be a kwarg
it's usually a kwarg when u are giving it another kwarg. Otherwise throws an error I think
That is unless / is used in the signature
Forces it to be pos-only, like how the asterisk forces kwarg-only
!e ```py
def foo(bar, /, baz) -> None:
...
foo(bar=1, baz=2)
@pliant gulch :x: Your eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "<string>", line 4, in <module>
003 | TypeError: foo() got some positional-only arguments passed as keyword arguments: 'bar'
by not using it
how would i loop through all the users in the server? could i do
for i in range(ctx.author.guild):
print(i)
It wasnโt going to fix the issue
for member in ctx.guild.members:
โฆ
you arenโt using range correctly

!resources
The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.
ok so im struggling rn
with?
im getting a ss one sec
Spoonfeed time ๐
for i in ctx.guild.members:
print(i)
here is my problem
?
import os at the top of the file
I did the spoon feeding already ๐ฟ
^ I think we found another non Python knowing discord bot dev
ยฏ_(ใ)_/ยฏ
the token is None
from dotenv import load_dotenv
load_dotenv()
at the top of the file
what do async def mean
!d async
!d def
8.7. Function definitions
A function definition defines a user-defined function object (see section The standard type hierarchy):
it defines a coroutine function
I put it there it said the same thing
what does Coroutines mean
pain and suffering
It is a subroutine @naive spoke
moai can you help me ๐ฅบ
the token is none
bro i wanna know what Coroutines
mean
I literally just said itโs a subroutine
Just don't use replit
!async-await
This too
oh no
so what exactly do I have to do then
Stop watching it and follow this:
https://vcokltfre.dev/
A tutorial on how to use discord.py to create your own Discord bot in Python, written to fix the flaws of many other popular tutorials.
add the token ๐ฟ
like ik what that is
the token is the blurred out thing
ok ill give it a shot
in os.getenv(โโ) the thing in the parentheses is the name of the env variable which stores it.
TOKEN=tokenhere is picked up by os.getenv("TOKEN")
!async-await
Concurrency in Python
Python provides the ability to run multiple tasks and coroutines simultaneously with the use of the asyncio library, which is included in the Python standard library.
This works by running these coroutines in an event loop, where the context of the running coroutine switches periodically to allow all other coroutines to run, thus giving the appearance of running at the same time. This is different to using threads or processes in that all code runs in the main process and thread, although it is possible to run coroutines in other threads.
To call an async function we can either await it, or run it in an event loop which we get from asyncio.
To create a coroutine that can be used with asyncio we need to define a function using the async keyword:
async def main():
await something_awaitable()
Which means we can call await something_awaitable() directly from within the function. If this were a non-async function, it would raise the exception SyntaxError: 'await' outside async function
To run the top level async function from outside the event loop we need to use asyncio.run(), like this:
import asyncio
async def main():
await something_awaitable()
asyncio.run(main())
Note that in the asyncio.run(), where we appear to be calling main(), this does not execute the code in main. Rather, it creates and returns a new coroutine object (i.e main() is not main()) which is then handled and run by the event loop via asyncio.run().
To learn more about asyncio and its use, see the asyncio documentation.
read asyncio docs for more info
im sorry for being as dumb as a rock but what does this mean I have to do
is there a way to keep my discord bot open the whole time
Host it on a VPS or other hostin service

I would learn Python before making a discord botโฆ
it is obvious that you are just a beginner in Python. Learn more and do the bot again when you have a good grasp over things like OOP and asyncio
Thank you for your advice
Where do you suggest I go after taking the beginner tutorial
realpython is very good
The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.
decorators are an advanced topic imo
like I literally started this week
I still don't understand decorators
I will read the boring stuff book
yeah learn the language first
๐
before boring book or after boring book
Just syntactic sugar for deco(args)(wrapped)
Not really, creating decorators isnโt the easiest
if itโs something complicated
the book helps you learn the language..
while me who uses conditionals
@slate swan :white_check_mark: Your eval job has completed with return code 0.
001 | hello
002 | world
003 | !
004 | hello
005 | world
006 | !
nonlocal is also useful for decorators in some areas
!d nonlocal
7.13. The nonlocal statement
nonlocal_stmt ::= "nonlocal" identifier ("," identifier)*
``` The [`nonlocal`](https://docs.python.org/3/reference/simple_stmts.html#nonlocal) statement causes the listed identifiers to refer to previously bound variables in the nearest enclosing scope excluding globals. This is important because the default behavior for binding is to search the local namespace first. The statement allows encapsulated code to rebind variables outside of the local scope besides the global (module) scope.
Names listed in a [`nonlocal`](https://docs.python.org/3/reference/simple_stmts.html#nonlocal) statement, unlike those listed in a [`global`](https://docs.python.org/3/reference/simple_stmts.html#global) statement, must refer to pre-existing bindings in an enclosing scope (the scope in which a new binding should be created cannot be determined unambiguously).
Off-topic channel: #ot2-never-nesterโs-nightmare
Please read our off-topic etiquette before participating in conversations.
bro
I never want to be the bad human being
well you are being it๐ฟ๐ข
This channel is gonna be dead for 8-9 hours frow now on, respect it
I am always the cruel one
await ctx.send('hi')
await ctx.send("yo")
await ctx.send("talk")
when i do this the bot sends the message at the same time how can i make it so it waits 1 second before sending
what about only 1 of them
wym
"Coroutine"
import asyncio as uwu
lst = ["hunter", " so", "uwu"]
for i in lst:
await ctx.send(i)
await uwu.sleep(1)```
Baiii take care
stop Ashley holy ๐
its the way you hold me hold me hold me, it feels so holy
discord.py send image how to change title
What?
Sory for?
Changing the title of the image posted with discord.py
title?
How?
@client.command()
async def test(ctx):
message = await ctx.send('click here to talk with bot')
await message.add_reaction('โ
')
await client.wait_for("reaction_add")
await ctx.send('hello {ctx.author.name} ')
await ctx.send("yo")
await ctx.send("talk")
when i add anything in here it just breaks
You need to check who reacted
wait
beside wait for i need to write check?
hey everyone does anyone have a cool idea i can add to a currency discord bot
Yepz
You need to write on the image?
like this

nope
(Shop command
Idk you explain
like this? await client.wait_for check("reaction_add")
The text that appears when we hover over the picture posted in "discord"
how do i uninstall all my imports and stuff
Lmao no, you need a seperate check which you pass to the wait_for method
That doesnt change
i alr have that
What is the best practice if I have multiple aiocron.crontab task in my bot? Should I separate all of the cron jobs into one cog or into multiple separated cogs? Or it doesnt really matter just dont care about the fact that these are cron jobs in my bot?
Idk what's the topic
reaction roles or stuff like this?
as well as vc grinding and more
why
Kill command
alr got that lol
Dunno fr
what do you mean?
are you guys trying to check for player input
It checks the type of attachment which is discord inbuilt
def check(reaction, user):
if user.id == ctx.author.id and reaction.emoji == your_emoji:
return True
return False```
i did that before
then i deleted it because it was not working properly
Rip
No?
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in ["{emoji}"] and reaction.message == message
emoji is basically the emoji that you want to be reacted
I'll show you
Okay sure, if you really can
yeap
confirmation = await bot.wait_for("reaction_add", check=check)
and something like dis for checking
then you would do if confirmation:
Imagine not having a custom timeout
what does it do tho
then
Checks if the person who reacted was the same person who invoked the Command
i showed you that
ah
also you can create a lambda here to make life easier
is this different then the one ashley showed?
i mean works for me but i use lambda check
when i use it it says ctx not defined
naming โ
?
bot
i use client
bad
its just a variable name .... it can be anything
I could name my int to myString
I almost said it
@slate swan
if your trying to make a system for a player reaction just use wait_for(and blah blah
What?
i did
I'm at home my friend
ok
Did what?
hover over the picture
@bot.command()
async def csk(ctx,*,arg):
delim = ","
res = {idx: ele for idx, ele in
enumerate(arg.split(delim))}
CSK = []
CSKBAL = 9000
print(res[0])
CSK.append(res[0])
print(CSK)
embed = discord.Embed(title = "Sold!", description = arg, color = 0XFFFF00 )
embed.add_field(name="CSK Squad" , value = CSK , inline = False )
embed.add_field(name = "CSK Balance", value = CSKBAL,inline = False)
await ctx.send(embed= embed)โ```
โโ
What this ends up doing is
Instead of showing CSK squad as
["Faf","Jadeja"] it should just show the most recent one
Im on phone
@commands.command(aliases = ["server", "serverinfo"])
async def ัะตัะฒะตั(self, ctx):
date_format = "%A, %I:%M %p"
members = len(list(filter(lambda m: not m.bot, ctx.guild.members)))
bots = len(list(filter(lambda m: m.bot, ctx.guild.members)))
mbrs = ctx.guild.members
online = len(list(filter(lambda x: x.status == discord.Status.online, mbrs)))
idle = len(list(filter(lambda x: x.status == discord.Status.idle, mbrs)))
offline = len(list(filter(lambda x: x.status == discord.Status.offline, mbrs)))
dnd = len(list(filter(lambda x: x.status == discord.Status.dnd, mbrs)))
emb=discord.Embed(title=f"ะะฝัะพัะผะฐัะธั ะพ ัะตัะฒะตัะต **{ctx.guild.name}**", description="**__ะัะฝะพะฒะฝะฐั ะธะฝัะพัะผะฐัะธั:__**", color=discord.Color.from_rgb(128, 0, 255), timestamp=ctx.message.created_at)
emb.set_footer(text=f"ะะฐะฟัะพัะธะป: {ctx.author.name}", icon_url=ctx.author.avatar_url)
emb.set_thumbnail(url = ctx.guild.icon_url)
emb.add_field(name="**ะะฐะทะฒะฐะฝะธะต:**", value=f"**{ctx.guild.name}**", inline=False)
emb.add_field(name="**ะกะพะทะดะฐัะตะปั:**", value=f"**{ctx.guild.owner}**", inline=False)
emb.add_field(name="**ะฃัะฐััะฝะธะบะธ:**", value=f"ะัะตะณะพ: **{ctx.guild.member_count}**\nะัะดะตะน: **{members}**\nะะพัะพะฒ: **{bots}**", inline=False)
emb.add_field(name="**ะะพ ััะฐัััะฐะผ:**", value=f"ะ ัะตัะธ: **{online}**\nะะต ะฐะบัะธะฒะตะฝ: **{idle}**\nะะต ะฒ ัะตัะธ: **{offline}**\nะะต ะฑะตัะฟะพะบะพะธัั: **{dnd}**", inline=False)
emb.add_field(name="**ะะฐะฝะฐะปั:**", value=f"ะัะตะณะพ: **ัะบะพัะพ**\nะขะตะบััะพะฒัั
: **{len(ctx.guild.text_channels)}**\nะะพะปะพัะพะฒัั
: **{len(ctx.guild.voice_channels)}**", inline=False)
emb.add_field(name="**ะฃัะพะฒะตะฝั ะะตัะตัะธะบะฐัะธะธ:**", value=f"**{ctx.guild.verification_level}**", inline=False)
emb.add_field(name="**ะะฐัะฐ ัะพะทะดะฐะฝะธั:**", value=f"**{ctx.guild.created_at.strftime(date_format)}**", inline=False)
await ctx.reply(embed=emb)โ
shows the wrong status of people, who is online and who is not, how to fix?
how would i check if a person has a certan role? I want to do something like:
admin_role = guild.get_role(945325312533729311)
@bot.command
if USER has admin_role:
exicute comand
other:
await ctx.send("no perms to do this!")
how would i do that?
You can use a check or a conditional
!d discord.ext.commands.has_role
@discord.ext.commands.has_role(item)```
A [`check()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.check "discord.ext.commands.check") that is added that checks if the member invoking the command has the role specified via the name or ID specified.
If a string is specified, you must give the exact name of the role, including caps and spelling.
If an integer is specified, you must give the exact snowflake ID of the role.
If the message is invoked in a private message context then the check will return `False`.
This check raises one of two special exceptions, [`MissingRole`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.MissingRole "discord.ext.commands.MissingRole") if the user is missing a role, or [`NoPrivateMessage`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.NoPrivateMessage "discord.ext.commands.NoPrivateMessage") if it is used in a private message. Both inherit from [`CheckFailure`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.CheckFailure "discord.ext.commands.CheckFailure").
Changed in version 1.1: Raise [`MissingRole`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.MissingRole "discord.ext.commands.MissingRole") or [`NoPrivateMessage`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.NoPrivateMessage "discord.ext.commands.NoPrivateMessage") instead of generic [`CheckFailure`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.CheckFailure "discord.ext.commands.CheckFailure")
Rip my slow typing on phone
ah sick thanks
Iโm on phone too
I mean, I rarely use phone to text, so i havent had muchh of a practice lol
File "/home/runner/Clan-Bot/venv/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke await ctx.command.invoke(ctx) File "/home/runner/Clan-Bot/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke await injected(*ctx.args, **ctx.kwargs) File "/home/runner/Clan-Bot/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped raise CommandInvokeError(exc) from exc discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'str' object has no attribute 'message'
help ! pls
@client.command(help = 'Ban a member!')
@commands.has_permissions(ban_members = True)
async def ban(ctx, member : discord.Member = None, reason=None):
await ctx.message.delete()
await member.ban(reason = reason)
embed = discord.Embed(description= f"โ
**{member.display_name}#{member.discriminator} banned!**", color=discord.Color.green())
await ctx.send(embed=embed)```
hello friends, i was looking over the discord documentation trying to find if it's possible to grab the custom status of a user, my intention is to make a custom bot that checks what users custom statuses are to then assign a role. so if the status is what my server invite is, it awards a role. just wondering if its possible and i've missed it in the docs, thanks ๐
!d discord.Member.activity
property activity: Optional[Union[discord.activity.Activity, discord.activity.Game, discord.activity.CustomActivity, discord.activity.Streaming, discord.activity.Spotify]]```
Returns the primary activity the user is currently doing. Could be `None` if no activity is being done.
Note
Due to a Discord API limitation, this may be `None` if the user is listening to a song on Spotify with a title longer than 128 characters. See [GH-1738](https://github.com/Rapptz/discord.py/issues/1738) for more information.
Note
A user may have multiple activities, these can be accessed under [`activities`](https://discordpy.readthedocs.io/en/master/api.html#discord.Member.activities "discord.Member.activities").
this gets the activity, you may use activity.name
so im dumb, thank you
pls help !
please send the full traceback, there's more
!d discord.ext.commands.has_permissions
@discord.ext.commands.has_permissions(**perms)```
A [`check()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.check "discord.ext.commands.check") that is added that checks if the member has all of the permissions necessary.
Note that this check operates on the current channel permissions, not the guild wide permissions.
The permissions passed in must be exactly like the properties shown under [`discord.Permissions`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions "discord.Permissions").
This check raises a special exception, [`MissingPermissions`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.MissingPermissions "discord.ext.commands.MissingPermissions") that is inherited from [`CheckFailure`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.CheckFailure "discord.ext.commands.CheckFailure").
for member in ctx.guild.members:
print(member)
this isnt working!
Can you give more context?
@bot.command(pass_context=True)
async def Blacklist(ctx, user: discord.User):
print(ctx.guild.members)
for member in ctx.guild.members:
print(member)
this is the command
What does it print?
the loops doesnt print anything
the first print works
and prints this
[<Member id=942927877173825597 name='BaconHub Utilities' discriminator='5858' bot=True nick=None guild=<Guild id=852498873247203348 name='Bacon' shard_id=None chunked=False member_count=525>>]
BaconHub Utilities#5858
does anyone know roblox and can help me with what I am working on
i know roblox
This is abt discord bots lol
dm me @south jetty
well its related to that
ok
โฆ?
BUT ANONYMOUAS, U KNOW WHATS WRONG
Caps lol
srry caps lok
Works in what way
it sends the text in the quotes
In dms or to a channel tho?
the channel
Alr one sec
perhaps an error?
theres no error
yje loop doesn't even run
what is your black list command supposed to do, and whatโs the issue? You can get the members in the guild with len(ctx.guild.members)
@bot.command(pass_context=True)
async def Blacklist(ctx, user: discord.User):
print(ctx.guild.members)
for member in ctx.guild.members:
print(member)
^ itโs legacy
im passing context
I said that earlier
dunno what you need user for
a user that is mentiopned
Smells like an ancient YouTube tutorial to me
Yuup
Your command is capped, you need to run !Blacklist
!intents
Using intents in discord.py
Intents are a feature of Discord that tells the gateway exactly which events to send your bot. By default, discord.py has all intents enabled, except for the Members and Presences intents, which are needed for events such as on_member and to get members' statuses.
To enable one of these intents, you need to first go to the Discord developer portal, then to the bot page of your bot's application. Scroll down to the Privileged Gateway Intents section, then enable the intents that you need.
Next, in your bot you need to set the intents you want to connect with in the bot's constructor using the intents keyword argument, like this:
from discord import Intents
from discord.ext import commands
intents = Intents.default()
intents.members = True
bot = commands.Bot(command_prefix="!", intents=intents)
For more info about using intents, see the discord.py docs on intents, and for general information about them, see the Discord developer documentation on intents.
you need these
change Blacklist to blacklist. Capital blacklist doesnโt follow PEP 8
enable members in code and in the dev portal
๐ซ
shouldn't it have errored?
still doesnt loop
no command named blacklist
intents?
ยฏ_(ใ)_/ยฏ
oh no
a bot for sum
idk, it seems to have printed your name
^ so youโre the only one on the server?
no, theres 500+ members in there

if you want it to send to discord use ctx.send
ignored question
im tryna make it loop through all the users in the server
Why you tryna print 500+ things to the window lol
lmao
for reasons
there is a lot wrong with this code besides that
ignored response to ignored question
And the fact that its in replit lol
๐legit
but its usin g barley any ram and all so its not lagging at all
Replit is just bad in general
not really
ignored response of the ignored response responding to the ignored question
just help me with this command plz
Yes it is
ok we get it bro ๐ฟ
just help me wit hthe code. its not replit cauting the issue
Honestly its prob a replit thing lol. If it doesnt give a list in ctx.guild.members
Replit
While this may seem like a nice and free service, it has a lot more caveats than you might think, such as:
- The machines are super underpowered.
- - This means your bot will lag a lot as it gets bigger.
- You need to run a webserver alongside your bot to prevent it from being shut off.
- - This isn't a trivial task, and eats more of the machines power.
- Repl.it uses an ephemeral file system.
- - This means any file you saved via your bot will be overwritten when you next launch.
- They use a shared IP for everything running on the service.
This one is important - if someone is running a user bot on their service and gets banned, everyone on that IP will be banned. Including you.
you didn't answer, did you enable the intents?
but could be intents as I always put all intents on for my bots
yes i did
where
- pass it to your bot
You also have to enable them in discord dev portal, no?

i did in dev portal
then pass it to your bot
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.
how would i do that?
in your bot instantiation, intents = Intents.all() (if you want to enable them all)
intents kwarg
intents = intents
the time has finally come, i need help
is there any downside to switch to commands.AutoShardedClient or any difference to .Bot besides sharding?
use AutoSharded if your bot is in 1000+ servers
rookie nums
!d discord.ext.commands.AutoShardedBot
class discord.ext.commands.AutoShardedBot(command_prefix, help_command=<default-help-command>, description=None, **options)```
This is similar to [`Bot`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Bot "discord.ext.commands.Bot") except that it is inherited from [`discord.AutoShardedClient`](https://discordpy.readthedocs.io/en/master/api.html#discord.AutoShardedClient "discord.AutoShardedClient") instead.
all my bots are private, it cooler
!d discord.AutoShardedClient
class discord.AutoShardedClient(*args, loop=None, **kwargs)```
A client similar to [`Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") except it handles the complications of sharding for the user into a more manageable and transparent single process bot.
When using this client, you will be able to use it as-if it was a regular [`Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") with a single shard when implementation wise internally it is split up into multiple shards. This allows you to not have to deal with IPC or other complicated infrastructure.
It is recommended to use this client only if you have surpassed at least 1000 guilds.
If no [`shard_count`](https://discordpy.readthedocs.io/en/master/api.html#discord.ShardInfo.shard_count "discord.ShardInfo.shard_count") is provided, then the library will use the Bot Gateway endpoint call to figure out how many shards to use.
how do i just enable the server members intent in code?
!intents
Using intents in discord.py
Intents are a feature of Discord that tells the gateway exactly which events to send your bot. By default, discord.py has all intents enabled, except for the Members and Presences intents, which are needed for events such as on_member and to get members' statuses.
To enable one of these intents, you need to first go to the Discord developer portal, then to the bot page of your bot's application. Scroll down to the Privileged Gateway Intents section, then enable the intents that you need.
Next, in your bot you need to set the intents you want to connect with in the bot's constructor using the intents keyword argument, like this:
from discord import Intents
from discord.ext import commands
intents = Intents.default()
intents.members = True
bot = commands.Bot(command_prefix="!", intents=intents)
For more info about using intents, see the discord.py docs on intents, and for general information about them, see the Discord developer documentation on intents.
i wouldn't bring in discussion sharding if my bot wasn't in 1k+
๐ฟbig man
intents = Intents.default()
intents.members = True
bot = Bot(command_prefix='!', case_insensitive=True, intents = intents)
this code gives this error:
raise PrivilegedIntentsRequired(exc.shard_id) from None
discord.errors.PrivilegedIntentsRequired: Shard ID None is requesting privileged intents that have not been explicitly enabled in the developer portal. It is recommended to go to https://discord.com/developers/applications/ and explicitly enable the privileged intents within your application's page. If this is not possible, then consider disabling the privileged intents instead.
it is on in dev portal
i just wanted to know if there's needed any syntax changes in the code besides replacing bot with autosharded 
Nothing you need to change, the only thing it does is shard your bot
Sharding in discord.py doesn't really make sense to me, as they are handled all on the same process
But, that's just discord.py, other languages do it right, such as djs with their shard manager
Did you save
How to make my bot tell me who it is connected as on startup
The userโs username.
^
!d discord.ext.commands.Bot.user
property user: Optional[discord.user.ClientUser]```
Represents the connected client. `None` if not logged in.
This returns a ClientUser object
Ok so an example? Because I have this big block but no tell who it is that is connected as
donโt use client, use bot
@slim ibex I am in a cog

I assume you are subclassing to create the bot?
subclass commands.Bot not discord.Client
