#discord-bots
1 messages · Page 1109 of 1
we see it
await channel.send(file=discord.File('./images/'+msg.content.split()[1]))
note, if the person only types one word, you get a list index out of range error
on this if statement
ok so how do i prevent that
I'm looking at how the commands get passed the arguments in the dpy source code but damn
there are 4x as many comments as code
this might be it
nop
try-except
I have no idea how it works but it does
oo
Thanks alot
discord/ext/commands/core.py line 798
async def _parse_arguments(self, ctx: Context[BotT]) -> None:```
what about
if msg.content.startswith("!image"):
image = None if len(msg.content.split()) < 2 else msg.content.split()[1]
if image in os.listdir("./images"):
await message.channel.send(file=discord.File(f"./images/{image}"))
else:
#image not found
thanks
it looks complicated af
yeah
just what is this
Can someone help me make a slash command please
bold of you to assume they use dpy
Well I need help making a slash command in 2.0 , I want it to have 2 required options , category1: and category2: when they are finished the send the command and it says your information has successfully been sent to the owner , then the bot DMs you the category1 and category2 , I am on 2.0
Idk I have never made one , I’m new to 2.0
commands.Bot
I already have some stuff with my bot
But idk how to make slash lol
Idk how lol
Ye
So make a new normal command?
I’m confused man sorry
Is this gonna be a slash command
How can i make a ban command what dont delete the message
And do the stuff I mentioned
So what’s the first thing I do ? I’m confused l
an internal mess
Anyone?
lmao
So @.client.command() ?
the message of the banned user gets deleted by default
does this not work?
I've seen people reporting it doesn't work often
Not yet
Ik but client works fine for me
And I only need the bot I’m making atm just for a slash command I’m using it for 1 thing
imao what if i detect alts 💀
how ru gonna do that
like some bots like anti alt or smthin do that 💀
how to make a sql db xd
Yes guild specific , much better
~~ ~~
Ohk
how to cut in middle of words like this message?
like the cut sign
~~hi~~
But i don't think the channel is right for asking it
:blobpain:
I think this is the exact channel you should ask this in
ew
I don’t see the YOUR_GUILD_ID
yikes
Ok so I paste then then What?
Should I grab that code at the top and test the command
@client.tree.command()
async def your_slash_command(interaction: discord.Interaction):
await interaction.response.send_message("test")
This.
Ok sync is at the top and the command below ? Or the orders don’t matter
gigacat or meh(brain="huge", looks=model) i could use some help again :/
any way to implement invenotry command with json
Ok
I apologize but I'm in an important meeting rn (and sorry for the late reply)
like no offence using db is better, but for now i want to use json
||JSON||
Yes
is it meant to look like this?
How do i make it so if i only type !image it will send a list of every image in that directory
@client.event
async def on_message(msg):
if msg.content.startswith("!image"):
image = None if len(msg.content.split()) < 2 else msg.content.split()[1]
if image in os.listdir("./images"):
embed=discord.Embed(title=image, url="", description="Loading...", color=0x4ccfb2)
await channel.send(embed=embed)
await channel.send(file=discord.File(f"./images/{image}"))
else:
return
#image not found
when the fuck did i say that
the _sync looks kinda dark
Maybe When You were dreaming
I ran sync and nothing happened
So like this after "else:" ??
embed=discord.Embed(title="Images In ./images", url="", description=os.listdir("./images").replace(',', ' '), color=0x4ccfb2)
await channel.send(embed=embed)
How to split the embed content
Ok
Use the command framework that dpy offers for commands, not the on_message event
doesn't want to work for me :/
What happens when you try? You must be doing something wrong. If you provide the error we can help
that doesn't send anything when executing !image
if msg.content.startswith("!image"):
image = None if len(msg.content.split()) < 2 else msg.content.split()[1]
if image in os.listdir("./images"):
embed=discord.Embed(title=image, url="", description="Loading...", color=0x4ccfb2)
await channel.send(embed=embed)
await channel.send(file=discord.File(f"./images/{image}"))
else:
files = [discord.File(f"./images/{image}") for image in os.listdir("./images")]
await channel.send(files=files)
you did not even define channel
i saw the code
look at the attributes of the text channel class below and use what you want in the embed
!d discord.TextChannel
class discord.TextChannel```
Represents a Discord guild text channel.
x == y Checks if two channels are equal.
x != y Checks if two channels are not equal.
hash(x) Returns the channel’s hash.
str(x) Returns the channel’s name.
@client.event
async def on_message(msg):
channel = msg.channel
if msg.content.startswith("!image"):
image = None if len(msg.content.split()) < 2 else msg.content.split()[1]
if image in os.listdir("./images"):
embed=discord.Embed(title=image, url="", description="Loading...", color=0x4ccfb2)
await channel.send(embed=embed)
await channel.send(file=discord.File(f"./images/{image}"))
else:
files = [discord.File(f"./images/{image}") for image in os.listdir("./images")]
await msg.channel.send(files=files)
What?
okok 1 sec
again, I recommend you to use the command extension instead of on_message event. It's an easy conversion
sooo that is a problem damn
yeah so if there is more then 10 it will send more messages
hmm my command doesnt seem to show
and i did to from discord import app_commands
so from discord import ...?
ok im gonna try
Hi
my command still hasnt loaded
I need a help with my python discord bot
import discord
client = discord.Client()
variavel = "!"
@client.event
async def on_ready():
return
@client.event
async def on_message(message):
content = message.content
channel = message.channel
if content == variavel + "help":
await channel.send(":emoji_2: Olá, me chamo Nexux, sou o bot oficial do servidor Several Operations, sirvo para auxiliar todos os moderadores e administradores a controlarem o servidor!")
wait does this send the whole image or just the name?
files = [discord.File(f"./images/{image}") for image in os.listdir("./images")]
await msg.channel.send(files=files)
Send a list of image Names
that could be something like this await msg.channel.send('os.listdir("./images")')
lmaoo
it just spammed me images lol
But who cares
im sorry :(
Yes it works
oh yeah btw do you know how to send a image using embed, i cant figure out how it works
!d discord.File
class discord.File(fp, filename=None, *, spoiler=..., description=None)```
A parameter object used for [`abc.Messageable.send()`](https://discordpy.readthedocs.io/en/latest/api.html#discord.abc.Messageable.send "discord.abc.Messageable.send") for sending file objects.
Note
File objects are single use and are not meant to be reused in multiple [`abc.Messageable.send()`](https://discordpy.readthedocs.io/en/latest/api.html#discord.abc.Messageable.send "discord.abc.Messageable.send")s.
Exists
class discord.Embed(*, colour=None, color=None, title=None, type='rich', url=None, description=None, 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.
For ease of use, all parameters that expect a [`str`](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") are implicitly casted to [`str`](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") for you.
Changed in version 2.0: `Embed.Empty` has been removed in favour of `None`.
Its an Attachments as i know or maybe i am dumb
sooooo set_image=discord.File("image")
Noo
What about converting the files to attachment?
.
Look await ctx.reply
The file sent through the bot converts to attachment
embed.set_image only supports http/https. You have to pass a URL (string)
It is in the embed only
What about me? It works fine for me
ah
He may now learn something new good idea
embed=discord.Embed(title=image, url="", description="Loading...", color=0x4ccfb2)
await channel.send(embed=embed)
await channel.send(file=discord.File(f"./images/{image}"))
what?
how... what?
No
Seems like you reached at starting point again
Simple Dpy
not for my stupid head :/
Btw I invited the bot with application commands so I know the permissions are correct!
Why sending the image normally you asked to send it in embed
Local File To Attachment
well it didn't like that 0_0
Show where you defined embed = ..
No
oh im dumb
any good places to host discord bots? (discord.py)
🥲
im using railway.app
Everyone host is good for me except Replit
any suggestion?
What about vps?
good idea
embed=discord.Embed(title=image, url="", description="Loading...", color=0x4ccfb2)
f = discord.File(f"./images/{image}", filename="image.png")
embed = discord.Embed(...)
embed.set_image(url="attachment://image.png")
await channel.send(file=f, embed=embed)
like that?
(i use replit before
):
Replit hacker edition or whatever it’s called is gud for hosting
u have option to have always on
Try removing url
why is replit bad
It uses shared ip and ur bot can get rate limited easily
good reason
i just realised that yesterday so i dont use it anymore
Also ur files aren't safe anyone can see them, tho u can secure tokens and all
@slim heart ^
embed=discord.Embed(title=image, description="Loading...", color=0x4ccfb2)
f = discord.File(f"./images/{image}", filename="image.png")
embed = discord.Embed(...)
embed.set_image(url="attachment://image.png")
await channel.send(file=f, embed=embed)
f = discord.File(f"./images/{image}", filename="image.png")
embed = discord.Embed()
embed.set_image(url="attachment://image.png")
await channel.send(file=f, embed=embed) ```
You defined two embeds
I did?
Raven's paragraph is soo helpfull
Ofc
ya lmao
I didn't saw it firstly
That worked but how do i set a title?
!d discord.Embed
class discord.Embed(*, colour=None, color=None, title=None, type='rich', url=None, description=None, 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.
For ease of use, all parameters that expect a [`str`](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") are implicitly casted to [`str`](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.10)") for you.
Changed in version 2.0: `Embed.Empty` has been removed in favour of `None`.
ok
Title = image huh?
~Deving~
Deving
💀
Lemmie delete my discord
Alr
😂Sorry for bad jokes
WoW
Getting started
you just test out your bot and then deploy it to your vps lol
Leme find raven's paragraph real quick
He doesn't have vps
||So what do you think you are on replit for||
show him 🔫 if he replies back
😂This is python server not something like shooting
Lol
im part of the pydis mafia, we smuggle python scripts 😎
U don't know this channel 😂
||But who cares||
😳
Ig they hack nasa
With html
🔫 🔫
Nasa's secreat algorithms especially
Ded chat 😔
thats always the problem
Sad lyf
i just killed the chat😳
@slate swan
and user.name != "Sparky"
😐
STOP DANCING AND REVIVE THE CHAT
dances on the grave
hey, I need help with choosing permissions for my bot. can someone join my testing server and help me with that?
tried few combinations but I didn't get it
you would need to test that yourself, so you know which permissions should/would be used
Nope
what's the issue?
But i pinged @slate swan
kek
embed = discord.Embed(title = "Giveaway!", description = f"{prize}", color = ctx.author.color)
how do you do so that its not the authors color and it's a color i can choose?
Command doesn’t show
can I see the code?
color=0xhexcode
hex?
discord.Colour.random()
imagine
gives some inbuilt colors
"colour i choose"
But who cares he want the color of his own
is there a website with all discord color commands?
Commands?
Codes*
ur question should be website with all colour hexcodes
Hexcodes*
yeah so go online type colour hexvalues there are plenty of websites which offer those services
thanks
Hexcolorcodes*
integers
just type colour picker easy peasy
embed = discord.Embed(title = "Giveaway!", description = f"{prize}", color = 0x#7289DA)```
why is it a problem "(" was not closed ?
HexColourCode
If u scroll up I legit did exactly what the guy said
Dont use #
why did u comment it?
?
thanks
👀
embed = discord.Embed(title = "Giveaway!", description = f"{prize}", color = 0x7289DA)
um, tag me maybe?
# makes a comment, anything in front of that is ignored by the compiler
ahh thank you
uwu

Ryuga



you can also use ```py
color = discord.Color.from_rgb(r, g,b)
rgb sounds easier than hexa colors
if ctx.message.attachments:
print('There's an attachement in this message')
This doesn't work for some reason, without returning an error. Someone might help me? :D
hex is easier cause you can get it from discord itself lol
For us it is hard when we can simply use
thanks so r = red b = blue?
"There's an attachement in this message"
really? I found it confusing at the beginning
Oh
'There\'s an attachement in this message'
Or
"There's an attachement in this message"
yes and g = green
you need 3 numbers to make a color
a hex might be easier to use ngl
if you go to the settings of a role and try to change color of it, you will see a complete table of colors with its hex you can choose from
I wanted to use random colors so hexa was hard for me
where in rgb I just made 3 random numbers
!d discord.Color.random 🤡
No documentation found for the requested symbol.
!d discord.Colour.random 🤡
classmethod random(*, seed=None)```
A factory method that returns a [`Colour`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Colour "discord.Colour") with a random hue.
Note
The random algorithm works by choosing a colour with a random hue but with maxed out saturation and value.
New in version 1.6.
https://www.computerhope.com/htmcolor.htm just scrape one of these sites and get all colours name and colours
oh yes indeed, but the message is just an example, it's still not working i mean
Imagine - Using hard ways for easier things
@slate swan around here
just use sarthak's json file (from anya) easy
british ppl pissed by seeing color
idk if its my luck or something i never got more than 10 diff colours using that
like, if list: is False when the list is empty right?? :o
oh well then it means the message does not have an attachment or you dont have message contents enabled
totally me
yes, but when I put an attachment it doesn't print anything see?
ya pretty much
so that condition somehow isn't working :o
Imagining Your Code Is So Hard
wdym not working?
send ur code of the command
random.randint(0,16777215)
mhm but its still good to have a color dict
Wow Sarth Python will Love You after this 
try adding a client.tree.copy_global_to(guild=discord.Object(id=...)) to the sync command
Basically I coded a while true loop that checks the answer and returns an error, and rechecks again.
elif urls or ctx.message.attachments:
await ctx.send('Images aren\'t allowed in reasons, keep that for later.')
continue
And I wanna make sure there isn't any url or image in the message with this.
But it isn't even entering that condition when I write an empty message with an attachment :o
is this an on message event?
its in an elif, so maybe the if above that is true
mmmh no it's a @bot.command()
ohhhhhh wait !
Wait what?
mmmmh no it's not the case
if its a bot command how du send an empty message with an attachment
Here's the whole function:
async def select_reason(ctx, bot):
print(ctx.message.attachments)
while True:
await ctx.send(bot_message)
def check(m):
return m.author == ctx.author
msg = await bot.wait_for('message', check=check)
urls = [x.group() for x in re.finditer(r'{0}'.format(links_regex), msg.content, re.S | re.I | re.M)]
if msg.content.lower() == cancel:
return False
elif msg.content.lower() == 'n':
return None
elif urls or ctx.message.attachments:
await ctx.send('Images aren\'t allowed in reasons, keep that for later.')
continue
elif len(msg.content) > 1999:
await ctx.send('Message is too long. Max lenght should be 2000 characters.')
continue
else:
return msg.content
So you get the whole process 😊
shouldnt it be <prefix><command_name> attachment
You are trying to track message simply use on_message
also why pass bot in parameter?
ohhhhh !!!!!!!!
I'm checking the wrong message indeed !
I'm so stupid thank youuuu !
I'm checking the original message that triggered the whole questionnaire, but i needed the message for that specific question ! :D
so should be msg.attachments instead of ctx.message.attachments !
ic
but if u want to check for attachments and urls better to do in a listner or on_message event
Idk
?
I doubt that will work
try it first atleast
Ok
I mean if you don't even try it and doubt it, then you should be able to fix the issue by yourself ¯_(ツ)_/¯
Traceback (most recent call last):
discord.ext.commands.errors.MaxConcurrencyReached: Too many people are using this command. It can only be used 1 time per user concurrently.
How can I capture this event so I can send a message like "Command is already running"?
Should it be:
try:
await my_command(ctx)
except MaxConcurrencyReached:
await ctx.send('Already running')
?
Indeed, I should have check that on stackoverflow before asking here I apologize
I think I'm beeing too greedy on your kind help. I'll make efforts to search myself before asking here 
👍
Because when I googled "how to handle concurrency error on command discord.py" the first answer was a detailed answer with explainations and code answer...
So I shouldn't bother you guys when there's an answer ready on google...
can i send a button without adding a label to it ???
Emoji buttons yeah
how exactly ?
You can pass in an emoji and ignore the label kwarg altogether
There should be examples on the GitHub page
ah alr ty
how would it be done ?
good morning, i might have broken something with my bot, he doesnt post to discord when i go live on twitch anymore.. but i havent touched anything.. i just havent streamed in a while.. would anyone be interested in spending a quick 5 minutes and check if my code is sound
ok so how can i do this ? my bot mentions the ctx.author i just need to know how to do it for the new member who joined
you can do ctx.author.name and it will drop the #0757
on_member_join event
ik that...the bot sends a greeting msg and all but not able to ping the person who joined...
the on_interaction event is separate..
says member not defined
send ur code?
@commands.Cog.listener()
async def on_member_join(self, member):
memberop = on_member_join
welcome = discord.Embed(title= "'•.¸♡ helllooo ♡¸.•'", color=0xE6E6FA, description=f"Welcome To the server {member.name} !!! \n Please Read all the Rules listed in [#935914067057578056](/guild/267624335836053506/channel/935914067057578056/) \n Make Sure to get your self-roles in [#935915930368753694](/guild/267624335836053506/channel/935915930368753694/) \n We also have great profile-colors so make sure to check those too [#936976679908298862](/guild/267624335836053506/channel/936976679908298862/)")
welcome.set_image(url="https://media3.giphy.com/media/Ulyubf7eYczLO/giphy.gif?cid=790b761197ac7ec60a21ee41ce9122d24380d159e69aded2&rid=giphy.gif&ct=g")
wel = self.bot.get_emoji(979772837701242931)
welcomer = [
create_actionrow(
create_button(style=ButtonStyle.grey,
custom_id="welcomes",
emoji=wel),
)]
await self.bot.get_channel(933980949421621279).send(f" <@&953549791265185832> {member.mention}")
await self.bot.get_channel(933980949421621279).send(embed=welcome,components=welcomer)
Homies = 934391119041687593
await self.bot.get_channel(935913776379752448).send(f":GreenRight: __*{member.name}*__ has joined")
@commands.Cog.listener()
async def on_component(self, ctx: ComponentContext):
if ctx.custom_id == 'welcomes':
await ctx.send(f"{ctx.author.mention} Welcomes You !!")
discord-components?
yes
async def verify(ctx,message):
guild = ctx.guild
role = guild.get_role(985205310740389918)
await ctx.author.add_roles(role)
await message.delete()
await message.channel.send(f'{message.author.mention}you are now verified', delete_after=3)``` why isnt this working?
@bot.command(name='add')
@commands.max_concurrency(number=1, per=commands.BucketType.user, wait=False)
async def cmd_add(ctx):
await cmd.add_report(ctx, bot)
@bot.event
async def on_command_error(ctx,error):
await ctx.message.delete()
if isinstance(error, commands.MaxConcurrencyReached):
await ctx.send(f'You already started a `{ctx.command}` command. Please finish it before running another one.')
return
I'm using this for a command, it should prevent someone from running the command while it's still running from that same person.
However it's not fully working. The error message is being sent to the channel AFTER the cmd_add(ctx) function has rerunned which is not what I want. It'd like it NOT TO RUN, and the error message show.
Oh actually, I missexplained the issue
bot.get_role()
what?
That's a thing?
not guild.get_role()
get_role(role_id, /)```
Returns a role with the given ID.
Changed in version 2.0: `role_id` parameter is now positional-only.
The issue is:
my on_command_error() makes cmd_add() rerun (a.k.a ends the previous one and start the new one). However i'd like it to not start the second one and let the first. How can I do it?
^^?
bit cache
i don't use components much but i don't see anything wrong with the mention part but ur indents are a bit off
But that method doesn't exist
alr
async def verify(ctx,member: nextcord.Member,message):
role = ctx.guild.get_role(985205310740389918)
await member.add_roles(role)
await message.delete()
await message.channel.send(f'{message.author.mention}you are now verified', delete_after=3)``` why isnt this working?
ic i remeber wrong then
Ok I'll explain my issue better:
I have a command that I want to restrict concurrency uses per user to 1. So I used this:
@bot.event
async def on_command_error(ctx,error):
if isinstance(error, commands.MaxConcurrencyReached):
await ctx.send(f'You already started a `{ctx.command}` command. Please finish it before running another one.')
return
I expected it to keep running a command and block any use of it while it's running.
But this code just stops the current command and starts the new use of it which is not what I want.
Shall someone please explain me what should I do?
is commands.MaxConcurrencyReached set to 1? im not saying this is the problem, im not knowledgeable.. but it seems like this should be set to an integer
Bucketype.default try with this
also set wait=True
class Transfermoneybuttons(discord.ui.View):
def __init__(self, amount, author, *, timeout=180):
super().__init__(timeout=timeout)
self.amount = amount
self.author = author
@discord.ui.button(label="-"+self.amount+moneycurrency,style=discord.ButtonStyle.green)
async def gray_button(self,interaction:discord.Interaction,button:discord.ui.Button):
Traceback (most recent call last):
File "C:\Users\lequi\Desktop\Hint Bot\hinttest.py", line 51, in <module>
class Transfermoneybuttons(discord.ui.View):
File "C:\Users\lequi\Desktop\Hint Bot\hinttest.py", line 63, in Transfermoneybuttons
@discord.ui.button(label="-"+self.amount+moneycurrency,style=discord.ButtonStyle.green)
NameError: name 'self' is not defined
Is there another define the variable because this way doesn't work.
What is this exactly? I want to restrict to one per user, not one in general tho
ok then just change wait=False to True
guys context = ctx?
Yes
im so newbie on here
indents
ui button in the class
thank youuu
Thank youuuuuuu 
What exactly do you mean by that?
Isnt it already in the class?
it isn't u have to put it on same indent level as init
check the button examples in the docs
indent it with your def that says self..
Yes but that removes the buttons
So if i indent it in the same indentlevel it outputs no buttons
Okay so now It's working as expected in terms of restriction, but it's not raising an error anymore, means I can't capture this part:
@bot.event
async def on_command_error(ctx,error):
if isinstance(error, commands.MaxConcurrencyReached):
await ctx.send(f'You already started a `{ctx.command}` command. Please finish it before running another one.')
return
There should be a way... Is there something like on_command_max_concurrency() for example?
like press the spacebar 4 times or a tab
Lol
Yes i know
What do u want
I did bro, But it doesnt show the buttons then
then that's a problem with ur code
What's the issue
You mean me?
If ur having issue yes
So i basically need the self.amount to work in the discord.ui.button as a label but it says that the variable isn't defined
add an else and see what error it gives now
Okay but how i can make it work?
i haven't used concurrecy b4 since point of discord is async i havent need it till now
Wait
Tried even with just
async def on_command_error(ctx,error):
await ctx.send(f'You already started a `{ctx.command}` command. Please finish it before running another one.')
still not working D:
with the wait=True it seems not considering it like an error,
yeah that's prolly the case
just make a custom handler
make a list add the user there on usage and remove when done
and handle the list
smart
yeah wait = True makes a queue
and runs them one by one
i generally make my own handlers for stuff like this allows me to keep a log for myself
not really !
It doesn't even do that
I'm confused
Copy/paste this reproduce example please:
@bot.command(name='test')
@commands.max_concurrency(number=1, per=commands.BucketType.user, wait=True)
async def cmd_sleep(ctx):
print('Started')
await asyncio.sleep(5)
print('Ended')
@bot.event
async def on_command_error(ctx,error):
print('Error handled !')
run the command two times in a row and see
i am on phone💀
XD
Ok smort ! lemme try this
yeah wait = True won't return an error
it makes a queue it seems
just make a custom handler in the worst case
@uncut jacinth so u do something like this
class ok(discord.ui.View):
def __init__(self):
super().__init__(timeout=30)
self.clear_items()
self.p()
def p(self):
self.but1.label = "ur var"
self.add_item(self.but1)
@discord.ui.button(label="hi", style=ButtonStyle.red)
...
but can someone suggest a command which needs to be run only by one person at a time
i can't think of anything
Slash command?
Isnt there something like server cooldown?
no i mean what type of command like ping/8ball etc what command feature i mean
There thankfull but this is not what i needed, + Never spoonfeed first try to explain
🥴
Ok so this is working fine for error handling ! :D
However these freezes the global use of that command... I want to freeze it just for the person that used the command u get it?
But thanks i appreciate that <3
I'm on mobile u don't know how i struggle to type that u expect to explain 😭
🫂
Nah its ok thank you
Ohhhh , commands.BucketType.user can be used for cooldown !
That's amazing thank you @shrewd apex ! !!
np u figured it out by urself👍
Almost 6 hours power cut here
u might want to take a look at the dpy buttons example docs
does this look right
Nah bro i already know how to pass in variables
that will help u narrow down to the problem and make it easier for us to explain or where to start from
There isnt anything written about how to use them outside a function
u can just create the button in a command too
subclassing it isn't the only way to make a button
does this look right someone
just more structured and good looking way
Thats what i searched for for hours
But anyway
Do you know how to use the argument outside the function?
async def comm....
view = View()
button = Button()
async def button_callback....
button.callback = button_callback
view.add_item(button)
await ctx.send(view=view)
i don't get wym
view class is way better
yeah but sometimes i only need like one button should I make a class for that too?
just too lazy sometimes
can somebody please help me....
So that was what you ment?
Do messages in threads get dispatched in older versions of the api?
Wait
I need to get the var from
@client.command()
async def transfer(ctx, amount: int):
await ctx.send("This message has buttons!",view=Transfermoneybuttons(amount, ctx.author))
this seems fine but whats moneycurrency
Money currency is working
Its just a variable for "$"
oh ic
So if i want i can change it to example "§"
also u don't need the extra *
Yeah u just pass it Normally
Ye i did
Traceback (most recent call last):
File "C:\Users\lequi\Desktop\Hint Bot\hinttest.py", line 51, in <module>
class Transfermoneybuttons(discord.ui.View):
File "C:\Users\lequi\Desktop\Hint Bot\hinttest.py", line 63, in Transfermoneybuttons
@discord.ui.button(label="-"+self.amount+moneycurrency,style=discord.ButtonStyle.green)
NameError: name 'self' is not defined
No i self.moneycurrency isnt working
Thats the problem
It says its not defined
Then like put it init and define it like self.something = something
Bro, If i like put the self.amount in the button it says the ammount but if i put it outside the function it says its not defined
And i need to fix it
remove the super and try once
Listen
Still not workin
Yes
thats not how OOP works
Ye 😭
Ok
@uncut jacinth use like this
And the but1 will be ur callback method name
@shrewd apex can u help me
i haven't used slash commands so i am inexperienced in that regard
@slate swan u seem like a pro lmao
hmmm
No 💀
someone who knows about slash commands dpy 2.0
I don't use slah commands.. M
@warped mirage I had the same issue as you, even my slash commands with dpy arent showing up for some reason
Seems like a bug
move thr global_to line above sync and remove the guild kwarg from sync, then wait for an hour, mine showed up that way
im so confused
have a good sleep, take care
you can just do it with ```py
class Foo(ui.Button):
def init(self, *args, **kwargs):
# stuff here
super().init(label=self.whatever)
async def callback (self, inter: Interaction):
...
class Bar(ui.View):
def init(self, *args, **kwargs):
self.add_item(Foo(arguments))
😭 6 hours power cut
gn
No it happens occasionally like it heavily rained
you missed a closing bracket for add_item
Bro im confused
my apartment has a generator luckily
no comments, it rains here like 5 days a week
done btw since the commands take 1 hour to show can u help me do my command so that i can wait less
thanks for correcting me :D
how experienced are you with OOP and reading the docs?
I might go offline in between, so I uhhh might just be out
the command isnt that hard i guess
I have experience with bots but not with oop never used it i dont even know what it is
I just want an argument to be usable outside thie function
Buttons so complicated
i need 2 options , category1: category2: it sends " your message has been sent to the owner" in dms the bot sends u category1 and category2 , i really need this
you can't access self anywhere outside a method.
But is there a way to make another argument with the same int
I also have an invertor
recommended to learn OOP since that's what discord.py, and actually everything in python is based on
Problem is this can get really messy and cause some not so great code
i just showed you how to.
anyone?
I dont understand what is callback for and foo
!d discord.ui.Button.callback
await callback(interaction)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
The callback associated with this UI item.
This can be overridden by subclasses.
basically the function you make under @ui.button
nais why power cut then?
Ohh okay
invertor failed
def foo(self): global self
I hate myself for that now
sed
Im very thankfull for your guys help, But i dont understand it so i gonna leave it like it is
Thanks <3
would making a class variable and passing it in that make that available?
self is the instance, so thats pointless
i wish i could unsee this
I know thats why I wrote it dw
i didnt even read the second line, python interpreter moment
lmao
No 💀
charge over?
No it will go like 6-10 h more
Indian parents have a tendency to make you switch off all the electronics when there's no electricity even when the invertor can carry on 
that might be his case
Lol
Ye
well not in my case the phew😔
U live in apartment cuz
the Anya emoji tho lmao
yes 😌
Battery also ded mobile*
Can someone help me make slash command , I made most now I need the actual command function
sed
ew, change parents, be my kid instead
no power bank?
Nah
oof
Rly I don't need them
Someone lmao
i need 2 options , category1: category2: it sends " your message has been sent to the owner" in dms the bot sends u category1 and category2 , i really need this
I don't need powerbanks I just get a charged phone 💀
need*
Get
@client.tree.command()
async def uwu(inter, category1, category2):
...```
then send them
I have like 3 device I just switch if one battery low
3 phones👀
They must be required and stuff bruh
well just reminded my phone needs an update
too lazy to write it all
gn
Gn
gn
Lol the mobile got auto switched off when I said gn
it's a smort phone
💀 what u think I was using dc on keypad?
dc?
Discord
That's not my personal mobile it's most like a landline phone
Everyone just uses it for calls
Forget slash commands , can u just make me a command
Lol
So the full command will be , /send category1: category2: , both of these options are required , then bot says in ephemeral mode , your message has been sent!
The bot dms u the category1 and category2 , makes sense ?
y not just add checks for the the category 1 and 2
@client.tree.command()
async def send(inter: discord.Interaction, category1: str, category2: str):
await inter.response.defer(ephemeral=True)
user = bot.get_user(_id) or await bot.fetch_user(_id)
await user.send(content=f"category one: {category1}\n{category2}")
await inter.edit_original_message(content="Sent the message to whoever, now fuck off")
welcome
from what i see in docs application commands has a bool for dm permissions
ew
btw how do i set it so it only sends it to a specific user
that does it
user = bot.get_user(_id) or await bot.fetch_user(_id)\
why edit_original_message
atleast she typed💀
someone help me fix the rest
do it urself no spoon feeding
what rest
i never asked ?
i asked for help , not to write it
💀
@client.tree.command()
async def send(inter: discord.Interaction, category1: str, category2: str):
await inter.response.defer(ephemeral=True)
user = client.get_user(_id) or await client.fetch_user(_id)
await user.send(content=f"category one: {category1}\n{category2}")
await inter.edit_original_message(content="Sent the message to the owner")```
okay lmao u didnt write a single line of code till now or run it till now u are just asking what u want
the id of the person you want to send the message to
ok

cz im deferring the response, welcome
mm no
okay bye im going to watch batman
yeah inter
mm still no
have fun
you too
why would he want to get user from interaction.user.id
@client.command(name="sync")
async def _sync(ctx: commands.Context):
client.tree.copy_global_to(guild=944574010828652544)
await client.tree.sync()``` will this work?
how no? interaction has user attribute
that's just interaction.user
yeah
ic
no idea what you did with that
so from interaction.data?
ashley told me to remove 2 lines and add
why not just do await client.tree.sync(guild=discord.Object(id=....))
thats what i did
but what's copy_global_to
new denial ^
!d discord.app_commands.CommandTree
class discord.app_commands.CommandTree(client, *, fallback_to_global=True)```
Represents a container that holds application command information.
user = client.get_user(944343972258648115) or await client.fetch_user(944343972258648115)``` would this work?
why did they use the term app and not application lol
yeah that i got but how do u check in slash commands then?
yes
check what
btw how can I do it so that both of the options are required
who invoked the command
interaction.user
then am i not telling that from the start🥲
but _id wasn't supposed to be inter.user.id
i was just telling if u want to send to the user who invoked
they are by default
what are they trying to do? an owner only slash command?
dm who ran the slash the command
and another person
just inter.user.send bruh

I'm now struggling to see what's the issue
nothing now i think
@client.tree.command()
async def send(inter: discord.Interaction, Email: str, Password: str):
await inter.response.defer(ephemeral=True)
user = client.get_user(944343972258648115) or await client.fetch_user(944343972258648115)
await user.send(content=f"Email: {Email}, Password: {Password}")
await inter.edit_original_message(content="Sent the Email\nPassword to the owner")``` if this works then im set
what is this
its my commands
sus
its for a game , it requires alot of accounts , my mates will be donating tons 😉
its the best
cant ur friend just dm directly?
i cba lol
its email ids and pass from what i figured
btw will my slash commands auto appear or do i have to restart bot to see
import class_eco_work
Dear, tell me what could be the problem? In another file, I simply copied the classes, variables and imports.
class eco_work(commands.Cog):
def __init__(self, client: discord.Client):
self.client = client
@commands.command(aliases = ["Вакансии", "вакансии"])
async def vacancies(self, ctx: commands.Context):
embed = discord.Embed(
color= 0x2c75ff
)
file = discord.File("./ImageO/Экономика/Work/Выбери Профессию.png", filename="image.png")
embed.set_image(url='attachment://image.png')
await ctx.send(file = file, embed = embed, view=vacancies(ctx.author.id))
view= needs to be passed an instance of discord.ui.View, not a command
ah naming conflicts huh
pep8 is probably the least of their problems at the moment
pep8 would've made the class be Vacancies
no naming convention already
still confusing
but python gets it 
Im feeling kinda dumb:/
Here is the error, but I don't understand what to send so you can help deal with the error
import class_eco_work
await ctx.send(file = file, embed = embed, view=class_eco_work.class_vacancies(ctx.author.id))
Tyy bro<3
how do i break a while loop command by a diff command?
set the condition as a bot var, run the while loop while the condition is true, set condition to false in a different command
what's the use case, if I may ask?
!p discord.ui.View
Converting to "int" failed for parameter "pep_number".
Converting to "int" failed for parameter "pep_number".
!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.
oh thanks
file eco_work
import class_eco_work
class eco_work(commands.Cog):
def __init__(self, client: discord.Client):
self.client = client
@commands.command(aliases = ["Вакансии", "вакансии"])
async def command_vacancies(self, ctx: commands.Context):
await ctx.send(view=class_eco_work.class_vacancies(ctx.author.id))
file class_eco_work
class class_vacancies(discord.ui.View):
def __init__(self, id):
super().__init__()
self.id = id
@discord.ui.button( label = "123", style=discord.ButtonStyle.secondary, row=1, disabled=True)
async def title1(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.edit_message(view=self)
Please tell me why when you turn on the bot gives an error?
you probably didn't switch to the directory where the script is
where are these files
They are all in the same folder.
yes
class CounterBot(commands.Bot):
def __init__(self):
intents = discord.Intents.default()
intents.message_content = True
super().__init__(command_prefix=commands.when_mentioned_or('.'), intents=intents)
async def start(self, *args, **kwargs):
await self.load_extension('cogs.mod')
await self.load_extension('cogs.eco_work')
await self.load_extension('cogs.class_eco_work')
await super().start(*args, **kwargs)
there is also
if str(ctx.author) != str(user):
guilds = ' \n'.join([str(x.id) for x in user.mutual_guilds])
This returns the mutual server of user and bot, but I want to to return mutual servers for user and ctx.author
any idea?
your bot cannot see all guilds of a member
you can only show the guilds where all 3 of them are in
but not where user and ctx.author are and the bot isn't
so it's impossible
I see.... okie thank you
hello!
i made a discord bot but whenever i execute a command it sends it twice
any reason?
oh
which I doubt
i have a on_ready
ok
don't change presence in on_ready
Don't change_presence (or make API calls) in on_ready within your Bot or Client.
Discord has a high chance to completely disconnect you during the READY or GUILD_CREATE events (1006 close code) and there is nothing you can do to prevent it.
Instead set the activity and status kwargs in the constructor of these Classes.
bot = commands.Bot(command_prefix="!", activity=..., status=...)
As noted in the docs, on_ready is also triggered multiple times, not just once.
Basically: don't 👏 do 👏 shit 👏 in 👏 on_ready.
ah
okay, thank you
"there is nothing you can do to prevent it"
what a joke, lemme heck discord real quick
Bruh my slash command still hasn’t came
ctx.message.content prints message content including the command.
any cool way to print the message content without the command, and without something like ' '.join(ctx.message.content.split(' ')[1:]) ?
class discord.ext.commands.Context(*, message, bot, view, args=..., kwargs=..., prefix=None, command=None, invoked_with=None, invoked_parents=..., invoked_subcommand=None, ...)```
Represents the context in which a command is being invoked under.
This class contains a lot of meta data to help you understand more about the invocation context. This class is not created manually and is instead passed around to commands as the first parameter.
This class implements the [`Messageable`](https://discordpy.readthedocs.io/en/latest/api.html#discord.abc.Messageable "discord.abc.Messageable") ABC.
just print the command parents then
Damn
now the copy globals was removed
yeah I said to use copy_to_global which contains the Object
then sync it without any kwargs provded
but okay ¯\_(ツ)_/¯
idc
bruh it returned crappy errors
and some other dude said remove it
can I see what you did?
send me the code again and ill do it
okay then let them help, ignore me
bruh...
i tried ur code and it returned errors so i asked for help and some dude said its not required
happy now
no, im not
move the global_to func above sync and remove everything out of sync's paranthesis so that it's just ...tree.sync()
now what should i do?
now run the code and wait for some time
ok
like 10-15 minutes or so, if the slashes sill dont appear, then reload the client (your discord)
that solution worked for me
Ignoring exception in command sync:
Traceback (most recent call last):
File "C:\Users\Dom\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 200, in wrapped ret = await coro(*args, **kwargs)
File "C:\Users\Dom\Desktop\ZEEFUT UTILITIES\main.py", line 36, in _sync
await client.tree.sync()
File "C:\Users\Dom\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\app_commands\tree.py", line 946, in sync
data = await self._http.bulk_upsert_global_commands(self.client.application_id, payload=payload)
File "C:\Users\Dom\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\http.py", line 502, in request
raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In 0.options.0.name: Command name is invalid
In 0.options.1.name: Command name is invalid```
i only have one
show the name
@client.tree.command()
async def send(inter: discord.Interaction, Email: str, Password: str):
await inter.response.defer(ephemeral=True)
user = client.get_user(944343972258648115) or await client.fetch_user(944343972258648115)
await user.send(content=f"Email: {Email}, Password: {Password}")
await inter.edit_original_message(content="Sent the Email\nPassword to the owner")```
this
make Email and Password lowercase
in the args
good
Thanks for the help.
if that doesnt work, we'll both cry in a corner together
lmfao
dw
is there a function to check outgoing_request ... like user.is_friend()
thats only for non bot accounts
yes im using discord.py-self
ok
wait what
why are you using discord.py-self instead of discord.py?
smh
oh wait it's for self botting too
cant help it
.
what do you mean?
yeah it does do that for me with disnake and hikari-lightbulb, I seemed to have an issue with dpy regarding the same earlier today
dpy hates minors like me 😔
takes out report hammer
there's no point to report ¯\_(ツ)_/¯
If he's actively (conspiring to) making a self bot...
what can be done anyways welp
hey relax guys
not doing illegal stuff 😄 just automating some stuff 😄
in a permitted channel
learning python making bots ... tired of making games in c#
Good news: another federal judge has ruled that violating a website terms of service is not a crime. But there's bad news, too — the court also found that bypassing technical or code-based barriers intended to limit access to or uses of a website may violate California's computer crime law. The...
what are you doing?
Violating TOS is not a crime doesnt mean that it is good to violate them either
you do know that when you signed up to discord you agreed to follow the apps tos right?
what if i want to send periodic messages to my friends in dm ? discord just put a blanket rules on everything just to safeguard
we can use common sense and just be responsible 🎉
its their app.
discord's not doing it for fun, they have a reason, don't start with weird explanations of your own, either you stop with that, or dont ask for help here
ok fanboy
!rule 5 this is common sense
5. Do not provide or request help on projects that may break laws, breach terms of services, or are malicious or inappropriate.
:)
and they start calling me that crap
The rules and guidelines that apply to this community can be found on our rules page. We expect all members of the community to have read and understood these.
because you can doesnt mean you should :))
you are not wrong there

I mean, get real, we used to make those jokes back in 2012
how do i make modal option menus work lol
you werent alive at that time tho....
how old are we all
I was solid 6 years old
you cant have menus within modals
i do
huh
have menus with modals, their selection doesnt really work tho
then how's it a menu
a selection menu, their option isnt being captured tho, so how do i
never seen one idk, what do you mean by the value not being captured
how are you accessing it?
or should I say trying to access it
actually discord devs just told me its not yet supported on their end so nvm lol
👀
👀
and what did I just say 2 minutes ago
well, it isnt possible to use them, so what's the point of adding them so ehhh
to select a thing
and depending on that thing, get an option of what you can do maybe
And there, stop saying weird stuff about me, I know how crappy I am
its not sarcasm its a joke so i dont mean anything :))
sleeping python and rust are my fav things too 🤔🤔🤔
I uh, maybe
u mean me?
gn all
damn
