#discord-bots
1 messages · Page 748 of 1

= pikachurole
so just str the emoji and add the role
it would look like py role = client.get_role(id) await ctx.author.add_roles(role)
it doesnt work. I've tried the role names and ids
Thats wut he wants right?
that is so not related to this question and bad
It is applicable for custom emojis only, stringing the unicode one would return itself
Thx
Wuts his question
His question is about adding a role but role is found by emoji
then he needs sets 🙂
and cant you just add the role with the id
How would he get the role id by emoji with set
this conversation is given me a stroke
Docs site lagging for me for some reason
Basically he use db or json so he can get it with the utils.get like {":man_police_officer:":"id"}
This is called a dict, not a set and isn't this what I said at first
Idk how to explain doe💀
Didnt see ur msg
yeah totally

And you can get an item from a dict like
d = {'yes': True, 'no': False}
d['yes']```
You don't need utils.get for a dict lol
Bro i thought he wants to use -add to get the role
so how you're going to get the role🤔
can you guys just stop with it? i got it to work...
newEmoji = emoji.split(":")
newEmoji2 = newEmoji[1]
roleName = newEmoji2.replace("_", " ")
role = discord.utils.get(member.guild.roles, name=(roleName))
await member.add_roles(role)
your zero two has turned evil
theirs explaining to do🧍♂️
*there's-
d = {'👮♂️': 12345}
@bot.command()
async def cmd(ctx, emoji):
await ctx.author.add_roles(ctx.guild.get_role(d[emoji]))```
Like this besides I don't remember what the emoji is like when parsed to command
looks like my method
yes🧍♂️
it is

class discord.Emoji```
Represents a custom emoji.
Depending on the way this object was created, some of the attributes can have a value of `None`...
Oh well thats wut he wants 
do you know how to check if a user has a sertain role? (ok i worded that horrably, let me explain)
like check if the user has a role that is in a list called roleList?
I have @commands.has_any_role(roleList), and ive tried using the role id's and names, but it just doesnt work
what's in roleList
probably doesnt work because you could be storing ints as a str
!d discord.Member.roles
property roles: List[Role]```
A [`list`](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.9)") of [`Role`](https://discordpy.readthedocs.io/en/master/api.html#discord.Role "discord.Role") that the member belongs to. Note that the first element of this list is always the default [‘@everyone](mailto:'%40everyone)’ role.
These roles are sorted by their position in the role hierarchy.
that doesnt have anything to do with this
You could do
if some_role in member.roles```
the rolelist is a list of ceratin foles i assume
role1 = "931261295846654042"
role2 = "931261273503576107"
role3 = "931261310325362798"
roleList = [role1, role2, role3]
is there an easy way to replace unicode emojis with their text representation?
(e.g. 👀 -> :eyes: or 😳 -> :flushed:)
called it
remove the quotation marks
called it
?
yw
wtf
still getting the same error -_- ;-;
?
@frank tartan troll?
no, why?
well
does it even accept a list
i was told yes
i dont think so
only
oh
i think it accepts *args
u make 3 hardcoded var for ids
which is a tuple
bet
n put to list n pass it
why not hardcode em in a list
cuz i use those variables else where
@discord.ext.commands.has_any_role(*items)```
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 **any** of the roles specified. This means that if they have one out of the three roles specified, then this check will return True.
Similar to [`has_role()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.has_role "discord.ext.commands.has_role"), the names or IDs passed in must be exact.
This check raises one of two special exceptions, [`MissingAnyRole`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.MissingAnyRole "discord.ext.commands.MissingAnyRole") if the user is missing all roles, 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 [`MissingAnyRole`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.MissingAnyRole "discord.ext.commands.MissingAnyRole") 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")
I'm gonna retreat
member_roles_ids = map(lambda i: i.id, ctx.author.roles)
if any([role_id in member_roles_ids for role_id in roles_list])```
Any better way to check if the user has one of roles in list (full of ids)?
even has a example
@commands.has_any_role('Library Devs', 'Moderators', 492212595072434186)
hmmmmmmm ok
roleList badname first of all
Hold up wrong way to much iter
its not the actual name -_-
your help isnt useful
agreed
but discord_ids = ["1234", "5678", "901011"]
tyyyyyyy it works
🙂 your de best
and you stored them as strings
this
no u ❤️
man you are throwing
Now I really need to know what does emoji look like when parsed to a command but the problem is it's 1am
its 5pm for me
or idlist = []
idlist.append(id_var)
hes problem has been solved why continue?
@vale wing 10pm
here aswell
1am just hit
2200 militarytime
Behold, I've created the worst looking rank card
that makes me wanna quite python
🚪🚶
It actually looks better with black background
yes
hey everyone
i have another question to ask
i am trying to make a bot where if you dm it once, it will give you a response. but if you dm it twice, it will give you a different repsonse
``dm 1: hey, i am a bot
dm 2: you already dmd me!``
database
My problem would be that the nanny button refers to the fact button, so the nanny changes after pressing the button. I tried to replace the custom id but then did not send anything to the button. Lib: discord_components The Code:
async def dadjoke(self, ctx):
await ctx.send(embed=discord.Embed(color = 0x34568B, title="Dad Jokes From CTRL", description=f"{random.choice(dadjokes)}"), components=[[
Button(style=ButtonStyle.green, label="Next :arrow_forward:", custom_id="button1"),
Button(style=ButtonStyle.red, label="Stop :octagonal_sign:", custom_id="button2"),
]])
@commands.Cog.listener()
async def on_button_click(self, interaction):
if interaction.component.custom_id == "button1":
await interaction.respond(type=7, embed=discord.Embed(color = 0x34568B, title="Dad Jokes From CTRL", description=f"{random.choice(dadjokes)}"))
elif interaction.component.custom_id == "button2":
await interaction.edit_origin(embed=discord.Embed(color = 0x34568B, title="Dad Jokes Stopped! :police_officer:", description=f"If you would like to use it longer, then push the next button or >dadjoke"))
@commands.command(aliases=["Facts","facts","Fact"])
async def fact(self, ctx):
await ctx.send(embed=discord.Embed(color = 0x990033, title="Did you know? :astonished:", description=f"{random.choice(facts)}"), components=[[
Button(style=ButtonStyle.green, label="Next", custom_id="button1"),
Button(style=ButtonStyle.red, label="Stop", custom_id="button2"),
]])
@commands.Cog.listener()
async def on_button_click(self, interaction):
if interaction.component.custom_id == "button1":
await interaction.respond(type=7, embed=discord.Embed(color = 0x990033, title="Did you know? :astonished:", description=f"{random.choice(facts)}"))
elif interaction.component.custom_id == "button2":
await interaction.edit_origin(embed=discord.Embed(color = 0x990033, title="random Facts Stopped!", description=f"If you would like to use it longer, then push the next button or >fact"))```
!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.
!code
Oop

!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.
Somebody? Besides api pages and "don't use this shitty library" sayings?
I don't get why'd you need a listener when there's wait_for
how can i do
!removeRole member
and it will remove the member role from them?
ive tried
await member.remove_roles(roleName)
but i cant seem to find a way to define member that makes it still work
If you don't bother to listen, this is old code and almost no one uses it anymore.
You need to typehint the role arg
Reading is also part of the job
? what does typehint mean?
async def removerole(ctx, member: discord.Member, *, role: discord.Role)```
And then you can remove it with `remove_roles`, as it takes `Role` object
the : representing a variable
role : discord.Role as a parmeter
Everyone here says everything's old, but nobody says anything other than nextcord, and I don't want to use it.
For pep8 sake it's role: discord.Role
Disnake better
-_- i already have that. also, i dont need to define the role name
Wym
Can you show your code?
Code style
Why not though this is much more difficult.
@client.command()
async def removeRole(ctx,emoji):
author_id = ctx.author.id
newEmoji = emoji.split(":")
newEmoji2 = newEmoji[1]
roleName = newEmoji2.replace("_", " ")
await member.remove_roles(roleName)
thats how pep8 says
You don't have the thing you mentioned
we have had problems with compatibilities
?
PEP 8 is the official style guide for Python. It includes comprehensive guidelines for code formatting, variable naming, and making your code easy to read. Professional Python developers are usually required to follow the guidelines, and will often use code-linters like flake8 to verify that the code they're writing complies with the style guide.
More information:
• PEP 8 document
• Our PEP 8 song! :notes:
With Disnake?
no, nextcord
There's no role typehint or even role argument
Dunno don't use it.
Ikr
me neither
i already have a way to define the role -_- read the code
i just need to define member in member.remove_roles
await remove_roles(*roles, reason=None, atomic=True)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Removes [`Role`](https://discordpy.readthedocs.io/en/master/api.html#discord.Role "discord.Role")s from this member.
You must have the [`manage_roles`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.manage_roles "discord.Permissions.manage_roles") permission to use this, and the removed [`Role`](https://discordpy.readthedocs.io/en/master/api.html#discord.Role "discord.Role")s must appear lower in the list of roles than the highest role of the member.
And you get Role by its id (better method) or by using utils.get with certain params
nvm...
U didnt get it right
nope.
U dont know how to define "member"? 🤔
in the past ive defined member as an arg. but this time i want them to be able to do
-remove 👮♂️
then a role called police man will be removed from them
Then u gotta do this member = ctx.author🙂
THANK YOU, FINALLY SOMEONE WHO UNDERSTANDS
Tell me if it works
i will

PEP 8 song is very epic
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'str' object has no attribute 'id'
i get this error
Show me ur code
@client.command()
async def removeRole(ctx,emoji):
member = ctx.author
newEmoji = emoji.split(":")
newEmoji2 = newEmoji[1]
roleName = newEmoji2.replace("_", " ")
await member.remove_roles(roleName)
I mean ur code seems weird
Y dont u use this
those are 4 unnecessary variables
Also camelCase is not for python
im used to using camelCase
Well personally I don't really care about that but it is not suitable for python in terms of code readability
If Java or C# is written with camelCase it will be readable, but python won't and vise versa
ok nice to hear about your opinion on how i write my code
Not an opinion but a small advice you can follow or ignore
ok i will ignore. considering camelCase is what im used too, i like it, and its what my python teacher is telling me to use
how can i stop my bot from waiting for an event should i set the timeout to the timeout i want with a var and then when i change the var it will cancel it since the timeout was set to a second?
I'm using sqlite3 with python, and when I use string.replace(), it makes sqlite3 raise errors because its counting them as multiple bindings
cuz i dont want to do that 30 times
type that?
here is the code that I'm having this issue with currently:
@bot.command()
async def deliverystatus(ctx,*,ordernum):
for row in cur.execute("SELECT deliverystat FROM orders where id = (?)", (ordernum.replace("#", ""))):
await ctx.send(str(row[0]))
You mean stop the wait_for?
yeah
That's an interesting question
ikr
But like how do you want to stop it, from code or by sending a message, adding reaction, etc.
on an interaction it will just stop it from listening to that event
a = 60.0
timeout=a
#on an interaction
a = 1.0
this is my method i was thinking
then idk
Nope it won't work
why so?
60 will be parsed to the function and it will not vary
ah yeah makes sense
Afaik the wait_for will only stop if it got a right event with check passed or if it timeouts
yeah ik
ion think u can stop an event 
im using buttons and one of them uses waif for to wait on a msg and i set a button to stop the event and stop the action given by the first button
Why'd you need to stop the event, you could just handle the return
soo what do you suggest i do to fix the error? I would use this, but i dont wanna do it 30+ times
it needs to check the author and if the author wants to cancel the action it wont do anything
or maybe i can just set a timeout and if the author isnt right just pass it ig
Could you show your wait_for with a check
dont have one lol
Oh lol
I suggest u to use that code 
nobody has answered me...
i think about my code first

how would i add multiple items to it?
Everyone does tho but when you start trying there's a higher chance you will find the solution, as you see everything easily 
i never start i only think and troubleshoot it in my mind
Ok
i am trying to make a bot where if you dm it once, it will give you a response. but if you dm it twice, it will give you a different repsonse
``dm 1: hey, i am a bot
dm 2: you already dmd me!``
anyoneee
You would probably need to store the users it has replied to somewhere
how would i do that
U need database
If you are going to store it after bot shutdown, there are databases
wdym?
Wym
I told him 30 min ago to use a database
well either you tell me how to add more items to it or i have to have 30+ variables...
me?
For small projects you could use pickle or json tho it's not recommended
no
kk
Wym by "add more items" 🤔
json like max 10 guilds
Like adding it to dict?
Yeah
yes
ohh i thought u meant to ask #databases
By small I mean 1-2 guilds
If u have more roles🤷🏾
sqlite for around 30k if you merge it with aiosqlite
How many with asyncpg 
Depends on how many pools, caches and server you got
Considering them the same you counted for sqlite
I'd say one server can handle about a million or 2/3
the reason i didnt want to store it in a dict is cuz there are 30+ roles i want ppl to be able to get by doing
-addRole 👮♂️
not just a police man role
Well that's still pretty small when looking at bigger companies. Also looking as commands can sometimes use multiple queries.
You could implement the following logic
Get role name by emoji
|
Check if role with this name already exists
|
If not exists create one
|
Assign the role
Then u can add em to dict like py {"👮♂️" : "police man role's id", "🥷🏾" : "ninja role's id"} ect
Reaction roles?
no
kk
that wont work
Well what do the big bots use
Clusters?
Most likely but Discord bots don't really need that much shit unless you do music.
Haha yes
wait why didnt you guys say this when i talked about adding roles the same way?
u can change it to removing roles
no i cant
I am thinking on migrating from sqlite to postgres when my bot hits 200 servers, right now I store lists in a very bad way
wait
Yes u can change ctx.author.add_roles to ctx.author.remove_roles
The issue is I gotta read too much of docs but I alr will
1 day of postgre and you're good to go
thats litterly what i did.... but it didnt work so i came here to asked for help... but than you guys are now telling me to redo it all
I have already tried it on my ubuntu server and I couldn't even find the proper setup guide at first
Show me ur code then
for which cmd?
The one you're working on
which one
@cloud dawn can you recommend any good postgres setup guides
Remove role?
Besides their documentation
@client.command()
async def removeRole(ctx,emoji):
member = ctx.author
newEmoji = emoji.split(":")
newEmoji2 = newEmoji[1]
roleName = newEmoji2.replace("_", " ")
await member.remove_roles(roleName)
Wut abt add role?
newEmoji = emoji.split(":")
newEmoji2 = newEmoji[1]
roleName = newEmoji2.replace("_", " ")
role = discord.utils.get(member.guild.roles, name=(roleName))
await member.add_roles(role)
!d discord.Role
class discord.Role```
Represents a Discord role in a [`Guild`](https://discordpy.readthedocs.io/en/master/api.html#discord.Guild "discord.Guild")...
how does that help?
u need to check docs
it still works
@client.command()
async def removeRole(ctx,role:discord.Role):
member = ctx.author
await member.remove_roles(role)
#Command Use:
{prefix}removeRole <metion role> or <or role.id>
Example (if prefix is !)
!removeRole @Admin
!removeRole role_id
He's doing a different thing and can't figure it out yet
He wants to add roles by an emoji
oh
read the conversation -_- i wanna do it by emoji not pinging the role
never see that!
ok im dumb
i forgot to add
role = discord.utils.get(member.guild.roles, name=(roleName))
to remove role
Just install postgre?
for file in os.listdir():
if file.endswith(".mp3"):
os.rename(file, "song.mp3")
await ctx.author.voice.channel.connect()
voiceClient = discord.utils.get(client.voice_clients, guild=ctx.guild)
voiceClient.play(discord.FFmpegPCMAudio(Path("song.mp3"), **ffmpeg_options))
Could someone help why this isn't working? It just comes up saying Option reconnect not found.
All I want to do is play music from a .mp3 file lol, yet it's so complicated.
Something is wrong with ffmpeg_options
Will it work without it?
I think so
!d disnake.ext.commands.Bot.reload
Whether to enable automatic extension reloading on file modification for debugging. Whenever you save an extension with reloading enabled the file will be automatically reloaded for you so you do not have to reload the extension manually. Defaults to False
New in version 2.1.
Well this saved a lot of time
If I was gonna make a leaderboard, how would I do that?
Like an embed with all the names and point values then I also need a command to add points.
How would I do that?
Database
Is there any good but easy ones that I should use?
Like ones that aren't too hard to learn
They all are the same level of difficulty.
.name
Ok, thanks
Do recommend postgresql
What's the difference between postgresql and sqlite?
postgresql is a relational database were as of sqlite is a file based sql.
Wdum relational?
So for postgre you need an additional program to run it. Sqlite doesn't that are just files. Postgre is significantly faster though.
An additional program.. what is it?
I recommend postgre for large projects around 30k+ guilds and postgresql for more guilds than that
postgresql's program
It's for about 16-17 guilds at most
sqlite is a good option then
Ok
Use aiosqlite and your good
Aiosqlite, got it, thanks Panda
!pypi aiosqlite
:3
just learned it myself
Try to get started with the docs you can always ask for help along the way.
youll need to learn sql which i recommend to use https://sqlbolt.com/
SQLBolt provides a set of interactive lessons and exercises to help you learn SQL
What's the difference between SQL and aiosqlite?
SQL is the syntax as of aiosqlite is a python module meant to communicate between the sqlite database and your porgram.
nothing
sql = (Structured Query Language) tldr a database language
sqlite = db
aiosqlite = async instance of the sqlite db
Ah, so aiosqlite is like an add-on in a way to sqlite
Well more like to Python.
its like and api wrapper
it just talks to sqlite which aiosqlite is like the endpoint of it
gosh im horrible at examples
that's.. really not how it works
the endpoint is the remote server, which in this case would be sqlite
yeah ik
aiosqlite is the client connecting to the remote
but idk if he understood it
To be fair, I'm just gonna do the guide and hope I can think up some sort of example and hope it works. Thanks for the help tho :)
you should learn sql first just saying
its like going to dpy without knowing dpy
you wont understand it
You should start learning over here, https://sqlbolt.com/ sqlbolt teaches you SQL by examples and quick challenges
really good interactive tutorial
That's what I'm following, the sqlbolt thing
##############################
#--- button ticket system ---#
class Support(discord.ui.View):
def __init__(self):
super().__init__()
self.value = None
@discord.ui.button(label='Create a ticket', style=discord.ButtonStyle.grey, emoji="📩")
async def create(self, button: discord.ui.Button, interaction: discord.Interaction):
channel = await interaction.guild.create_text_channel(name=f"{interaction.user.name}-{interaction.user.discriminator}")
await channel.set_permissions(interaction.user, send_messages=True, read_messages=True)
await interaction.response.send_message(content=f"Ticket created {channel.mention}", ephemeral=True)
self.value = False
@bot.command()
async def support(ctx):
view = Support()
supportembed = discord.Embed(title=" ", color=botcolortheme, description="To create a ticket, click below")
supportembed.set_author(name="Support")
await ctx.send(embed=supportembed, view=view)
await view.wait()
#--- end of button ticket system ---#
#####################################
with this command it creates a channel with overwritten perms to the ticket to type and view the channel as a ticket, is it possible to make the channel created in a specific category with a id or the category name(prefered)?
can i send a message when the bot turn on
How do I actually make a database?
Like how do I put info into it?
It's got this sort of lay out on the site but never actually says how to make a database on sqlbolt, it just uses a table diagram
Got a guide for this?
not a specific one, no.
Damn
largely depends on what he's going to use
Oop nvm you’re not using PostgreSQL
Probably still examples if you look in the official dpy server
Wait that’s a different person; what are you going to use?
If it’s postgresql I can provide an example or two
Sqlite
I just started making discord bots, and I got an error saying that "event() missing 1 required positional argument: 'coro' error discord.py" in this code:
import discord
import os
client = discord.Client
@client.event
async def on_ready():
print(" We have logged in as, {0.user}" .format(client))
@client.event
async def on_message(message):
if messag2.author == client.user:
return
if message.content.startswith('[ Hi'):
await message.channel.send('Hello bros')
client.run(os.getenv("token"))```
pls halp!
messag2
In client event, the second one, you have if messag2.author == client.user:
Change messag2 to message.
oops i did that
but its telling theres a problem with "async def on_ready():" thats what the error was for
i had already realized that mistake and changed it btw
make a task and send the message but use wait_until_ready() so it wont send a msg while the bot internals cache is loading
!d discord.ext.commands.Bot.wait_until_ready
await wait_until_ready()```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Waits until the client’s internal cache is all ready.
pycord, discord.js
Thanks
why the heck would he change his language
Which should I do py cord or disnake
thats just dumb
pycord is very similar
disnake
discord.js has more features and can do more with it
Disnake is like the exact same right just import disnake
idc you dont recommend someone to change his whole language because of a lib thats just stupid
correct
i just see why u switch
Yeah I’ve seen some of the documentation
discord.py is better
Pycord is regarded as one of the meh forks
stay with discord.py if u can
Bro there is no difference
Between disnake and discord.py
Well I mean besides a few things
because you know js doesnt mean your smart btw
But majority it’s like exact same
Dude why would I go to something that’s not goi mf to be updated
dpy is hard and python as well so dont come here comparing them
that is python
@slate swan if u dont want anything very similar to discord.py try discord.js
Dude I do not wanna do js
Or you can just use a lib that's not a fork of discord.py
ik
disnake is a fork btw
is there any way i can make a discord bot not repeat a previous message? for example
bot: @user tagged me!
user: @bot
bot:-------```
hikari
U can try saving the last message as a variable and then comparing to see if the new message matches the old one
whats the code for the last message?
he probably wants it per user so use a db
What do u use for db
Hikari is actually pretty nice clean written
@slate swan
where do i start with a db?
andy knows
Rewriting my wrapper to not be like discord.py now
wish hikari
@slate swan
!pypi aiosqlite
Not really
Ok thx
learn sql and then use aiosqlite
The repo is private right now but if you see the revamp as it is now It's pretty different
mhmmm
Even revamped caching system
Now it looks like this ```py
class User(Cacheable, type="User", max=1000):
...
nice
what's aiosqlite
is it
like sqlite3
or sql
but for async
Yes
its a async bridge of sqlite
nice
Its just sqlite3 but async
so like database stuff im guessing?
yeah
yes
hi again
whats the script for
if last message = second to last message
if type is always the class name you can just do cls.__name__ fwiw
i cant find it
Using that for the Cache generic
https://gist.github.com/an-dyy/e11fbe63a3871f220b009884e952f97b Heres the full impl
And I know that Cache[type] isn't valid but It was to late when I found that out
it doesn't really make sense to do attrs["__cache__"] = Cache[type](max) # type: ignore
What should I do here?
how do i make a bot delete a duplicate message?
actually you probably want Cacheable[type[Self]]
oh wait no
Ouuh that's really smart. What happens if I do class User(Cacheable, ...)? Is type[Self] User?
Wow perfect, thanks man
class Cacheable(metaclass=CacheableMeta):
__cache__: Cache[type[Self]]``` you want this instead btw
That's what I get for trying to make a strongly typed package without being that good at types
since Self would be an instance of it instead of the class
you can always ask for help in #type-hinting
Actually in this case I wouldn't want type[Self] though right?
As get etc in Cache return an instance or should
Not a type of the class
if the T for self.root is an instance then yeah, just Self
Alright yea sounds good, thanks
👍
could use a dict to store the last message of a user in a channel, not sure what's the best way
if chanel.last_message.content == int(message.content):
await message.delete() ```
i got this prob doesnt make sense 
your making message content a int?
wut
int(message.content)

uhhhh
how can i put the a function on my discord bot to play music?
Hey @dry orbit! I noticed you posted a seemingly valid Discord API token in your message and have removed your message. This means that your token has been compromised. Please change your token immediately at: https://discordapp.com/developers/applications/me
Feel free to re-post it with the token removed. If you believe this was a mistake, please let us know!
import discord
import os
class MyClient(discord.Client):
async def on_ready(self):
print('Logged on as {0}!'.format(self.user))
async def on_message(self, message):
print('Message from {0.author}: {0.content}'.format(message))
if message.content == ';;regras':
await message.channel.send(f'{message.author.name} as regras do servidor são: {os.linesep} 1- não tem regras ksksks {os.linesep} 2- sla só tô testando meu bot sksksksksks {os.linesep} 3- python é legal!')
elif message.content == ';;comandos':
await message.channel.send(f'{message.author.name} Regras: {os.linesep} ;;regras - Vê as regras do bot {os.linesep} ;;nivel - Manda o seu nivél na sua DM')
elif message.content == ';;nivel':
await message.author.send('Nivel 1, mlk mó noob')
else:
pass
client = MyClient()
client.run('meu_tokin')
!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)
Yes and we can't help you
ok
Consider using the commands extension
thanks
Hmm, one issue, but when using this outside of the file where it is implemented it shows Cache[Unkown] rather than the correct type
not too sure, try asking in #type-hinting
iirc Self didn't work well in metaclasses but that might've been changed
why does @ look like an among us character🧍♂️
Nah that aint an among us theme 💀
and its red😭
🆘?
sus
||s||||u||||s||
Hmmm Self is still expiremental right? I think I should just make a strict checker inside of the set method of cache. E.g ```py
def set(self, key: int | str, value: Any) -> None:
if not isinstance(value, self.type_passed_in_constructor):
raise ...
Of course this would mean I get rid of any type errors that would pop up though,
can i use wait for with buttons?
Hey, I'm using py-cord v2.0.0-alpha...
Does self.bot.wait_for('message', check=lambda m: m.author.id==ctx.author.id) not work anymore?
I have a / command, where my bot sends a dm and then waits inside the dms for a message, but somehow wait_for doesn't respond at all and my code "freezes".
Do I have to use something new for this?
I used discord.py before and it worked (well... I didn't use lambda, but it should be the same, except for the checked values)
self.bot is defined right?
Yup.
def __init__(self, bot):
self.bot = bot
does it show that its the bot class?
Yup
same
But thank you for trying ^^
yw ig
Idk If u should use dpy 2.0 since it's not a final product
Like I would be happy if it even would just trhow anything
mine is defined as well but im not sure why its not respoding because its not even printing in the check
I sadly need to for some of it's features
!pypi disnake
you can use disnake
Does it also have full slash and cogs support?
yes
Also discord.Guild.Events?
probably yes
Thank you. I'll take a look
yw
import disnake as discord
My favorite line
no
import disnake as nextcord
is mine
But why
🚪 🏃
Don't run
🏃💨
Fart
Because looks like fart
no

u could , but should not
bad practice
Instead. Install it with the discord namespace
its like doing
import seed as plant
It can work nicely for embeds though
I mean, no.
😠
yes
No, since disnake is a fork of discord literally is almost copy paste dpy
no🚶
Yes
theirs a difference🧍♂️
Well yes
The slash commands and all the new stuff
what if someone has both Disnake and discord installed
But besides that it's the same
its more developed like a plant compared to a seed
There are more additions
me: 🚶
I have both, and have no problem with it
not recommended btw
That was just an example
Doesn't exist on discord
i had it on my laptop but i dont anymore
getch is only for disnake
Yeah that's what in saying
I use pycharm so it's fine
The projects don't inherit the libraries between them
yeah
I use venvs 
i quit pycharm cuz it doesnt support md files
just edit it somewhere else...
I feel more comfortable coding in pycharm tbh
Vs Atom or vscode
i just moved to vsc
Neovim 🙏
Vsc 💩
Vsc bloatware
ive never used atom only pycharm vsc and the idle
On god
uh hey, rq, ik its weird practice but instead of a prefix with "-" or whatever for my bot, I actually just want my bot's prefix to be when someone mentions it... how do I do that? lmao
I keep tryna search it up online and it's just being weird and giving me answers that dont appear to be helpful at all
this is for discord.py btw
coming from a linux guy
when_mentioned
command_prefix = commands.when_mentioned
or you can have both prefixes
ill try it, thanks!
when_mentioned_or("")
Ok and
that will help u with having a normal and mention prefix as well
@slate swan does vsc has the code together feature? Like in Pycharm you can invite someone to code with u in ur project I think that's being done in cloud
you need to hack googles database to just to shutdown your computer
can i make messages send a certain amount of time after the command? (for example the person says !hello and the bot replies hello 5 seconds later)
afaik no
😔
thanks haha
well , vsc has other features like online editor ( https://vscode.dev ) and pretty much of good plugins
Meanwhile you windows users need to do like hella steps to set a PATH variable
I just do export
We are not the same
idc atleast i dont need to make a whole command just to shut my computer off
And yes afaik , u can do multiplayers on vsc cause someone once sent me a link for their vscode project

I can also just push my power off button lmao
or , keep your device running for 48hrs straight like me
imagine
🧍♂️
Windows is an OS worth try ||uninstalling||
||never gonna give you up never gonna let you down||

OMG I love that song
ik you do
Speedrun how fast you can get your data to microsoft data center
1v1 in apex
oh wait.......................

I mean , I won't even use windows ( except for gaming ) once I install linux
the Self pep is still a draft but pyright supports it
you could do that though yeah
since generic metaclasses aren't supported as well afaik
Yea, ended up going with that workaround
As the current behaviour is rather undefined so
Just not worth the trouble to try to make it work
is there a way to make buttons last for like 30 minutes? if so, how?
Buttons last forever, you just need to recieve the interaction
might be more difficult with some libraries tho, I don't really use them much
after a while i get a interaction failed message
||I feel like a button||
I'm gonna click you
I'd throw an error for sure
ill just disable myself😔
seems like you need a rewrite
I'd rate it an F
good one
im going to wait_for the movie
that's where we draw the line lol
😭
Trying to make a command that puts my bot into a state that only i can use the commands.
@bot.event
async def on_message(message):
await bot.process_commands(message)
if bot.test_mode == False:
return
<other on_message actions>
def test_mode(ctx):
if ctx.author.id == 352986404621647873:
return
@bot.command(name='testmode')
@is_owner()
async def test_mode(ctx):
bot.test_mode = True
await ctx.send('`Now in testmode.`')
well according to your on_message override , you are allowing the commands to get processed normally , and other things inside on_message will happen only if test_mode is true
so should i move process commands below the if?
What is disnake
The best A fork of discord.py
nextcord
Why not use hikari
disnake is the only right answer
Just use is_owner deco, that's it...
you mean @commands.is_owner?
same thing
¯_(ツ)_/¯
Yea
@disnake.ext.commands.is_owner()```
A [`check()`](https://docs.disnake.dev/en/latest/ext/commands/api.html#disnake.ext.commands.check "disnake.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://docs.disnake.dev/en/latest/ext/commands/api.html#disnake.ext.commands.Bot.is_owner "disnake.ext.commands.Bot.is_owner").
This check raises a special exception, [`NotOwner`](https://docs.disnake.dev/en/latest/ext/commands/api.html#disnake.ext.commands.NotOwner "disnake.ext.commands.NotOwner") that is derived from [`CheckFailure`](https://docs.disnake.dev/en/latest/ext/commands/api.html#disnake.ext.commands.CheckFailure "disnake.ext.commands.CheckFailure").
I mean im already using that...
i don't see @commands.is_owner anywhere
What im trying to do is make it so the rest of the commands get locked to only me
Bro he's using
o
@is_owner()
Ah
i didnt include this
def is_owner():
async def predicate(ctx):
return ctx.author.id == 352986404621647873
return commands.check(predicate)
Don't
not related
just use the dpy one
!d discord.ext.commands.is_owner is already a check
@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").
thats what i said earlier, i already showed that
Mhm
yeah what are they
Okay...
His wish 🤷♂️
we ain't genies
don't go "whatever works ill use", just improov and never settl
Really easy way to do this is to do a bot check. You can do something like ```py
@bot.check
def foo(ctx: commands.Context) -> bool:
if bot.test_mode is True and ctx.author.id == owner_id:
return True
elif bot.test_mode is False:
return True
return False
I know I told you yesterday about process_commands but now I realise that this is a much better method of doing this
so many elif 😭
What are these role variables?
Like the member, admin, organizer
Can we see the code for those?
so this properly stops all commands again, i 100% am forgetting to do something else with this
What should be changed is the naming of all variables.
None of them follow the Python naming conventions.
that makes sense.
Well you're showing random parts of your code which don't help us to find the issue.
Do you get an error?
What is the full code before and after you've initialized the variables?
Well we still need a better code overview.
How can I make my bot to leave other servers
Hey @hidden hazel!
Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:
• If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)
• If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:
!d discord.Guild.leave
await leave()```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Leaves the guild.
Note
You cannot leave the guild that you own, you must delete it instead via [`delete()`](https://discordpy.readthedocs.io/en/master/api.html#discord.Guild.delete "discord.Guild.delete").
I have to type the command in other server
Can't I just type that command in my server and bot leave other servers
you type the id of the guild and it will leave that guild
lets say I have a yes or no question. How can I make it so if either button is pressed, both get disabled?
I don't have ID BRO NOR I KNOW WHICH GUILD IS MY BOT IN? SO IN JUST WANT MY BOT TO LEAVE ALL SERVERS
delete your bot account
just print all the guild ids
for guild in bot.guilds:
print(guild.id)
for guild in bot.guilds: await guild.leave()
I don't have guild Id bro
Loop through your servers and leave them
Yes you do.
Simple for loop
an extra unnecessary step
How
bot.guilds contains all guilds your bot is in, including IDs.
can someone help me with my question....?
i thought he wanted all the ids
So yes, you do have the IDs.
oh
nah he just wants his bot to leave all servers
just add the coro easy
Can you tell me how can I make invite link from my bot of all guilds in which my bot is in so I can know who invited my bot
.
yep
This is not allowed.
I wanna know
then how will I know who invited my bot
thats just creepy no offense
You don't.
I wanna know because my bot isn't made for public use
Can I have a link to that?
can someone help me with my question....?
I need to check if I'm breaching tos
It doesn't matter, it's backdooring.
Nope bruh
It is
use children[]
Backdooring is not allowed as per the Developers policy.
or a for loop if you have many
So please stop asking about how to do this.
!rule 5
5. Do not provide or request help on projects that may break laws, breach terms of services, or are malicious or inappropriate.
what
There's a "public bot" option in the dev portal or something, enable/disable it and only u will be able to invite the bot
Bruh sometimes you have to do it so you can check the problem
No.
Provide a way to contact you, do not backdoor servers.
As simple as that.
for child in self.children:
self.child.disabled = True
Discord have the access of all accounts in discord? That doesn't mean backdooring
Are you Discord?
they dont lmao
Exactly, no
its discord lmfao
How is that relevant?
what... ive never seen anything like that before
But discord runs in internet. Internet isn't discord
What?

children is a list of components
this dude just trolling now
ikr
so that will disable both of the buttons if 1 is pressed?
Discord runs in google services and google services doesn't allow backdooring but discord does
You're just going off topic trying to prove you're not breaching their terms of service.
yeah it disables all the buttons
@ mods pls ban him
ok
@flint cypress Bottom line is, what you're trying to do breaches tos. You can continue talking about it but that will be against this servers rules and you might be punished
No pls
So please drop the topic before Moderators come all right?
I was just asking doubts
yeah
That's unfair ban
would be a deserved and fair ban
¯_(ツ)_/¯
@tranquil badge
This discord bring a new feature. Add server button that's why
My private bot is added in many servers now 😭
My replit got crashed
Disable the public bot check.
I have to make a new bot again in developer
Make the bot leave all the guilds. Invite it again yourself to needed guilds.
TypeError: decline_reply() missing 1 required positional argument: 'self'
async def decline_reply(interaction, self):
self always goes first
No. It's a simple switch to disable.
kk
Then make your bot leave all guilds using this ^
And invite it again only to the needed servers.
TypeError: decline_reply() missing 1 required positional argument: 'interaction'
its not in a cog
could even exclude the servers you dont want it to leave
or a class
i dont use cogs
then why self
No...
Yes you can, would just be unnecessary as they don't seem to have a lot of knowledge.
cuz i need self for
for child in self.children:
self.child.disabled = True
youll need to subclass view?
children still
If you have the IDs of excluded servers just check before leaving it.
yeah just children
?
if your doing it that way its children without self
so
for child in children:
child.disabled = True
?
yes
for guild in guilds:
if not guild.id in [1234, 4321]: # Ignore servers the bot should be in
await guild.leave()
@bot.command()
async def leave(ctx):
await ctx.send("I am leaving this guild!")
await ctx.guild.leave()
This is ok? But I don't have guild id or server
just use a for loop?
How
Make a loop, and leave all guilds.
Didn't I have to execute that in that particular server
NameError: name 'children' is not defined
Then make the bot private and invite it to needed servers.
@final iron ok so this is fine
It leaves the current guild.
isnt it something like disnake.children or something
Make a for loop and leave all guilds.
Oh
for guild in guilds:
if not guild.id in [1234, 4321]: # Ignore servers the bot should be in
await guild.leave()
idk, im not the one who knows how children work
You said you don't have guild IDs
So under which event should I put this
This is what you need.
On_ready?
NameError: name 'disnake' is not defined
Yes, or make it a command.
K
Have you imported disnake?
no
...
No module named 'disnake'
Replace disnake with discord
basic stuff
ive already imported discord
!e
a = range(1, 10)
b = [str(c) for c in a]
print("\n".join(b))
@slate swan :white_check_mark: Your eval job has completed with return code 0.
001 | 1
002 | 2
003 | 3
004 | 4
005 | 5
006 | 6
007 | 7
008 | 8
009 | 9
make sense
then use it?
NameError: name 'disnake' is not defined
i ment discord
discord.children
AttributeError: module 'discord' has no attribute 'children'
im not sure myself
probably does
It's either ActionRow.children or View.children.
yeah
view.children sounds right
I guess you have a View object yourself.
still dont get why children
So simply go on and use view.children if you do so.
It's always called like that in development.
children is a list of the components
ahh missed that part
AttributeError: 'View' object has no attribute 'child'
for child in view.children:
view.child.disabled = True
discord.ui.View.children maybe
and no need for view.child.disabled just child
AttributeError: type object 'View' has no attribute 'children'
at this point just subclass view🚶
so just child.disabled = True?
yes
Subclassing is hard
no its not
thats why i dont wanna do it
AttributeError: type object 'View' has no attribute 'children'
for child in View.children:
child.disabled = True
no
for child in discord.ui.View.children:
child.disabled = True
It's supposed to be your view object.
Not just the class of discord. It will never work.
let me watch my anime i cant anymore😠
You also never do discord.Member.name, you do ctx.author.name.
If either of you could help, cant find a way to fix it from locking everything
Since ctx.author represents an object of discord.Member.
AttributeError: type object 'View' has no attribute 'children'
for child in discord.ui.View.children:
child.disabled = True
^ @frank tartan
pretty easy when you get a hang of it
;-; i dont think you get it... i dont want the author... i want them to ping someone
im still dumb
how is that supposed to be related to what krypton sent
same here
thats not what i replied to
It's supposed to be your view object.
ok.... how do i fix it?
well it needs the be the view obj
my head hurts
well can i just delete the message instead?
!d disnake.Role.icon
property icon: Optional[disnake.asset.Asset]```
Returns the role’s icon asset, if available.
New in version 2.0.
Pretty sure you could've found it yourself when taking a look at the documentation of the Role class -> https://docs.disnake.dev/en/latest/api.html#disnake.Role
so how can i make it so when someone clicks a button, the message the button is attatched to gets deleted?
elif ctx.author.top_role.id == 855877108055015465:
allowed_channels = [795879613393666048, 795709746501648384, 756552586248585368, 747853054329487500, 747184622386806824]
if ctx.channel.id in allowed_channels:
if channel.overwrites_for(ctx.guild.default_role).send_messages == None or channel.overwrites_for(ctx.guild.default_role).send_messages == True:
await channel.set_permissions(ctx.guild.default_role, send_messages=False)
else:
await ctx.send(f"🔒 Looks like `{channel}` is already locked")
else:
await ctx.send(f"You are not allowed to lock {channel}")
In this part of my code, I want a certain role to be able to unlock only certain channels. However when the user with that role tries unlocking a channel even if its in allowed_channels it still sends you are not allowed to lock ...
Bro one person is banned but I can't find them in discord ban list. How is that possible
Not the place to ask for it
Traceback (most recent call last):
File "/root/6mans/cas_v1.py", line 961, in report
team2_mmr[team2idlist[count]] = get_mmr(team2idlist[count])
File "/root/6mans/cas_v1.py", line 553, in get_mmr
mmr = x["MMR"]
TypeError: 'NoneType' object is not subscriptable```
What have I done 
is x none?
Yea
Yes
They deleted their account?
That could be a reason
Nah. They dm me for unban but I can't find their name
In ban list but they show me link shows banned from server

add


