#discord-bots
1 messages ยท Page 539 of 1
Hi
Motor
i could have easily sent the code here but its big
which method would you recommend?
Minecraft
you can do some pull requests too to do some additions and u will be creddited
๐
pymongo is sync
that's why i said to use motor, motor is an asynchronous wrapper for pymongo
this place is shit tbh
and, which method would you recommend for accessing collections?
eh, up2u, there's no difference in speed between those methods
oh, good to know. My bot never went online for some reason..
hm
worker: python __main__.py
``` so if this runs that file, to run my bot. Then I can't make it work
mongo?
are you sure that you have a .run in your file to run the bot
as well as toggled the dynos
if __name__ == '__main__':
setup()
extensions = []
for extension in extensions:
bot.load_extension(extension)
bot.run(TOKEN)
``` the problem is, my bot is a whole module. Only way to run it is `python -m MyBot` and `python __main__.py` will never work.
why not keep it as a module, make a main.py or bot.py or run.py or smth like that in outside it, and then do python main.py or python bot.py or whatever
hmm so I create a new file to run a module?
yes
and sorry for all these pings and wasting your time, Pretty sure I won't do it for now on.
it's alr
@client.check
def blacklist_check(ctx):
blacklisted = {'778662114663071765', '795030779264237599'}
if [int(ctx.author.id)] in blacklisted:
return
can I get help with my blacklist command
There seems to be some kind of problem where run.py can't run the MyBot. https://github.com/Nipa-Code/testbot @copper quartz
Lists are with []
ow thanks
how
ohh I see thank you so much
"12"/'12' -> that's a string
12 -> that's an integer
is it possible to have a command that takes in a sentence as an argument???
e.g. $warn @Joshalot#1023 "for being cringe"
Yes
how would one do that? haha
Thank you!
@client.check
def blacklist_check(ctx):
blacklisted = [778662114663071765, 795030779264237599]
if ctx.author.id in blacklisted:
return
but still I am getting The global check functions for command help failed. <class 'discord.ext.commands.errors.CheckFailure'> error
@naive parcel Are you looking for feedback on your project? ๐
You need to return a boolean
boolean?
So return false if it's in the list
Have you learned Python?
Then you should consider learning it more
I am knowing but I couldnt remember the name of it
Not knowing what a boolean, string, etc. is, means you didn't really learned the basics
Alright. If you're just looking for feedback or ideas or whatever, I think it's fine to ask for that here ๐
Although this probably isn't a good place to look for longer-term contributors to a project.
There seems to be some kind of problem where run.py can't run the MyBot. https://github.com/Nipa-Code/testbot
If someone would like to take a look at it. When I run the run.py nothing happens, not even printing anything from __main__.py file, nor any logs from logging.
!code
Here's how to format Python code on Discord:
```py
print('Hello world!')
```
These are backticks, not quotes. Check this out if you can't find the backtick key.
importing a module calls __init__.py
no because as mentioned it calls __init__.py
you can run python3 -m MyBot instead of python3 run.py
but, I need another file to run the MyBot
or in your case with heroku, worker: python -m MyBot
._. I was told that won't work
did you try it?
hii
nothing happens, the bot is still offline
How do I make this
use 2.0
how do i send a msg to a specific channel ?
get channel and then channel.send("anything")
ty
hmm
?
!d discord.ext.commands.Bot.get_channel
get_channel(id, /)```
Returns a channel or thread with the given ID.
!d discord.ui.View
class discord.ui.View(*, timeout=180.0)```
Represents a UI view.
This object must be inherited to create a UI within Discord.
New in version 2.0.
ty

Thanks
how can I get it call the __main__.py because that did not work for some reason?
!d discord
In order to work with the library and the Discord API in general, we must first create a Discord Bot account.
Creating a Bot account is a pretty straightforward process.
!d discord.Member @near oyster if you were looking for this
class discord.Member```
Represents a Discord member to a [`Guild`](https://discordpy.readthedocs.io/en/master/api.html#discord.Guild "discord.Guild").
This implements a lot of the functionality of [`User`](https://discordpy.readthedocs.io/en/master/api.html#discord.User "discord.User").
x == y Checks if two members are equal. Note that this works with [`User`](https://discordpy.readthedocs.io/en/master/api.html#discord.User "discord.User") instances too.
x != y Checks if two members are not equal. Note that this works with [`User`](https://discordpy.readthedocs.io/en/master/api.html#discord.User "discord.User") instances too.
hash(x) Returns the memberโs hash.
str(x) Returns the memberโs name with the discriminator.
!d discord.Member.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**.
import time
seconds = 300
while True:
seconds -= 1
m, s = divmod(seconds, 60)
if m == 5:
print('5 minutes')
break
elif m == 0:
print(f'{s} seconds')
else:
print(f'{m} minutes {s} seconds')
time.sleep(1)
At the end of 5 minutes, it moves to a negative number.
Is it possible to automatically start counting again after 5 minutes?
ask away
You should ask in normal help channels as this is not related to bots, just general Python question -> #โ๏ฝhow-to-get-help
Dude you barely even bothered changing the example I gave you ๐
To answer your question, yes, it's possible, very easy, by using your python knowledge 
How to make a specific role in discord have full control over the bots
give it perms?
Simply give it administrator and put it above the bot's role
Hmm
yes
But people without mods can be able to access it
u want it only to be usable by you?
And the mods
Then put the bot role above the mod role
add a check I guess
think he wants normal users to not have access to the bot
Iโve read through the code on @unkempt canyon , thereโs something that looks similar
Then use @commands.has_role(role_id)
To perms
Thx
How to make the bot online
!d help
help([object])```
Invoke the built-in help system. (This function is intended for interactive use.) If no argument is given, the interactive help system starts on the interpreter console. If the argument is a string, then the string is looked up as the name of a module, function, class, method, keyword, or documentation topic, and a help page is printed on the console. If the argument is any other kind of object, a help page on the object is generated.
Note that if a slash(/) appears in the parameter list of a function when invoking [`help()`](https://docs.python.org/3/library/functions.html#help "help"), it means that the parameters prior to the slash are positional-only. For more info, see [the FAQ entry on positional-only parameters](https://docs.python.org/3/faq/programming.html#faq-positional-only-arguments).
This function is added to the built-in namespace by the [`site`](https://docs.python.org/3/library/site.html#module-site "site: Module responsible for site-specific configuration.") module.
Yw
Upload it to GitHub and use heroku
use discord.ext.commands.has_any_roles()
Thx
Run the file
No heroku sucks
he said he wants it online ๐ค
Then how to make a music bot
Besides self-hosting
Is there a code?
I ask because I donโt know -_-
You have an example in dpy's repo
!ytdl
Per Python Discord's Rule 5, we are unable to assist with questions related to youtube-dl, pytube, or other YouTube video downloaders, as their usage violates YouTube's Terms of Service.
For reference, this usage is covered by the following clauses in YouTube's TOS, as of 2021-03-17:
The following restrictions apply to your use of the Service. You are not allowed to:
1. access, reproduce, download, distribute, transmit, broadcast, display, sell, license, alter, modify or otherwise use any part of the Service or any Content except: (a) as specifically permitted by the Service; (b) with prior written permission from YouTube and, if applicable, the respective rights holders; or (c) as permitted by applicable law;
3. access the Service using any automated means (such as robots, botnets or scrapers) except: (a) in the case of public search engines, in accordance with YouTubeโs robots.txt file; (b) with YouTubeโs prior written permission; or (c) as permitted by applicable law;
9. use the Service to view or listen to Content other than for personal, non-commercial use (for example, you may not publicly screen videos or stream music from the Service)
!join.channel

ofc
also 15 sec just to write "!ytdl"?
nah, I started to write something else
Ikr kinda disappointing
then deleted it
Oh I thought he wanted it 24/7
#bot-commands
youtube :troll:
Wait how to do what python just did with the cool colour symbol
I didn't see anything related to "24/7"
And we won't help for that
what "cool color symbol"
the cool what?
what thing
Color symbol?
Online I took that as forever
what
Let me do that again
ok
There
what symbol
Text
Thanks bro
the reaction?
its a embed
No
!d discord.Embed
class discord.Embed(*, colour=Embed.Empty, color=Embed.Empty, title=Embed.Empty, type='rich', url=Embed.Empty, description=Embed.Empty, timestamp=None)```
Represents a Discord embed.
len(x) Returns the total size of the embed. Useful for checking if itโs within the 6000 character limit.
bool(b) Returns whether the embed has any data set.
New in version 2.0.
Certain properties return an `EmbedProxy`, a type that acts similar to a regular [`dict`](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.9)") except using dotted access, e.g. `embed.author.icon_url`. If the attribute is invalid or empty, then a special sentinel value is returned, [`Embed.Empty`](https://discordpy.readthedocs.io/en/master/api.html#discord.Embed.Empty "discord.Embed.Empty").
For ease of use, all parameters that expect a [`str`](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.9)") are implicitly casted to [`str`](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.9)") for you.
The text
an embed isnt a symbol
Ok
The text being random?
Thx
**hello**
he meant the embedded message
@gentle tulip you want to look at this https://discordpy.readthedocs.io/en/stable/ if you want help
no rtfm'ing
Ok
hm
So it's RTFM and nothing more
or google
The example is more than enough
Not for newbies
ยฏ\_(ใ)_/ยฏ

ยฏ_(ใ)_/ยฏ
stop typing fast then
I'm on mobile
How to add those code to the bot
I'm not typing fast
I forgot
oh

i forgor-
You can't even copy paste now?? ๐
Dude
\๐น
Yeah, all you have to do is copy paste it
use an IDE > imports > code > click run
KEK
Wow
Cant even understand what Iโm asking
add the code to your bots code?
learn how to make a file โ
start dpy bot โ
From discord.py import ext
sorry, but wtf?
lmfao
This.
Youโd wanna use pip install
embed fields must be 1024 characters or fewer
No
but there are less than 1024 characters
i mean
Add the code to my application
No
whats ur application in this case
Wdym application
You added all the text_channels
Application
Which returns an entire list of channels
Apps
whats application
And that is??
Bot then
a folder containing code files
@slate swan i assume you wanted the count of channels, which would be len(guild.text_channels)
I take my apologies back ๐
Having a few channels is already enough to get over 1024 characters as you give all the channels
thx
Shut up pls
we said add the code to ur bot earlier but u said application ๐คจ
You are so rude
hes being sarcastic
Me?
No not you...
i have leveling system and my problem is it should level me up and send me congrats message but it keeps gain xp as you can see in photo and keeps gain and the goal is 1.97k exp but he keeps gain to 2.01k why?
he as in kraots
Who?
@client.command()
async def invites(ctx):
totalInvites = 0
for i in await ctx.guild.invites():
if i.inviter == ctx.author:
totalInvites += i.uses
embed = discord.Embed(title="MCity Bot - Invites",
description=f"Invitao si {totalInvites} membera",
color = 0x3498db)
await ctx.send(embed=embed)
how can i track fake invites for this code?
@slate swan
Without code we can't help, giving a picture doesn't help us at all
Is there any way for a discord bot to DM other people?
yes
๐
Use a database and increment a number
!d discord.Member.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**.
Lol laughing
Member.send
@commands.Cog.listener()
async def on_message(self, message: discord.Message):
if message.channel.id != 898662705228029972:
return
if message.author.bot is True or message.guild is None:
return
result = await self.find_or_insert_user(message.author)
user_id, guild_id, xp, level = result
print(xp, level)
xp += random.randint(0, 25)
if self.calculate_level(xp) > level:
level += 1
# 1,000
await message.channel.send(f"Congratulations, {message.author.mention} You are levelled up to {level:,}.")
cursor = await self.db.cursor()
await cursor.execute('Update users set xp=?, level=? where user_id=? and guild_id=?', (xp, level, user_id, guild_id))
await self.db.commit()
Tysm
Anyways to answer your question, you'll need to install ffmpeg and youtube_dl from pip, some additional files but can't tell u which because !ytdl, and to add it to your code copy paste the code in your file
@slate swan here is the code
But... after 5 minutes, I don't know how to do it again
Omg
import time
seconds = 300
while True:
seconds -= 1
m, s = divmod(seconds, 60)
if s == 0 and m == 0:
print('5 minutes passed, restarting the loop')
seconds = 300
elif m == 0:
print(f'{s} seconds')
else:
print(f'{m} minutes {s} seconds')
time.sleep(1)
it was really that hard
!code
Here's how to format Python code on Discord:
```py
print('Hello world!')
```
These are backticks, not quotes. Check this out if you can't find the backtick key.
!codefill
thank you so much
code?
wdym
i have leveling system and my problem is it should level me up and send me congrats message but it keeps gain xp as you can see in photo and keeps gain and the goal is 1.97k exp but he keeps gain to 2.01k why?
Show ur code?
@commands.Cog.listener()
async def on_message(self, message: discord.Message):
if message.channel.id != 898662705228029972:
return
if message.author.bot is True or message.guild is None:
return
result = await self.find_or_insert_user(message.author)
user_id, guild_id, xp, level = result
print(xp, level)
xp += random.randint(0, 25)
if self.calculate_level(xp) > level:
level += 1
# 1,000
await message.channel.send(f"Congratulations, {message.author.mention} You are levelled up to {level:,}.")
cursor = await self.db.cursor()
await cursor.execute('Update users set xp=?, level=? where user_id=? and guild_id=?', (xp, level, user_id, guild_id))
await self.db.commit()
fake edited pic
what
ya i guess so
cuz tht is not possible
~~discord.errors.HTTPException: 400 Bad Request (error code: 10014): Unknown Emoji
when bot tries to react:
await msg.add_reaction(":flag_tr:โโ")
all other flags i need work fine
is there any other way to do flags reactions?
EDIT: it shows :flag_tr: here coz code view but my reaction is unicode
ps i am new T-T~~
as suggested by @slate swan emoji from emojipedia worked fine. Thank You
why do i gonna edit a pic and miss around in help channel -_-
because
pls help
Any code to make the bot online?
bot.run("token")
run the file
@commands.command(aliases=['exec', 'evaluate'])
@commands.is_owner()
async def eval(self, ctx, *, code: str):
I have this in a cog, why am i getting command eval is not found
loaded the cog?
Plsss give any bot name
how do i fix this
bot = client.Bot(command_prefix=)?
yes
don't use discord.Client
use commands.Bot instead to use commands
it needs to be _eval since python already has something called the eval() function
discord.Client doesn't have commands functionality
dont @client.command() use @bot.command()
depend
.
no that's not the problem
yes
@slate swan
the heck
shhhhhh
idk it work fine on mine
nope
commands.Bot
*commands.Bot
it's commands.Bot
oof
ok
i`m stuped
i writed that tho sorry
yes
i mean you could pull it off
ok thx its works now
btw did anyone make ship cmds?
guys
Hello, it's possible to add date in embed ?
Those cmds that ship 2 ppl?
from discord.ext import commands as client 
yes
Did you have a documentation for ?
that is quite useless
ok wait me
yeah
!d discord.Message.created_at
property created_at: datetime.datetime```
The messageโs creation time in UTC.
how would i type hint commands.Context and discord.Message on something like this?
you dont need to typehint it
ctx is just Context not both.
you can if you want tho
Learn how to use typing.Union, or if you're using Python 3.10, the new sugar syntax ctx: Context | discord.Message
just use ctx.message if you need it
id rather typehint because it auto completes and shows me properties they have
ok
ok
then typehint it to commands.Context
embed = discord.Embed(colour=discord.Colour.green(), timestamp=ctx.message.created_at
thanks ๐
not discord.Message
If ctx is custom.. ```py
from typing import Optional, Union
(ctx: Union[Context, discord.Message])
By he has import Context differently.
How i get the user that send the command with the CommandError object?
on_command_error has ctx..?
@autumn bone worked or not
Hahahaha
!message_eror
!d discord.ext.commands.Bot.on_command_error
await on_command_error(context, exception)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
The default command error handler provided by the bot.
By default this prints to [`sys.stderr`](https://docs.python.org/3/library/sys.html#sys.stderr "(in Python v3.9)") however it could be overridden to have a different implementation.
This only fires if you do not specify any listeners for command error.
!d discord.ext.commands.Bot.cogs
property cogs: Mapping[str, discord.ext.commands.cog.Cog]```
A read-only mapping of cog name to cog.
thc
Guys plss give me any bot name
like this?
yes
just think what u like and give it bot
fun,moderation
ahahhahhah
ahahhahahah
nope like i like sky so i named the bot SkyBot
sorry bad speech
Nice but this bot is maked
sorry
give some
ok
thats good name, but someone maybe used the name tho
yes
dont make a bot have a "bot" in its name
its cringe
so if it was for personal use i think its ok
you is cringe
yeah ikr, my bot isnt for public tho
agreement
you cringe
XD
ok guys
ok
ok
"cringe" word is so cringe
dont take it so seriously
ok
you say it anythink for Probot
what
its just flexing its a bot
automatically cring
probot, carl-bot cringe ? 
did anyone want to share ping cmds?
Guys it's fine if it is quite to get a bit off topic but don't argue.
carl bot is gud cause made in python
no spoonfeed
spoonfeed = bad
It is his own code 
its a debate
?
nvm then
okay
"you cringe" hmm debatable.
What should I look into for an image sharing bot?
I want users to upload images via command and view via commands in discord.
change sharingan logo
pillow
?
for image manipulation
wait
Iโm new to coding and itโs my first bot
Are you trolling?
no
how does it help him?
set this image
wdym set the image?
STOP
First time Iโve seen such behavior in this sever.
Shhhhss
i had a question
If you donโt have insight, donโt waste your energy
not like he said it first..
@vapid ingot I assume you are looking for some library that does image manipulation, if so , you can try pillow
!pypi pillow
@bot.command(name="Ping", when i try use ping it doesnt respond. any suggestion?
Iโll look into it thank you!
did u close the parentheses
wut
wut
wait google translating
nice
Well do you got case sensitive commands?
๐ฟ
nope
close it then lol
i have level system and im wanna know how do i when someone level up reset his exp so im not getting errors ```py
class Levelling(commands.Cog):
def init(self, bot):
self.bot = bot
self.db = self.bot.db
async def find_or_insert_user(self, member: discord.Member):
# user_id, guild_id, xp, level
cursor = await self.db.cursor()
await cursor.execute('Select * from users where user_id = ?', (member.id,))
result = await cursor.fetchone()
if result is None:
result = (member.id, member.guild.id, 0, 0)
await cursor.execute('Insert into users values(?, ?, ?, ?)', result)
await self.db.commit()
return result
def calculate_xp(self, level):
return 100 * (level ** 1.2)
def calculate_level(self, xp):
# Sqrt => value ** 0.5
return round(0.1 * math.sqrt(xp))
@commands.Cog.listener()
async def on_message(self, message: discord.Message):
if message.channel.id != 869579846450302978:
return
if message.author.bot is True or message.guild is None:
return
result = await self.find_or_insert_user(message.author)
user_id, guild_id, xp, level = result
print(xp, level)
xp += random.randint(0, 25)
if self.calculate_level(xp) > level:
level += 1
# 1,000
await message.channel.send(f"Congratulations, {message.author.mention} You are levelled up to {level:,}.")
cursor = await self.db.cursor()
await cursor.execute('Update users set xp=?, level=? where user_id=? and guild_id=?', (xp, level, user_id, guild_id))
await self.db.commit()
Wouldn't be the first 
@bot.command(name='Ping')
not like that
i do that with the help
did you do !Ping?
i tested it when i type "Ping" it answer but when i typed"ping" it doesnt
yeah and it run perfectly
you changed the name of the command using the name kwarg
kwarg?
keyword argument
async def ping(ctx):
await ctx.reply('Pong')
why spoonfeed
!d discord.ext.commands.Bot.case_insensitive
Whether the commands should be case insensitive. Defaults to False. This attribute does not carry over to groups. You must set it to every group if you require group commands to be case insensitive as well.
wtf
tq
idk lol
Bad example ignore this
its his code bruh, dont do like that
why
his feed i mean*
cuz it doesnt solve his/her problem
yeah there were better tho, sometime your give bigger latency
@zenith zinc please don't waste your energy if you don't know how to help someone
No type hint, bare function e.g not using the decorator like they are designed.
okkkejjj........ sorry ๐ข
Have you tried debugging it yet?
well i still didnt understand
think of it as an optional parameter I guess?
So you got something like this right?
bot = commands.Bot(command_prefix="!")?
yes i run it and its gain exp but not leveling up
yeah i think
yes
Could you maby print self.calculate_level(xp) and level before the if
add case_insensitive=True in there
that's the same code that we saw yesterday
just from a different guy
well command_prefix="!" is what we call a kwarg we can seperate muliple kwargs with , in thace we want to set case_insensitive to true
my feed try to make the xp bar better
oh ๐ฟ
ok then
even one before that
#discord-bots message
XD i used to copy from stackoverflow but sometime i cant event solve the problem myself
๐
im the same guy
KiMo?
i haven't been on that site since january ๐
yes
mhm
Hey I wanna send a button through my message using nextcord.
Here is my code that does not work
from nextcord import *
from nextcord.ext import commands
@client.command()
async def button(ctx):
button = Button(
label = 'me',
style = ButtonStyle.primary,
url = "https://www.astranova.com/xyz"
)
await ctx.send(button)
What will I do?
Last time I've stolen code on there was on july and I go there because I google people's problems ๐ฟ
its not working btw, it still didnt run
i never googled ppl's problems ๐
isn't it await ctx.send(view=button)
docs don't apply.
Finally
!d discord.ext.commands.Bot take a look here
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.
Notice how in the parenthesis it is formatted?
ok thx ๐
no problem
now i am getting this error
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/nextcord/ext/commands/core.py", line 177, in wrapped
raise CommandInvokeError(exc) from exc
nextcord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: __init__() got an unexpected keyword argument 'label'
And here is the code
@client.command()
async def button(ctx):
button = Button(
label = 'me',
style = ButtonStyle.primary,
url = "https://www.astranova.com/xyz"
)
await ctx.send(view = button)
just use disnake, easier ๐ โ
hmm
imagine self promoting
although i'm fairly sure that your problem doesn't have anything to do with the lib itself
ok i think i messed my code up
you need to pass a View not a Button
but you might wanna check the docs just in case
i did check the docs. there was nothing on sending buttons
Guys How Do I Continue With Discord.py
u cant. use nextcord
disnake >>>
Why?
NEXTCORD??
dpy v2.0 is stable except it doesnโt support slash commands
using 3rd party libs which is most likely to break something in the future so you're better of using a fork (like disnake)
yeah.
almost same syntax as dpy
@nimble kayak , @reef shell https://nextcord.readthedocs.io/en/latest/index.html
i don't remember asking
disnake is def the way to go right now.
^^
i remember u saying why?
i said why you can't continue with dpy until discord makes some breaking changes to their api
anyways your issue is that you're ussing .Button and not ui.Button
says it big here see?
uhhh im still struggle with capital cmds
capital cmds?
Add a case_insensitive=True kwarg next to your command_prefix="!" kwarg
bot = commands.Bot(command_prefix="?")
case_insensitive=True
like that?
put the case_insensitive=True in the tuple
bot = commands.Bot(case_insensitive=True, command_prefix="?")
case_insensitive after command_prefix and yes
sure
It ain't a tuple...
channels += f"{} - {}\n".format(key , channel.mention) whats wrong?
Remove the f
channels += f"{key} - {channel.mention}\n"
parenthesis then
done
constructor
init
hm
BTW Dia
yes?
i just wanna spcae them equally for channel. mention
what
Do u read any library's source code?
no
:c
not that either
bunch of c cpp
Breh, I ain't able to understand HOW events are dispatched
Lmao
well
in Unity, it's just calling functions whenever something sends you a trigger
so that's prolly the case
ask blanket
mb, bunch of .dll files
If i have this query:
"SELECT X, A FROM table"
In python what it returns to me if i use fetchall using sqlite3?
I meant, in dpy...
Tuple
programming
list of tuples
people will use the same logic to do stuff in languages
A lists of tuple or only tuple?
just written elseway
Thanks
Breh, as Rush said yesterday in my DM, what I think, is dpy's source code is like black magic. No one knows how it works lmao
Except Danny and other contribs ofc ^^^
danny should just continue his masterpiece
Indeed
All I wish to know is why dpy thinks asdjdjj is a Context object
every first param is a context object
in a command
put ctx as the first param
๐
and you can remove
await bot.wait_until_ready()
God damnit
I spent an hour trying to fix that
and please change that command name
I hate discord.py
peepoCry
I mean- you could look at a code and every command's parameters start with ctx
me who always did the second one: 
or self, ctx
I thought ctx wasn't necessary
It is, now
has_any_role throws an error if it checks roles from different servers?
That's bad
I'm creating a command and i have to check a role which is set by a command
So i don t know that role during the coding but the bot has to know it when the command is casted
#bot-commands
I m really stuck at this
let me look at it on github
Oke thanks
yes, it checks for member
Ok so I Guess i should check without using discord checks xD
No no, i have that role saved in a database in the guild table
So I have just to check if the author has that role
I hoped that i could do that with checks so it will pass through on_error method but it seems that i have to code it xD
I know i know, just lazy to do it xD
def predicate(ctx):
if ctx.guild is None:
raise NoPrivateMessage()
# ctx.guild is None doesn't narrow ctx.author to Member
getter = functools.partial(discord.utils.get, ctx.author.roles) # type: ignore
if any(getter(id=item) is not None if isinstance(item, int) else getter(name=item) is not None for item in items):
return True
raise MissingAnyRole(list(items))
return check(predicate)
kms
Maybe I can raise the MissingPermission error so it will pass through the on_error event lol
The thing is that i don t know the role during the coding
The role depends on the guild where the command is sent
mmhmm
And that role is set by using a command
doesnt everyone use the 2nd one
after dpy 1.0 yes
who uses dpy <1.0
Yup
I mostly think its really analog
I can read it alright, but some stuff they do makes no sense to me what so ever
Seems like most of it stayed the same since 2015
same
So I should not waste my time smashing my head around tryna figure out how it dispatches an event, right?
Is it possible to use Member objects as dictionary values?
wym
i read dpy's files earlier and most of the files had lots of functions
yea
Just take a look at my dispatch system, discord.py does it like that as well but I do some different stuff
Ah cool. Lemme check it out
which file?
how can i get the cog name for a certain command?
Command.cog
But again, get gateway url endpoint -> connect to ws via the url -> read the messages received from the gateway -> determine what to do
Well, I understand how to receive from the ws, but how to dispatch them
"dispatch" really just passes the event and its data to parsers\
Cool thanks
yeah, i still wasnt able to find the code which was responsible for handling component interactions
Huh
Why would it be any different
I have a dictionary like this:
player1 = {'User': ctx.author, 'Piece': 'x'}```
Whenever I call `player1["User"]` I get the following error: `discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: 'Member' object is not subscriptable`
its still being dispatched over the gateway
You don't need to hardcode for it, just make a parser for components event
i.e interaction_create etc
weird
says str obj has no atrr cog
Yeah.
code
Hello, guys!
I am using discord and discord_components for my imports and I'm trying to make the bot that will respond with client-side messages, like Clyde bot. It works perfectly when I'm trying to respond to button click event, but I was wondering if it's possible to send this kind of client-side message when on_message event is triggered.
Here's what i mean by client-side messages if anyone's wondering. I will appreciate any help, thanks in advance!
is this good or commands???
do u have any other variable named player1?
async def limitedcommands(self, ctx, guildid:str = None):
if guildid is None:
guildid = str(ctx.guild.id)
try:
guildLimit = self.channelLimitations[guildid]
except:
return await ctx.send("Looks like no commands are limited here.")
limitmsg = ""
for command in guildLimit.keys():
cogname = command.cog
channelList = guildLimit[command]```
@maiden fable
https://github.com/an-dyy/Lefi/blob/9916004278b0bfa3027505bb7be063413ef107aa/lefi/state.py#L115-L153 and heres where it actually dispatches the event and its data to the event callbacks
no
u need a Command object
yeah, but out of curiosity wasnt able to find the relevant part which calls the components callback
Ok, thanks!
Nope.
how
weird then
bot.get_command
discord/state.py lines 701 to 708
def parse_interaction_create(self, data) -> None:
interaction = Interaction(data=data, state=self)
if data['type'] == 3: # interaction component
custom_id = interaction.data['custom_id'] # type: ignore
component_type = interaction.data['component_type'] # type: ignore
self._view_store.dispatch(component_type, custom_id, interaction)
self.dispatch('interaction', interaction)```
I have assigned it to another variable though. Could that possibly be the issue? I did active_player = player1
could be. idrk tbh, sorry
@maiden fablepy for command in guildLimit.keys(): cmd = self.bot.get_command(command) cogname = cmd.cog channelList = guildLimit[command]
like this?
Yea ig
how would i go about running multiple discord clients?
def one():
client.run(tokens[0], bot = False)
def two():
client.run(tokens[1], bot = False)
i tried threading i get some positional argument error
Is there a discord.Sticker class or something?
pretty sure that's against discord's ToS
!d discord.Sticker
class discord.Sticker```
Represents a sticker.
New in version 1.6.
str(x) Returns the name of the sticker.
x == y Checks if the sticker is equal to another sticker.
x != y Checks if the sticker is not equal to another sticker.
simple answer:
you cant run 2 bots on the same file
ty
you can
but he's not trying to run a bot from what i see
hm
to run multiple bots from the same file you can do something like this ```py
import asyncio
from discord.ext import commands
loop = asyncio.get_event_loop()
bot_1 = commands.Bot(loop=loop, ...)
bot_2 = commands.Bot(loop=loop, ...)
loop.create_task(bot_1.start(token_1))
bot_2.run(token_2)
what does bot_1 refer to?
it's a var
Neither is it recommended
^
start is a coro
If you read the source code you would know its blocking
And something being a coro doesn't mean it isn't blocking
you're creating a task
It would still block
it wouldn't
why isnt this working?
@bot.event
async def on_reaction_add(ctx, reaction, user):
channel = reaction.message.channel
await ctx.send(channel, '{} has added {} to the message: {}'.format(user.name, reaction.emoji, reaction.message.content))
!d discord.ext.commands.Bot.start
await start(token, *, reconnect=True)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
A shorthand coroutine for [`login()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Bot.login "discord.ext.commands.Bot.login") + [`connect()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Bot.connect "discord.ext.commands.Bot.connect").
its supposed to send a message whenever a reaction is added to a message
It doesn't take ctx as an argument
Only args are reaction and user
!d discord.on_reaction_add
discord.on_reaction_add(reaction, user)```
Called when a message has a reaction added to it. Similar to [`on_message_edit()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_message_edit "discord.on_message_edit"), if the message is not found in the internal message cache, then this event will not be called. Consider using [`on_raw_reaction_add()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_raw_reaction_add "discord.on_raw_reaction_add") instead.
Note
To get the [`Message`](https://discordpy.readthedocs.io/en/master/api.html#discord.Message "discord.Message") being reacted, access it via [`Reaction.message`](https://discordpy.readthedocs.io/en/master/api.html#discord.Reaction.message "discord.Reaction.message").
This requires [`Intents.reactions`](https://discordpy.readthedocs.io/en/master/api.html#discord.Intents.reactions "discord.Intents.reactions") to be enabled.
Note
This doesnโt require [`Intents.members`](https://discordpy.readthedocs.io/en/master/api.html#discord.Intents.members "discord.Intents.members") within a guild context, but due to Discord not providing updated user information in a direct message itโs required for direct messages to receive this event. Consider using [`on_raw_reaction_add()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_raw_reaction_add "discord.on_raw_reaction_add") if you need this and do not otherwise want to enable the members intent.
By blocking means become synchronous not asynchronous
ยฏ_(ใ)_/ยฏ
bot.start by itself is blocking, and create_task runs it the running loop
should this not block the running loop???
I'm confused now
so you want me to show you that i can run 2 bots on the same event loop?
isnt running a bot already an asyncio event loop
.start is as it says, a coro, a coro is an asynchronous function
So this isn't blocking by that logic.... ```py
async def sleep():
time.sleep(10)
you'd use asyncio.sleep
That's not the point
I'm trying to tell you that just being a coro doesn't mean it doesnt block
Making it not asynchronous
that's because you're running it using asyncio.run
try making a loop and running it on that loop
asyncio.run is not relevant I'm just showing you again, that just because its a coro
does not make it not blocking
ยฏ_(ใ)_/ยฏ
and do you even know what asyncio.run does?
it creates a new event loop and runs it on there
yeah saw that now that i read its docs
Which goes back to my original question as to why it didn't block the loop
create_task if I'm not wrong runs the coro in the running loop so shouldn't it be blocking it
async do be confusing 
gives a nonetype error
how can I prevent an event if an action is done ?
for example, if my bot leave the server himself, is it possible to don't call the on_guild_remove event ?
idk dude. seems like a DB problem tbh
for command in guildLimit.keys():
cmd = self.bot.get_command(command)
cogname = cmd.cog```
the command here is the command name
is it the corrct wat to get the command?
correct*
The point of this event is to log when your bot gets removed from a server
If you don't need it, don't add the code...
I need it, but I need it to be started only if the bot is kicked from the server, not if the bot leaves the server himself
then when the bot leaves himself unload the cog where you have the event and after it's done load it back
okay thanks, I'll do that
yw
hw cn i get the roles from the channel overwrites
!on_message.delete
!d on_message_delete
No documentation found for the requested symbol.
discord.on_message_delete(message)```
Called when a message is deleted. If the message is not found in the internal message cache, then this event will not be called. Messages might not be in cache if the message is too old or the client is participating in high traffic guilds.
If this occurs increase the [`max_messages`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") parameter or use the [`on_raw_message_delete()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_raw_message_delete "discord.on_raw_message_delete") event instead.
This requires [`Intents.messages`](https://discordpy.readthedocs.io/en/master/api.html#discord.Intents.messages "discord.Intents.messages") to be enabled.
Are there any good commands I could work on to help deepen my knowledge of discord components? I have an end goal of what I want to do but I would first need learn how to use them. Im just drawing blanks right now
Hi im trying to make a music bot leave after every person leaves. Here's the code:
@commands.Cog.listener()
async def on_voice_state_update(self, member, before, after):
if not member.id == self.bot.user.id:
pass
if before.channel is not None:
voice = before.channel.guild.voice_client
if len(after.channel.members) == 1 and voice.is_connected() is True:
await voice.disconnect()```
AttributeError: 'NoneType' object has no attribute 'members'
``` and im getting this error
!d discord.on_voice_state_update
discord.on_voice_state_update(member, before, after)```
Called when a [`Member`](https://discordpy.readthedocs.io/en/master/api.html#discord.Member "discord.Member") changes their [`VoiceState`](https://discordpy.readthedocs.io/en/master/api.html#discord.VoiceState "discord.VoiceState").
The following, but not limited to, examples illustrate when this event is called...
can't help
?
That's meant for me
kk
if user_message.startswith(f'*quote'):
response = f'{user_message}, {username} 2021'
await message.channel.send(response)
return
.
I want to quote the word that the user said
Hello, guys!
Does anybody know how to delete a ping notification message?
if user_message.lower() == '*specs':
await message.channel.send("SSD: M.2 1000GB Hard Drive")
await message.channel.send("MOBO: B460M Pro Vdh Wifi")
await message.channel.send("GPU: Intel UHD 630")
await message.channel.send("Case: H510 Elite")
await message.channel.send("RAM: 16GB")
await message.channel.send("CPU: Intel core i5 10400")
return
how do i make this into embed text?
!d discord.Embed
class discord.Embed(*, colour=Embed.Empty, color=Embed.Empty, title=Embed.Empty, type='rich', url=Embed.Empty, description=Embed.Empty, timestamp=None)```
Represents a Discord embed.
len(x) Returns the total size of the embed. Useful for checking if itโs within the 6000 character limit.
bool(b) Returns whether the embed has any data set.
New in version 2.0.
Certain properties return an `EmbedProxy`, a type that acts similar to a regular [`dict`](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.9)") except using dotted access, e.g. `embed.author.icon_url`. If the attribute is invalid or empty, then a special sentinel value is returned, [`Embed.Empty`](https://discordpy.readthedocs.io/en/master/api.html#discord.Embed.Empty "discord.Embed.Empty").
For ease of use, all parameters that expect a [`str`](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.9)") are implicitly casted to [`str`](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.9)") for you.
i even tried that!
then what's the error
if member.activities[0].name != "blahblah":
IndexError: tuple index out of range
On a side note tf is an M.2 1000GB Hard Drive
There are hard drives
And NVME m.2 ssds
it means that the user doesn't have any activity
so you get the index error
So I made a timer command and when the bot says โyour timer has endedโ is there any way to show the result of the time like โyour timer has ended (60s)โ?
@commands.command()
async def timer(self, ctx, seconds):
try:
secondint = int(seconds)
if secondint > 300:
await ctx.send("i dont think i can go over 5 minutes")
raise BaseException
if secondint <= 0:
await ctx.send("i dont think i can do negatives")
raise BaseException
message = await ctx.send(f"โฑ๏ธ Timer: {seconds}")
while True:
secondint -= 1
if secondint == 0:
await message.edit(content="โฑ๏ธ Timer ended")
break
await message.edit(content=f"โฑ๏ธ Timer: {secondint}")
await asyncio.sleep(1)
await ctx.reply("your countdown has ended")
except ValueError:
await ctx.send("you must enter a number")
Anybody? ๐
while True is blocking
do you mean pinned?
!d discord.wait_for
No documentation found for the requested symbol.
don't do that
Not pinned messages exactly, but rather the notification about the message being pinned
!d discord.ext.commands.Bot.wait_for
wait_for(event, *, check=None, timeout=None)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Waits for a WebSocket event to be dispatched.
This could be used to wait for a user to reply to a message, or to react to a message, or to edit a message in a self-contained way.
The `timeout` parameter is passed onto [`asyncio.wait_for()`](https://docs.python.org/3/library/asyncio-task.html#asyncio.wait_for "(in Python v3.9)"). By default, it does not timeout. Note that this does propagate the [`asyncio.TimeoutError`](https://docs.python.org/3/library/asyncio-exceptions.html#asyncio.TimeoutError "(in Python v3.9)") for you in case of timeout and is provided for ease of use.
In case the event returns multiple arguments, a [`tuple`](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.9)") containing those arguments is returned instead. Please check the [documentation](https://discordpy.readthedocs.io/en/master/api.html#discord-api-events) for a list of events and their parameters.
This function returns the **first event that meets the requirements**...
Oh Idk about this
Quite simple, it should print the amount of members in role however it prints 0.
Does anyone know why? It has caught the correct role as it prints Role.id correctly but always returns Role.members with 0
Your members intent is disabled
how can i only delete messages sent by bots with my purge command?
ping?
Check if the message author is a bot or not
!d discord.abc.User.bot
If the user is a bot account.
what theme is this?
I enabled it but it still doesnt work
how would i check a if a user was online in a command not event
You need to enable it inside your code
I<3u
No wonder it comes from there... Pure toxicity
Dpy server has some good tags
For example:
slash cmd
indeed
you made that
I remember
shhh
you're a bad person, I said
4k60fps tho
but I don't remember what it was so I'll tag it again
.
That's a good song
indeed
Sorry if this isn't the right place to ask, but how do I make sure my application is public?
it is the right place, dw
but I dunno
Anyways it looks like It's public to me
so I pass
why doesn`t it work?
await wl.connect()
discord.voice_client.play(discord.FFmpegPCMAudio("C:/Users/VIP/Documents/Audiotonic/Starcity.mp3"))
while not voice_client.is_done():
await asyncio.sleep(1)
await wl.disconnect()
print(len(channel1.members))```
Error:
```py
discord.voice_client.play(discord.FFmpegPCMAudio("C:/Users/VIP/Documents/Audiotonic/Starcity.mp3"))
AttributeError: module 'discord.voice_client' has no attribute 'play'```
!rule 5
5. Do not provide or request help on projects that may break laws, breach terms of services, or are malicious or inappropriate.
no. the mp3 is local on my pc
well I guess then
use ctx.voice_client
discord.voice_client is not a thing
!d discord.ext.commands.Context.voice_client
property voice_client: Optional[VoiceProtocol]```
A shortcut to [`Guild.voice_client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Guild.voice_client "discord.Guild.voice_client"), if applicable.
the problem is that this is an on_voice_state_update event
mmhmm
so ctx will not work
so it's a voice channel
yes
so how can i play music in a specefic vc?
yes?
oh i have it alreasdy
then you can use voiceClient.play()
yw
does anyone know what this error is AttributeError: 'FFmpegOpusAudio' object has no attribute '_process'
is it in the same directory as ur py file
yeah basically lookk
idk
Well, we shouldn't really help for mass dm bots
2. Follow the Discord Community Guidelines and Terms Of Service.
!rule 5
5. Do not provide or request help on projects that may break laws, breach terms of services, or are malicious or inappropriate.
didn't notice it's a mass dm bot
its to dm all members of my server announcements
i sincerely apologize sir, i did not realize.
why won't this work?
if len(channel1.members) == 0:
for members in channel2:
await members.move_to(channel1)
if len(channel2.members) == 0:
for members in channel3:
await members.move_to(channel2)
if len(channel3.members) == 0:
for members in channel4:
await members.move_to(channel3)```
error:
``` for members in channel2:
TypeError: 'VoiceChannel' object is not iterable
Channels are VC's
Channels aren't iterable as error says
You want to be iterating over members
The property of the channel
couse there are now members in the channel?
?
You just need to iterate over the channels member property
I.e the list of members in the channel
okay
Loop through the channel .members, and not the channel object itself
Does anyone know why it doesn't wanna print the channel name where the message was sent?
import random
TOKEN = ''
client = discord.Client()
@client.event
async def on_ready():
print('Bot Is Running as {0.user}'.format(client))
@client.event
async def on_message(message):
print(message.channel.name)
client.run(TOKEN)
add await client.process_commands(message) in your on_message event
That's for processing commands






