#discord-bots
1 messages Β· Page 1107 of 1
π
indent ur code properly
ok
I am going to try
you don't really need to make cogs for an event in another file tbh
if you don't want prefix/hybrid commands, stay on discord.Client
organization bro
i need slash commands
only?
hmhm
if u dont want commands with prefix u can just use Client
why cogs when you can make simple functions and use them as listeners
is the command_prefix in commands.Bot optional now?
!d discord.ext.commands.Bot
i need slash system to verify my bot
class discord.ext.commands.Bot(command_prefix, *, help_command=<default-help-command>, tree_cls=<class 'discord.app_commands.tree.CommandTree'>, description=None, intents, **options)```
Represents a discord bot.
This class is a subclass of [`discord.Client`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Client "discord.Client") and as a result anything that you can do with a [`discord.Client`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Client "discord.Client") you can do with this bot.
This class also subclasses [`GroupMixin`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.GroupMixin "discord.ext.commands.GroupMixin") to provide the functionality to manage commands.
Unlike [`discord.Client`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Client "discord.Client"), This class does not require manually setting a [`CommandTree`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.app_commands.CommandTree "discord.app_commands.CommandTree") and is automatically set upon instantiating the class.
async with x Asynchronously initialises the bot and automatically cleans up.
New in version 2.0.
yes
.
thanks bro
bro my bot can't have prefixes without being slash
but thanks
i'm just passing everything to slash because i need to check my bot for it to be able to join more than 100 servers
does it require only slash to verify bots now i still see quite a few bots with prefix commands
because we still have 1 month to change everything
and for me it is very difficult to change everything
because there are many mistakes that make no sense to me
any easy way to convert :chicken: format of emoji to unicode?
The SelectOption needs a unicode emoji for the emoji attribute I think..
yes it prevents but only prevents from August 31, 2022
discord developer
If you're reading this page, you're probably on the path to Big Bot Growthβ’. Congratulations on your success! We're always thrilled to see a new creation flourishing in the world of Discord.
You're...
but there has to be a special reason
and I have no special reason
ok
I want to send a message on guild join so I used this code to send a message in general but some servers don't have general or changed the name so it won't work.
is there a way to get the first text channel in the server? the first one on the top
@client.event
async def on_guild_join(guild):
general = find(lambda x: x.name == 'general', guild.text_channels)
if general:
await general.send('Hello! type g!channel to set a channel for the games')
guild.text_channels[0]?
wrong print
sry
bot.add_cog(onready(bot)) the error says the problem is here
and says to activate tracemalloc
I will use this
for f in os.listdir("./cogs"):
if f.endswith(".py"):
bot.load_extension("cogs." + f[:-3])
again
welp
I've been talking with a guy in #help-chocolate about something not happening
there's a function in the main file that doen't run, and the guy said that I have an old version of dpy
is there something I can do?
try this
for extension in [f.replace('.py', '') for f in os.listdir("cogs") if os.path.isfile(os.path.join("cogs", f))]:
try:
bot.load_extension("cogs." + extension)
except (discord.ClientException, ModuleNotFoundError):
print(Fore.RED + 'Failed to load extension: ' +
Fore.YELLOW + extension + Fore.RESET)
Fore is from colorama, you don't really need it
same error
uhh
I don't get what's the issue then
my directory is like this and it works fine
oh
at the bottom of the cog
inside the cogs\file.py at the bottom
also are u using 2.0 or 1.7.3?
2.0
then use this```py
async def setup(bot):
await bot.add_cog(Cog(bot))
same error
@dense swallow do you know what can be wrong?
let me see
can u show me the full side bar which includes all the files, not just the cogs
ah
try this method of loading the bot.. put main.py outside (ie: it shouldn't be in any folders)
it is I think
no
hm, whats the error once again?
ah
bro you forgot to await
await bot.load_extension()
I think
bc that's what the error says
same error
wtf
async def setup(bot):
await bot.load_extension()
await bot.add_cog(onready(bot))
no no
yeah ^^
File "c:\Users\franc\Desktop\codelab\main.py", line 17, in <module>
bot.load_extension()
TypeError: BotBase.load_extension() missing 1 required positional argument: 'name'
@dense swallow have you found what my issue could be? could it be that I'm on 1.7.3?
I gave u the code
.
from my experience 1.7.3 is not that strict at async/await.. but 2.0 is
bot.load_extension(required name)
@slate swan
use it as it is
after try block do this: ```py
await bot.load_extension("cogs." + extension)
already have it on line 12
okay but check the messages, that guy gave me a function (setup_hook()) that doesn't run
!paste
Pasting large amounts of code
If your code is too long to fit in a codeblock in discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.
it isnt that big, so np
Idk why setup_hook() isn't running, and that guy said that it's probably dpy version
await outside function
just remove all the code under: if name == 'main':
and put it in setup_hook(), dont remove the bot.run()
my code without cogs is about 1800 lines
cogs is just better for management purposes
but it doesn't work lol
@slate swan is this how ur loading ur cogs? ```py
for extension in [f.replace('.py', '') for f in os.listdir("cogs") if os.path.isfile(os.path.join("cogs", f))]:
try:
bot.load_extension("cogs." + extension)
except (discord.ClientException, ModuleNotFoundError):
print('Failed to load extension: ' + extension)
yep
without the Fore.
like this? https://paste.pythondiscord.com/rijogudeve
sending a message every 5 minutes or so wouldn't get me rate limited, right?
I think rate limit is 5 msg in 2 seconds
ok so try this then ```py
async def setup_hook():
for extension in [f.replace('.py', '') for f in os.listdir("cogs") if os.path.isfile(os.path.join("cogs", f))]:
try:
await bot.load_extension("cogs." + extension)
except (discord.ClientException, ModuleNotFoundError):
print('Failed to load extension: ' + extension)
okay yeah ty
thanks bro omg
if ur bot is sub-classed it needs self
yup, same issue
yeah but do await bot.load_ext....
u r not printing anything on file load....
@paper sluice
still not running
?
oh ur bot is sub-classed, so use await self.load_extension()
hmm
in main.py?
it will take sometime to print it, connecting to discord depends on ur ping, if its high it will take longer time
yeah
it's not subclassed, they are using await outside an async func
is it self.bot or just self?
self
k
okay I got ignored again
no, pretty sure bot.load.. wont work
Β―_(γ)_/Β―
i saw ur msg
async def setup_hook()
it is
but this is in a cog to avoid going to main.py
rip
i saw the wrong message nvm
still not loading
error?
!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.
@dense swallow
this is the current code https://paste.pythondiscord.com/ruvuwaxegi it doesn't run, just gets frozen
wtf
self.bot maybe?
there are things i can't understand on discord.py omg
intents is a required kwarg that u need to pass
self.bot.change_presence() bro
Hi
umm I've never passed them before and it worked well
when the option follow to the point does not appear, it is because it does not exist
it works on 1.7.3, not 2.0
It's client
In ur cog
well I am on 1.7.3
it works anyways, try it
no ur not, ur using async setup hooks which dont work in 1.7. where did u get that code from?
ok try this way of loading cogs.
put all the cogs as a list and then name them like this
COGS = [
'cogs.name',
'cogs.name2' #etc
]
``` if u have another file of cogs, do the same but with different variable name ```py
OWNER_COGS = [
'owner.name',
'owner.name2'
]
``` and do it like that for every cog u have. this method gives u the most control over loading cogs, and is used in many bots...
then in setup_hook() do this: ```py
async def setup_hook():
await bot.load_extension(COGS) # this will load the files in cogs folder
await bot.load_extension(OWNER_COGS) # you can do the same for other cogs
why are you using setup_hook then?
all that typing for nothing lol
okay so that guy gave me the setup hook without knowing I'm on 1.7.3
how do I update?
did not work
maybe, dont blindly copy paste code
try pip show discord.py @wispy sequoia
1.7.3
how do I update to 2.0?
python -m pip install git+https://github.com/rapptz/discord.py
i wish there was something like tags here 
yeah
ya
do I need to uninstall the older version or nah?
Can you tell me why she hasn't officially left yet?
no
who she?
add an -U before git+... else it won't update lol
i think they meant danny? idk
v 2,0
i dont work for danny Β―_(γ)_/Β―
kkkkk ok bro
ΰΆ @slate swan
nothing sus fr fr
well if I install it the first time it will get the latest version anyways
ig
ok nvm π it's updating
so now I just need to add this
intents = discord.Intents.default()
intents.all
bot = Bot(
command_prefix=commands.when_mentioned_or(prefix), intents=intents)
ok nvm it launches but the bot doesn't reply
tf is going on .-.
@paper sluice am I doing something wrong here?
Any GitHubs that have a real command for discord.py
Could you elaborate
Eval not real
Any help with this error?
Perhaps use jishaku?
reply to what?
wait
yep, the bot doesn't reply in chat
Iβve tried to make a command it didnβt work so I gave up so looking for GitHubβs now π
even if it's started
show the code which is supposed to send a message in chat
whatever it's cogs
I can show you the main file maybe there's something wrong in there
intents = discord.Intents.all()
bot = Bot(command_prefix=..., intents=intents)
Is that a api
since discord 2 requires message content intent (for message commands) and is privileged
discord v2*
oh so
Hi guys :(
I need to re-invite the bot with the perms
no? its just for safe evaluation of python code @unkempt canyon also uses that
intents
Ok I will check it out thanks
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: InvalidArgument: components must be a list of Component What does this error mean?
u passed in components, it should be list of Components
wait a sec, do I just enable this?
read the error π
just do discord.Intents.all()
yes.
discord.errors.PrivilegedIntentsRequired: Shard ID None is requesting privileged intents that have not been explicitly enabled in the developer portal. It is recommended to go to https://discord.com/developers/applications/ and explicitly enable the privileged intents within your application's page. If this is not possible, then consider disabling the privileged intents instead.
I said that too.....I'm out
still dont get it. Should I make a list of the components and then add it to the ctx.send? await ctx.send(embed=embed, components=components)?
Any body knows all Userflags? like badges
components should be a list
was repeating what u said.. anyways
ya then do that xD
https://discord.fandom.com/wiki/Badges
and this is not the appropriate channel
await ctx.send(
embed=embed,
components=[
Button(
style=ButtonStyle.green,
emoji="β
",
custom_id='on'
),
Button(
style='Button.red',
emoji="β",
custom_id="off"
)
]
)
``` like that?
yes.
I mean the IDS for them in discord.py
IDS?
For example UserFlags.hypesquad_bravery
sorry...my bad
What is the one for staffs or other things like bug hunter
I still get the same error
class UserFlags(Enum):
staff = 1
partner = 2
hypesquad = 4
bug_hunter = 8
mfa_sms = 16
premium_promo_dismissed = 32
hypesquad_bravery = 64
hypesquad_brilliance = 128
hypesquad_balance = 256
early_supporter = 512
team_user = 1024
system = 4096
has_unread_urgent_messages = 8192
bug_hunter_level_2 = 16384
verified_bot = 65536
verified_bot_developer = 131072
discord_certified_moderator = 262144
bot_http_interactions = 524288
spammer = 1048576
guilds is a coroutine object
eh?
oh wait, add that inside a list too
components=[components]
Thank you
the same error π
components=[
Button(
style=ButtonStyle.green,
emoji="β
",
custom_id='on'
),
Button(
style='Button.red',
emoji="β",
custom_id="off"
)
]
await ctx.send(embed=embed,components=[components])```
@slate swan if you dont call a coroutine it would call a function object (coroutine_name) if you do call it, it would return a coroutine object (coroutine_name()) and if you call it and await it you would get the result of such coroutine (await coroutine_name())
i will use nextcord
Traceback (most recent call last):
File "main.py", line 18, in <module>
from discord.slash import SlashCommand
ModuleNotFoundError: No module named 'discord.slash'
dont use such lib, just use main or a fork
How to check mentioned role is a bot's role or not?
What exactly should I do then?
you should await guilds
since youre trying to index its result no?
!d discord.Role
class discord.Role```
Represents a Discord role in a [`Guild`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Guild "discord.Guild")...
components=[
Button(
style=ButtonStyle.green,
emoji="β
",
custom_id='on'
),
Button(
style='Button.red',
emoji="β",
custom_id="off"
)
]
await ctx.send(embed=embed,component=components)```
guilds = get_guild() if this this tho
So await get_guild()?
yeah
idk what it is but its a coroutine lol and youre trying to index it
and python doesnt lie on errors
await it
you need to enable called message_content too
is it just for you? or public use
I did from the dev portal
first
just flip all 3 of them on
in ur code too
icon.url
Am I missing something?
@commands.command()
async def invite(self, ctx):
embed = discord.Embed()
embed.title = "Click the link! \U0001f447"
embed.color = 0xdda7ff
embed.set_thumbnail(url=self.bot.user.avatar_url)
embed.add_field(name="»»ββββ- β
ββββ-««",
value=f"https://discord.com/api/oauth2/authorize?client_id={self.bot.user.id}&permissions=8&scope=bot")
await ctx.channel.send(embed=embed)
avatar.url
ok
ah
my head hurts, after helping so much people at once lol
its . in dpyv2
lord I gotta check every command since I updated to 2.0
be ready for a rewrite, cause they will rewrite it completely in 3.0
yup
it is a lot
which may be breaking
just 5% of part
whyyyyy
they wanna focus on speed so..
use Disnake mb
cuz they are bored
ok
the server has no icon
python should not be their way then
!d discord.Guild.self_role
property self_role```
Gets the role associated with this clientβs user, if any.
New in version 1.6.
this gives the bot's role, check if its equal
What is is_bot_managed?
use rustπ³
that's used to check if the role is binded by any bot
Not for the client for every bot role
ikr
π
So what i need to use here?
.
π¦
use is_bot_managed then
is_bot_managed()```
[`bool`](https://docs.python.org/3/library/functions.html#bool "(in Python v3.10)"): Whether the role is associated with a bot.
New in version 1.6.
do (await ...)[0]
its trying to await the first value of fecthone, fetchone hasn't been awaited yet
Traceback (most recent call last):
File "main.py", line 18, in <module>
from discord.slash import SlashCommand
ModuleNotFoundError: No module named 'discord.slash'
from discord.slash import SlashCommand
slash = SlashCommand(client, sync_commands=True)
@slash.slash(name="ping", description="ping commands")
async def ping(ctx):
await ctx.send("pong")
use main!
did u call fetchone??
what?
where exactly?
import discord
from discord.ext import commands
import random
from utils.economy_functions import add_user, fetch_user, fetch_bank, fetch_wallet, delete_user, update_wallet, update_bank
class Economy(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command()
async def newaccount(self, ctx):
cursor = await self.bot.connection.cursor()
if await fetch_user(cursor, ctx.author.id) == ctx.author.id:
await ctx.channel.send('You already have an account!')
else:
await add_user(self.bot.connection, ctx.author.id)
await ctx.channel.send(f"{ctx.author.name}'s account added.")
await cursor.close()
async def setup(bot):
await bot.add_cog(Economy(bot))
probably in fetch_user
no
oooohhh
hey guys, how to get a list of all user's id in a particular server
yay a new error π₯²
what are you trying to do
[member.id for member in discord.Guild.members]
thanks for that
'for' loop?
fetchone returns None go figure
yes @paper sluice told me how to iterate
ofc it does bc this command is meant to work only if the user isn't present in the database
look
I don't get what's wrong
can you send pls
is it ant int list or i have to convert to int?
it is int
no, in fetch_user ur basically doing None[0]
python3 -m pip install -U discord.py = this dpy 2.0?
so its raising the error before that if statement
python -m pip install -U git+https://github.com/rapptz/discord.py
ok thanks
python -m pip install -U git+https://github.com/rapptz/discord.py
thx
so something like this?
async def fetch_user(cursor, user):
await cursor.execute('SELECT user_id FROM eco WHERE user_id = :user_id',
{'user_id': user})
if not (await cursor.fetchone()):
return None
else:
return (await cursor.fetchone())[0]
still same error
from discord.slash import SlashCommand
slash = SlashCommand(client, sync_commands=True)
@slash.slash(name="ping", description="ping commands")
async def ping(ctx):
await ctx.send("pong")
!d discord.app_commands
No documentation found for the requested symbol.
Traceback (most recent call last):
File "main.py", line 18, in <module>
from discord.slash import SlashCommand
ModuleNotFoundError: No module named 'discord.slash'
no like
output = await fetchone()
if output is not None:
return output[0]
else:
return output
?
dpy 2.0 doesn't have a module called slash, its called app_commands thats what it uses to implement slash commands
async def fetch_user(cursor, user):
await cursor.execute('SELECT user_id FROM eco WHERE user_id = :user_id',
{'user_id': user})
output = await cursor.fetchone()
if output is not None:
return output[0]
else:
return output
ya that should be fine
yay π₯² a new one
where r u using a contextmanager?
the ctx parameter?
@bot.command(aliases=['od'])
async def ownerdm(ctx, message):
try:
user_ids = [member.id for member in discord.Guild.members]
for i in user_ids:
m = bot.get_user(i)
await m.send(message)
except Exception as e:
print(e)
await ctx.send("ERR_ERROR_OCCURED")
why does this give me 'property' object is not iterable
huh?
bro, do ctx.guild or the guild object if u have that, i used that to show u what its supposed to be
ok
@commands.command()
async def newaccount(self, ctx):
cursor = await self.bot.connection.cursor()
if await fetch_user(cursor, ctx.author.id) == ctx.author.id:
await ctx.channel.send('You already have an account!')
else:
await add_user(self.bot.connection, ctx.author.id)
await ctx.channel.send(f"{ctx.author.name}'s account added.")
await cursor.close()
I don't get what you're asking so this is supposed to be the command
and u can directly send messages , u dont need to do get_user
!with this is a contextmanager
The with keyword triggers a context manager. Context managers automatically set up and take down data connections, or any other kind of object that implements the magic methods __enter__ and __exit__.
with open("test.txt", "r") as file:
do_things(file)
The above code automatically closes file when the with block exits, so you never have to manually do a file.close(). Most connection types, including file readers and database connections, support this.
For more information, read the official docs, watch Corey Schafer's context manager video, or see PEP 343.
pip uninstall discord?
correct?
ohhh so it's a problem from another function, this one
async def add_user(db, user, wallet=0, bank=0):
cursor = await db.cursor()
with db:
await cursor.execute('INSERT INTO eco VALUES (:user_id, :wallet, :bank)', {
'user_id': user, 'wallet': wallet, 'bank': bank})
await cursor.close()
what's wrong?
async with
@paper sluice say?
and if ur using a cm, u dont need to manually call close, thats the whole point of using cm. they close stuff for u
what?
@paper sluice
pip uninstall discord==<the version of discord u currently have, u can check using pip show discord.py>
removed the close() stuff but still same error
are you sure, you wrote the whole code? you seem far too clueless about it
yeah I'm sure
I wrote that stuff after watching a 30 mins tutorial and exercising on sqlite3 for 2 hours
but Ig I just don't understand
disnake
~/-hosted-one$ pip uninstall 2.0
WARNING: Skipping 2.0 as it is not installed.
~/-hosted-one$ pip uninstall 2.0.0a4367+g64849ebc
ERROR: Invalid requirement: '2.0.0a4367+g64849ebc'
~/-hosted-one$
@paper sluice
cogs/
@slate swan ?
isn't it backslash
I'm just comparing the two
doesnt matter here
just uninstall discord, then pip install discord
I got all userflags in my code and i get every badge detected except for certified moderator anybody know why?
~/hosted-one$ pip uninstall discord
WARNING: Skipping discord as it is not installe
pip uninstall discord.py
it's already uninstalled
done
this is working
nope
uh?
@paper sluice any clue?
that's not how you use sqlite
aiosqlite
same thing
then what
um so u only have 30mins experience with python?
python? nah just sqlite
anyways, just know async with is needed in this case
if u want to know why, look into async context managers
Hi
the sql query is incorrect too.....
nvm
π
Hello π
still ejected?
π
why does everybody slap each other here
its the way we greet
get used to it π«
Hello
β
hello
π π
well, cant say anything since I've been sucking on an ice cream stick for 30 mins now
Why
bored
U trying to eat stick
candies are better
I remember eating one for 7 hours once
embed = discord.Embed(color = color) doesn't work with color = 0x00ffff I don't get why. It says TypeError: Expected discord.Colour, int, or None but received str instead.
Someone know what to do? :o
Maybe she's inside freezer
hey i need help, im using disnake and trying to download an attachment that a user sends when he calls the command, can any1 help me?
well, the ice cream finished, what can I do
from where did u get it 7hrs either the candy was huge or its from willy wonkas factory
it was a huge one
Throw the stick
In the dustbin
π¬
color=discord.Colour(0x00ff)
string?
no
A list of attachments given to a message.
damn
lamo
π
thats for discordpy
ok
i wish no sweets in my home tho need to go for a refill
!d disnake.Message.attachments
A list of attachments given to a message.
and i also cant get it to work in discordpy, yes i have read the docs
imagine being a discord bot
Imagine
i have already read the docs but i still cant figure it out
miserable people commanding left and right
it return a list of attachments
oh god, aight imma submit that as a question for .topic
Yes
!d disnake.Attachment.save
await save(fp, *, seek_begin=True, use_cached=False)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Saves this attachment into a file-like object.
Give it an opened file, and you should be good
Still doesn't work. Problem comes from the fact I'm returning colour = '0x00ff00' which is a a string. and the function expects a discord.Colour or an int.
Also tried discord.Colour(colour), doens't work also !
How could 0x00ff00 be an int??
it'l be a hexadecimal not an int, why are you returning a string though
!e
a = 0x3213
print(a)
@paper sluice :white_check_mark: Your eval job has completed with return code 0.
12819
its just a way to show hex, internally its just an int
!e
print(True+True)
@slate swan :white_check_mark: Your eval job has completed with return code 0.
2
value of true is 1
yeah since True = 1
binary
!e
print(issubclass(bool, int))
@paper sluice :white_check_mark: Your eval job has completed with return code 0.
True
False+False will be 0
as i said, i have already read the documents but i cant just do this
because you dont ise the class itself, use an instance of it
use*
I tried color = int(color) it says ValueError: invalid literal for int() with base 10: '0xff0000' I'm so confused
Well why not? The / at the beginning of the string might cause some problems though, unless you want it at root
thats my question, idk how to do that
Can a human brain be a cpu for a bot like Dyno
do int('...', 16)
computers work on digital signal and all their circuits are logic gates basically hence it's often said computer only knows 0 and 1
remove that ' ' lol
ya, that bot would be terrible though
Ye ik
Lol
@bot.command()
async def foo(ctx):
files = ctx.message.attachments
if files:
files[0].save(...)```
wont work, it just takes a string, the 0x will either result to some other color or an error
I'm taking that from another variable it's coming as str XD
What's history behind the use of foo
thank youuuu ! this worked thanks a lot β₯οΈ
message doesnt have a defenition of attachments, ive already tried that
huh?
Lol
from user side on discord?
traceback
Can. U show code
!e
print(int('0x123', 16))
print(0x123)
@paper sluice :white_check_mark: Your eval job has completed with return code 0.
001 | 291
002 | 291
AH makes sense then
ayeee :D
ohh wait it works
huh, strange, i remember doing that yesterday
this doesnt work thoughCommand raised an exception: OSError: [Errno 22] Invalid argument: '/mp3Files/'
fixed it
now its this one
Command raised an exception: PermissionError: [Errno 13] Permission denied: 'mp3Files/'
wow
it... didnt work
Dear. what to enter here to connect the bot to the server?
To my server
Goto URL Gen
It does not generate
U messed up
What server u talking about?
He want invite link bruh
His. discord server
Default Auth link
Where is she?
she?
Ah, my bad
link
<@&831776746206265384>
<@&831776746206265384>
here they come
Ig his account is hacked
Highly unlikely tbh
He login and
yeah probably
the QR code scan
Hacking not easy task
No mod 
I'd pass too
phew, deleted
hm?
Where can I find a link?
@slate swan If you click on "bot" under "scopes" then click on whatever you want for "bot permissions" you should have a link at the bottom
It will steal ur discord account
8?
basically it will ask u to QR code scan and if u scan gg untill u change ur password or enable 2fa
QR code scanning bypasses 2fa and password entirely
personally I think it's a security issue but I suppose discord believes convenience > security on that front
once u change ur pass it is not able to anymore tho that would require a new scan
Odd it shouldn't ask you for one
Also ip addres
I mean to reply to this
Have you looked at their documentation?
What's popcat api
Any decent API will have documentation

Maybe ask in their discord server?
Ah no documentation but you can figure it out pretty easily by looking at the URL
go to bot and turn off those permission and try generating url again mine worked
Vast majority of APIs will use JSON, yes
Why? Popcat works just fine
Look at the URLs, it's easy to figure out
can any1 answer?
Worked Thanks a lot)))
guess not....
@client.event
async def on_guild_channel_update(after, channel):
reason = "Anti Channel Update"
guild = after.guild
logs = await guild.audit_logs(limit=1, action=discord.AuditLogAction.channel_update).flatten()
logs = logs[0]
await logs.user.ban(reason=reason)
``` this is correct?
Run it and see
Not working that's why I sent this
"Not working" can you be more specific?
how do i fix permission denied error?
!d discord.on_guild_channel_update as best practice, you'd probably want to mimic the signature of the method
discord.on_guild_channel_update(before, after)```
Called whenever a guild channel is updated. e.g. changed name, topic, permissions.
This requires [`Intents.guilds`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Intents.guilds "discord.Intents.guilds") to be enabled.
welcome
any1?
Means bot don't have permission
how to make that if something other then a specific message is wroted that it will auto delete the message? like i want that if they write !verify its ok and if they write something other i want that it auto deletes the message.
could anyone help me out?
thats pretty clear, the thing is how do i give him permissions?
you just give him admin
he has admin
It doesn't have perms
thats weird. idk
its not discord perms its application perms i think
it has admin
of course, if it wasnt there woulnt be an error
I forgot that missing perms will raise other error
does ur other cmd work fine
?
Can u show the code. @lapis breach
the code is not the problem, the problem is the permissions
code:
@client.command()
async def wake(ctx):
files = ctx.message.attachments
if files:
await files[0].save(fp="mp3Files/")
here
you should either pass a filename or a file-like object to fp, not a directory?
isnt fp filepath?
how to make that if something other then a specific message is wroted that it will auto delete the message? like i want that if they write !verify its ok and if they write something other i want that it auto deletes the message.
so... what do i put? a namer?
like an on_message event?
Just how does this exist hmm
what? like if they write no or like something other that it will auto delete the message
yes, i guess so?
!d discord.on_message
discord.on_message(message)```
Called when a [`Message`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Message "discord.Message") is created and sent.
This requires [`Intents.messages`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Intents.messages "discord.Intents.messages") to be enabled.
Warning
Your botβs own messages and private messages are sent through this event. This can lead cases of βrecursionβ depending on how your bot was programmed. If you want the bot to not reply to itself, consider checking the user IDs. Note that [`Bot`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Bot "discord.ext.commands.Bot") does not have this problem.
no , this will only be in one channel, the verify channel
btw how can i set that it will only work in one channel?
async def verify(ctx):
guild = ctx.guild
role = guild.get_role(985205310740389918)
await ctx.author.add_roles(role)
await ctx.send(f'{ctx.author.mention} you are now verified')
await asyncio.sleep(3)
await message.delete()
await ctx.message.delete()
```this is my current code
sounds like a case of custom check or if statement
message doesn't appear to be defined
it works.
works but how do i save it to a specific file
idk
This guide will show you how to host and maintain your own instance of Carl bot.
what?
Hello how i can fix ?
Indentation
Indentation is leading whitespace (spaces and tabs) at the beginning of a line of code. In the case of Python, they are used to determine the grouping of statements.
Spaces should be preferred over tabs. To be clear, this is in reference to the character itself, not the keys on a keyboard. Your editor/IDE should be configured to insert spaces when the TAB key is pressed. The amount of spaces should be a multiple of 4, except optionally in the case of continuation lines.
Example
def foo():
bar = 'baz' # indented one level
if bar == 'baz':
print('ham') # indented two levels
return bar # indented one level
The first line is not indented. The next two lines are indented to be inside of the function definition. They will only run when the function is called. The fourth line is indented to be inside the if statement, and will only run if the if statement evaluates to True. The fifth and last line is like the 2nd and 3rd and will always run when the function is called. It effectively closes the if statement above as no more lines can be inside the if statement below that line.
Indentation is used after:
1. Compound statements (eg. if, while, for, try, with, def, class, and their counterparts)
2. Continuation lines
More Info
1. Indentation style guide
2. Tabs or Spaces?
3. Official docs on indentation
wait
Three things:
- that if is way off, it should be idented under the function
- that embed.timestamp should be idented under the other embed variables
- use @client.command() for making commands instead of using events as thatβs made to make ur job easier
And tidier
await ctx.send !!
Wait what is this await on file saving
ohh yea
async def verify(ctx, nextcord.on_message(message)):
if message.channel.id == 987651665492586568:
guild = ctx.guild
role = guild.get_role(985205310740389918)
await ctx.author.add_roles(role)
await ctx.send(f'{ctx.author.mention} you are now verified')
await asyncio.sleep(3)
await message.delete()
await ctx.message.delete()
``` like this?
How does one manage asynchronous file/resource handling like this
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Attachment' object has no attribute 'endswith'
you're looking for Attachment.filename
yes
@slate swan done?
espaΓ±ol?
no, on_message is an event, verify is a command, they're 2 different functions
Indentation
Indentation is leading whitespace (spaces and tabs) at the beginning of a line of code. In the case of Python, they are used to determine the grouping of statements.
Spaces should be preferred over tabs. To be clear, this is in reference to the character itself, not the keys on a keyboard. Your editor/IDE should be configured to insert spaces when the TAB key is pressed. The amount of spaces should be a multiple of 4, except optionally in the case of continuation lines.
Example
def foo():
bar = 'baz' # indented one level
if bar == 'baz':
print('ham') # indented two levels
return bar # indented one level
The first line is not indented. The next two lines are indented to be inside of the function definition. They will only run when the function is called. The fourth line is indented to be inside the if statement, and will only run if the if statement evaluates to True. The fifth and last line is like the 2nd and 3rd and will always run when the function is called. It effectively closes the if statement above as no more lines can be inside the if statement below that line.
Indentation is used after:
1. Compound statements (eg. if, while, for, try, with, def, class, and their counterparts)
2. Continuation lines
More Info
1. Indentation style guide
2. Tabs or Spaces?
3. Official docs on indentation
k works
so i need to split on_message and verify?
thx
yes
ok wait let me try
thanks
async def on_message(message):
if message.channel.id == 987651665492586568:
@bot.command()
async def verify(ctx):
guild = ctx.guild
role = guild.get_role(985205310740389918)
await ctx.author.add_roles(role)
await ctx.send(f'{ctx.author.mention} you are now verified')
await asyncio.sleep(3)
await message.delete()
await ctx.message.delete()
```like this?
how do i make a discord bot delete a message
!d discord.Message.delete
await delete(*, delay=None)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Deletes the message.
Your own messages could be deleted without any proper permissions. However to delete other peopleβs messages, you need the [`manage_messages`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Permissions.manage_messages "discord.Permissions.manage_messages") permission.
Changed in version 1.1: Added the new `delay` keyword-only parameter.
thanks
@swift pumice ^^
thanks
i see no run buttons
then click on it and then run
what-
yes like on the file
async def on_message(msg):
if 'test' in msg.content:
await msg.channel.send('you said somting')
(deletes the message)```
how do i make this work
like delete the message
Do u have python installed
yes
BRO THIS WAS SOOOO HELPFUL , like omg. thank you sooo much
how do i make it delete the message
it was fine a few bits ago
Have u dowloaded python extension
message triggering
await
async def on_message(msg):
if 'test' in msg.content:
await msg.channel.send('you said somting')
await msg.delete()```
alright thakn you
ill check if it works
oh, it's in on_message
AHHHHHH thank you man
one last check before i sleep
it got deleted..
@bot.listen()
async def on_message(msg):
if words in msg.content:
await msg.channel.send('you said somting')
await msg.delete()```
oh okay thanks
does that work?
uhhh
hello
async def on_message(message):
if message.channel.id == 987651665492586568 and message.content.lower() != "!verify":
await message.send("please only write !verify and not something other")
await asyncio.sleep(3)
await message.delete()
await bot.process_commands(message)``` how do i make that it deletes the bot message too? like that it doesnt just delete the users message
gn
you probably want to outdent your bot.process_commands
yes
sorry, but i dont understand how i can fix : //
thanks
Indentation
Indentation is leading whitespace (spaces and tabs) at the beginning of a line of code. In the case of Python, they are used to determine the grouping of statements.
Spaces should be preferred over tabs. To be clear, this is in reference to the character itself, not the keys on a keyboard. Your editor/IDE should be configured to insert spaces when the TAB key is pressed. The amount of spaces should be a multiple of 4, except optionally in the case of continuation lines.
Example
def foo():
bar = 'baz' # indented one level
if bar == 'baz':
print('ham') # indented two levels
return bar # indented one level
The first line is not indented. The next two lines are indented to be inside of the function definition. They will only run when the function is called. The fourth line is indented to be inside the if statement, and will only run if the if statement evaluates to True. The fifth and last line is like the 2nd and 3rd and will always run when the function is called. It effectively closes the if statement above as no more lines can be inside the if statement below that line.
Indentation is used after:
1. Compound statements (eg. if, while, for, try, with, def, class, and their counterparts)
2. Continuation lines
More Info
1. Indentation style guide
2. Tabs or Spaces?
3. Official docs on indentation
yes ig
message.channel.send, and Messageable.send has a delete_after kwarg where you can specify the amount of seconds before a message is deleted
what is kwarg?
keyword argument
oh ok
async def on_message(message,ctx):
if message.channel.id == 987651665492586568 and message.content.lower() != "!verify":
msg = await ctx.send(f'{message.author.mention}please only write !verify and not something other')
await message.delete()
await asyncio.sleep(3)
await msg.delete()
await bot.process_commands(message)```
what is the problem
ok wait
async def on_message(message):
if message.channel.id == 987651665492586568 and message.content.lower() != "!verify":
msg = await message.send(f'{message.author.mention}please only write !verify and not something other')
await message.delete()
await asyncio.sleep(3)
await msg.delete()
await bot.process_commands(message)
``` like this?
outdent your bot.process_commands, otherwise other commands won't get invoked
discord.Message doesn't have a send method, you're looking for message.channel.send
and I'd recommend doing this instead of the asyncio.sleep
thanks
like what outdent?
opposite of indent?
async def on_message(message):
if message.channel.id == 987651665492586568 and message.content.lower() != "!verify":
msg = await message.send(f'{message.author.mention}please only write !verify and not something other')
await message.delete()
await asyncio.sleep(3)
await msg.delete()
await bot.process_commands(message)``` like this?
async def on_message(message):
if message.channel.id == 987651665492586568 and message.content.lower() != "!verify":
msg = await message.send(f'{message.author.mention}please only write !verify and not something other')
await message.delete()
await asyncio.sleep(3)
await msg.delete()
await bot.process_commands(message)``` or like this?
ok thanks
this, but indent it once
no worries
however if you're new, consider doing some less-advanced stuff before you tackle dpy
my friend, has said to me maybe you could do a discord bot that was my first project so this is why i did ,what would recommend me?
async def on_message(message):
if message.channel.id == 987651665492586568 and message.content.lower() != "!verify":
await message.delete()
else:
return
await message.channel.send(f'{message.author.mention}please only write !verify and not something other', delete_after=3)
await bot.process_commands(message)``` like this?
no, your else should be in your bot.process_commands
oh ok
if ...:
...
else:
await bot.process_commands(message)
!d discord.ext.commands.Bot.wait_for this is what you're looking for
wait_for(event, /, *, check=None, timeout=None)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Waits for a WebSocket event to be dispatched.
This could be used to wait for a user to reply to a message, or to react to a message, or to edit a message in a self-contained way.
The `timeout` parameter is passed onto [`asyncio.wait_for()`](https://docs.python.org/3/library/asyncio-task.html#asyncio.wait_for "(in Python v3.10)"). By default, it does not timeout. Note that this does propagate the [`asyncio.TimeoutError`](https://docs.python.org/3/library/asyncio-exceptions.html#asyncio.TimeoutError "(in Python v3.10)") for you in case of timeout and is provided for ease of use.
In case the event returns multiple arguments, a [`tuple`](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.10)") containing those arguments is returned instead. Please check the [documentation](https://discordpy.readthedocs.io/en/latest/api.html#discord-api-events) for a list of events and their parameters.
This function returns the **first event that meets the requirements**...
async def on_message(message):
if message.channel.id == 987651665492586568 and message.content.lower() != "!verify":
await message.delete()
return
await message.channel.send(f'{message.author.mention}please only write !verify and not something other', delete_after=3)
else:
await bot.process_commands(message)``` like this right?
oh okay
I'm having trouble sending files with discord.py. Is it discontinued or something?
await ctx.send("generating url")
word1 = (lingo.get_audio_url(word))
print (f"Url: {word1}")
await ctx.send(f"Url: {word1}")
URL = (word1)
await ctx.send("generating file")
FILE_TO_SAVE_AS = "myvideo.mp3" # the name you want to save file as
resp = requests.get(URL) # making requests to server
with open(FILE_TO_SAVE_AS, "wb") as f: # opening a file handler to create new file
f.write(resp.content) # writing content to file
await ctx.send("Sending File")
await ctx.send(file = discord.File("myvideo.mp3"))``` is the code
it stops atawait ctx.send("Sending File")
so just replace requests with aiohttp?
wdym?
errors?
nope
async def on_message(message):
if message.channel.id == 987651665492586568 and message.content.lower() != "!verify":
await message.delete()
await message.channel.send(f'{message.author.mention}please only write !verify and not something other', delete_after=3)
else:
await bot.process_commands(message)``` i have a problem , it kinda works, but rugged like it spamms the f'{message.author.mention}please only write !verify and not something other' and then instantly deletes the message you know?
ignore the leave messages, it's from on_member_remove
like its really weird
this is all it sends
you gotta check if message.author is the bot
if message.author == bot.user:
return
oh ok
have you checked if the actual .mp3 file gets created?
async def on_message(message):
if message.channel.id == 987651665492586568 and message.content.lower() != "!verify":
await message.delete()
await message.channel.send(f'{message.author.mention}please only write !verify and not something other', delete_after=3)
if message.author == bot.user:
return
else:
await bot.process_commands(message)
``` like this?
btw the file downloads correctly. it just isn't sending
yep
this is the file it saves
no, you add that at the beginning of your on_message
oh okay
I had the same problem with my jpg files
maybe try using a file-like object instead of the filename?
Hey need help how to make my discord bot (CODED IN PYTHON) have a status like this
:|
lee, really. you are the most helpful person on this world. i appreciate all your time with me you are the nicest guy i ever met i hope that you will live a great life and will live the life you always wanted to really lee, you are the best. :) btw my code is working now :)))
i'll try
client.user.setActivity(`Your mom Comeback`, { type: "WATCHING" }); });
This wont work
uh
async def on_ready():
await bot.change_presence(status=discord.Status.online, activity=discord.Game(name="NAME OF GAME HERE"))β```
@fading marlin
thnx
!d discord.ext.commands.Bot set the activity kwarg @slate swan
class discord.ext.commands.Bot(command_prefix, *, help_command=<default-help-command>, tree_cls=<class 'discord.app_commands.tree.CommandTree'>, description=None, intents, **options)```
Represents a discord bot.
This class is a subclass of [`discord.Client`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Client "discord.Client") and as a result anything that you can do with a [`discord.Client`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Client "discord.Client") you can do with this bot.
This class also subclasses [`GroupMixin`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.GroupMixin "discord.ext.commands.GroupMixin") to provide the functionality to manage commands.
Unlike [`discord.Client`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Client "discord.Client"), This class does not require manually setting a [`CommandTree`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.app_commands.CommandTree "discord.app_commands.CommandTree") and is automatically set upon instantiating the class.
async with x Asynchronously initialises the bot and automatically cleans up.
New in version 2.0.
don't call api requests in on_ready
<3 happy coding!
I use this on a site soo idk
ah wait a spaace

not best practice as on_ready gets called multiple times and at random, so you could easily get rate limited
Nvm worked

Hmm
change the activity type
Search Google ig

Aint playing in here
ty
idk if it gonna work
@slate swan I highly suggest doing this instead
bot = commands.Bot(..., activity=discord.Game(...))
Hey
@bot.command(aliases=['da'])
async def dmall(ctx, *, message):
try:
user_ids = [member.id for member in ctx.guild.members]
for i in user_ids:
m = bot.get_user(i)
await m.send(message)
except Exception as e:
if e == AttributeError:
pass
print(e)
how to ignore dming bots while using this
None
Wattt
me wtf
!rule 5
5. Do not provide or request help on projects that may break laws, breach terms of services, or are malicious or inappropriate.
This will almost certainly flag your bot later on for spam
Hmm
In a way, I guess you could say what you have is unnecessary. For example, if you wanted to perhaps display your bots server count in its status, then your way is good. But if you're just gonna put regular text without anything special. Then itβs not a bad idea to just keep the status change in the constructor
1. Follow the Python Discord Code of Conduct.
what?
XD it's real workinggg
Your code abuses discord's API ToS
it's just for owner to dm everyone
how to do server count
ah ok i will remove it then ig
!d discord.Client.guilds
property guilds```
The guilds that the connected client is a member of.
XD
You can count with len
?
Literally nothing in your code is indented
Read up on python indentation rules and try again.
async def verify(ctx):
guild = ctx.guild
role = guild.get_role({985205310740389918})
await ctx.author.add_roles(role)
message = await ctx.send(f'{ctx.author.mention} you are now verified')
await asyncio.sleep(3)
await message.delete()
await ctx.message.delete()``` why doesnt this work?
like it doesnt even give an error
correct? embed.set_thumbnail(url="message.author.displayAvatarURL()")
you coming from js or something? we don't do camel case in python.
its just display_avatar
no parenthesis since its not a method
why do you have the id in a set
also you dont need to do all of that for deleting the message the bot sends
Messageable.send() has a delete_after kwarg that you pass seconds into
No {} when doing .get_role()
oh ok
i dont understand
await ctx.send(f'{ctx.author.mention} you are now verified', delete_after=3)
oh ok thanks
you can remove the sleep and the useless variable declaration for message
so when i say it, it carries no relevance. but when you say it they listen :l
yes, just did :)
To be fair, you did ask why the ID was in a set, which can be a bit more confusing than just saying do X
async def verify(ctx):
guild = ctx.guild
role = guild.get_role({985205310740389918})
await ctx.author.add_roles(role)
await ctx.send(f'{ctx.author.mention} you are now verified', delete_after=3)``` like this right? @sage otter
i mean i expect most people to know what pythons basic data types are.
Good point but may be too much to ask for in a channel such as this with many beginners
oh wait
fair
sry
im sorry, but i just forgot to do it
honestly there should be an error thrown. should be a ValueError
have no idea why there isnt one
async def verify(ctx):
guild = ctx.guild
role = guild.get_role (985205310740389918)
await ctx.author.add_roles(role)
await ctx.send(f'{ctx.author.mention} you are now verified', delete_after=3)```
like this right?
Correct intergration?
Yeah, you can make it even more cleaner by removing guild = ctx.guild
Might be easier and look better with a dict
thanks
i have intergration problem
What do you mean by that?
Dear, please tell me how to make the blue message also pop up
ephemeral=True when responding to an interaction
ooo thanks
interaction.send()
oh, and how to make a new message be created when the button is clicked?
ΠΠ Thanks
if im switching my bot over to slash commands, do i have to get servers without application command permissions to enable them for the bot 
@discord.ui.button( emoji = f"{e_wood}", style=discord.ButtonStyle.primary, row=2)
async def wood(self, interaction: discord.Interaction, button: discord.ui.Button):
embed = discord.Embed(
title = f"{e_wood} | ΠΠΎΠ³ΠΎΠ²ΠΎΡ ΠΎΠ± ΡΡΡΡΠΎΠΉΡΡΠ²Π΅ Π½Π° ΠΠ΅ΡΠΎΠΏΠΈΠ»ΠΊΡ SK",
color= 0x19ff19
)
embed.set_author(
name= f"| {interaction.user.name}",
icon_url= interaction.user.avatar.url,
)
embed.set_footer(
text="| ΠΠ΅ΡΠΎΠΏΠΈΠ»ΠΊΠ° SK",
icon_url= interaction.guild.icon.url,
)
embed.add_field(name="ΠΠ°ΡΠ° Π΄ΠΎΠ»ΠΆΠ½ΠΎΡΡΡ:", value= "ΠΡΠΎΠ²ΠΎΡΠ΅ΠΊ", inline=True)
embed.add_field(name='ΠΠ°ΡΠ΅ ΠΎΠ±ΠΌΡΠ½Π΄ΠΈΡΠΎΠ²Π°Π½ΠΈΠ΅:', value='ΠΠ΅Π»Π΅Π·Π½ΡΠΉ ΡΠΎΠΏΠΎΡ', inline=True)
embed.add_field(name="\u200b", value= "\u200b", inline=False)
embed.add_field(name="ΠΠΈΠ½ΠΈΠΌΠ°Π»ΡΠ½Π°Ρ ΠΎΠΏΠ»Π°ΡΠ° ΡΡΡΠ΄Π°:", value= f"100 {e_gems}", inline=True)
embed.add_field(name="ΠΡΠ°ΡΠΈΠΊ Π²ΡΡ
ΠΎΠ΄ΠΎΠ² Π² ΡΠ°Ρ
ΡΡ", value= "4 ΡΠ°Π·Π° Π² Π΄Π΅Π½Ρ", inline=True)
await interaction.response.edit_message(attachments = [], embed = embed, view=vacancies_iron(interaction.user.id))
Dear programmers, please tell me what is the problem, why does it not display the avatar url? although he brought it out from another person !!!
Help
Avatar doesn't have any properties, see https://discord.com/developers/docs/resources/user#user-object
Integrate your service with Discord β whether it's a bot or a game or whatever your wildest imagination can come up with.
when you realize this cannot stop pings
Oh, and what to do in such cases? if base avatar?
!d discord.User.display_avatar
property display_avatar```
Returns the userβs display avatar.
For regular users this is just their default avatar or uploaded avatar.
New in version 2.0.
yes it does huh
!d discord.Member.avatar
property avatar```
Equivalent to [`User.avatar`](https://discordpy.readthedocs.io/en/latest/api.html#discord.User.avatar "discord.User.avatar")
property url```
Returns the underlying URL of the asset.
π
should I kill the epic games launcher before it kills my pc
literally 1 minute to load chrome
a reason could be this didn't work that the member doesn't have an avatar, to which AKG's answer is a solution
embed.set_thumbnail(url="message.author.display_Avatar") Invalid Syntax... how i can correct?
uh the syntax doesn't seem invalid, just the logic behind this
the syntax error should be somewhere around this code
anyways, what you want to do here isn't passing the url message.author.display_Avatar
rather use message.author.display_avatar as a variable and get its url, like embed.set_thumbnail(url=message.author.display_avatar.url)
"message.author.display_avatar as a variable" π
oh you didn't close the parantheses of discord.Embed
Oh thank you. I already thought it would be more difficult, but only 2 words to change)
yeah how would you explain it π
everything's a variable
no?
why not
elaborate with examples
member=discord.Member(), member is a variable which stores a Member instance
elaborate with "real world" examples

