#discord-bots
1 messages · Page 42 of 1
bruh I just didn't mind a speed up if it's possible, didn't expect this much problems
sed
and that's what u always say😭
i get bad feeling about this i feel like it not gonna end well
🗿you were migrating the repo right, its still empty
I have friends those use it in their bot, I don't think I can handle this much changes, it's traceback is looking realllyyyy weird
who migrating no one we didn't even finish
devs i manage to find are even lazier than me my luck too bad😔
and what are your current intents?
noones lazier than me
me is
i can't code for more than 100 lines a day without motivation
apparently slice gonna beat ur record
i managed to get u to work once a week
he broke ur record yesterday
and try running now
respect+ for mah man
😭
How can I do this in my readme?
u too savvy slugging it out for u
why is this giving this error
io shields
how use
he is almost done tho
We serve fast and scalable informational images as badges
for GitHub, Travis CI, Jenkins, WordPress and many more services. Use them to
track the state of your projects, or for promotional purposes.
he got it done pretty fast
Google for github readme badges lol
there are many sites
still not responding
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.
meh I'll be active after moving to kota
sarth btw if u free tonight can u make the code latest dpy compatible u have to like make the paginator again...
oh cool
just keep this in mind then if i haven't done it or i forget
the hash stuff? we can make our embeds hashable easy
yeah and they changed interaction response method names
still no message_content enabled 
i have been kinda lazy so didn't fix these
i figured it i don't soon it gonna pile up
!d discord.ext.commands.Context.from_interactiom
No documentation found for the requested symbol.
!d discord.ext.commands.Context.from_interaction
classmethod await from_interaction(interaction, /)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Creates a context from a [`discord.Interaction`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.Interaction "discord.Interaction"). This only works on application command based interactions, such as slash commands or context menus.
On slash command based interactions this creates a synthetic [`Message`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Message "discord.Message") that points to an ephemeral message that the command invoker has executed. This means that [`Context.author`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Context.author "discord.ext.commands.Context.author") returns the member that invoked the command.
In a message context menu based interaction, the [`Context.message`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Context.message "discord.ext.commands.Context.message") attribute is the message that the command is being executed on. This means that [`Context.author`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Context.author "discord.ext.commands.Context.author") returns the author of the message being targetted. To get the member that invoked the command then [`discord.Interaction.user`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.Interaction.user "discord.Interaction.user") should be used instead.
New in version 2.0.
do ```py
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)```
huh i meant names 
i mean just change it to Context and use ctx.send and stuff you want 🤷
😭 Bot finally workedd thxx
this code doesnt show my user avatar
🗿
whats the load_image_async function
what would i use it for tho?
legit
no avatar...
interaction method names are pain
Why are you moving to kota
imagine sarth's feelings after he got ignored with saying the same thing
ctx do be short
jee preps ofc
oh ok 👍
can yall help me or????
totally not the first time so yeah
You will die there !!!
@dense fiber
hardcore
totally intended
dosent matter u die anyway
@slate swan
Asher's so smart
kek i wish i clear in first try or i am gonna go be neighbours with sarth
well idk much about PILLOW, asher does ask him
probably some issue with the paste part
NOOO!
🗿 imagine asher knocking at my door "code when"
this guy not even using pil he is using a third party for pil which is named something like easy_pil
i thought u would be happy 💔
am i so irritating 🥲 ||tho u need to get to work no more excuses 🔪 ||
☕ you'd be clearing JEE in 1st attempt tho, whats the deal
never knew it was a thing
!pip easy_pil
heh i wish ...
i learnt few days ago
from some yt tutorial a guy asked before
same question
ur mind always wandering in dangerous areas
are app commands supposted to be slash commands?
eh no typing stuff is really easy if you do it from the base
huh
i don't mind u making more stuff but u don't finish prev tasks😔
app commands include but are not limited to slash commands
i have 1.5 year old projects pending
okay thx
u need to focus 🚶
i legit did this: pip install easy-pil
yeah
is it supposed to be easy_pil??
the name is easy_pil but u install it like easy-pil
u installed correct package
anyways gl for ur studies
ty , ill go study nowww
do i need to reinstall?
rip discord mobile image not loading
oh
Bai Bai 👍
how do i go about fixing it?
Do you really want engineering that badly!!! Why not BCA or B SC CS
hmm i don't see much wrong except just do member.display_avatar.url
k
image = await load_image_async(ctx.author.display_avatar.url)
# Initialize the editor and pass image as a parameter
editor = Editor(image).circle_image()
try this?
just the first line use member. whatever i said
k
parents 
prolly
Or maybe he wants to buy Lamborghini
just interests
i looked into syllabi of B.Tech B.Sc and B.C.A. and found Btech more interesting
maybe both
It's literally just more math !!!
I'd be in college rn if it was my parents wish lol
this channel should be moved to ot
mhm
and should be kept there
too much math
this is literally #ot3-discord-bots
BCA has more business stuff but BSc CS is btech without physics and chem
i mean if i would have to take a drop it would prolly only be if i am sure shot to get into iit in my next try
Do that IIT Madras BSc online thing
BSc has too less programming in practice when compared to Btech
they focus more on theory
and applications
otherwise as long as i get a good course and college i am good
umm at best it's just gonna be 2/8 subjects for programming
in any semester
rest all still gonna be maths and all
which class u are in?👀
ok im gonna shove the memo in your face, go to one of the ot channels please
😔 okie
I am going uni in September!!
Do you have a discord.py question?
cse
pog
Wbu when are you going uni!!
this year gonna write entrance
i mean technically next year
this academic year
which college?
Just a local one nothing special
You're also doing cse?
Well wanting to do cse
cse is good no matter which college
nice nice
do you want an ORM
if so sqlalchemy, prisma, tortoise are nice
otherwise asyncpg best prolly
what's ORM
object relational mapping
do you have any resources that explain the benefits of ORM?
Not writing SQL
Not in particular, maybe the wiki page: https://en.wikipedia.org/wiki/Object–relational_mapping#Comparison_with_traditional_data_access_techniques
Prisma is my personal favorite
basically it's the interaction with a database without sql?
Yes and data is returned in nice dicts
You use methods and classes to interact with the database
It’s pretty cool honestly
which one do you think is the best between asyncpg and motor?
Those are not ORMs
motor is not a ORM?
No they’re connectors
no it's just a database wrapper
I wanted to say sqlalchemy
ah yes connector is the proper term
I believe it’s blocking
there's the async version
sqlalchemy does have an async interface
That’s great then use that
in my experience prisma is the most fun to use
the prisma python maintainer is awesome too
it does
I red that wrong my bad
are you going to make the embed text formatting gist thing
absolutely not
😭
Can prism connect to the database with a url string?
yes
do you think that prisma is easier than sqlalchemy?
yes
if you don't like the prisma schema lang you can make it in sql and then generate it with prisma generate or something
aside from that I think prisma is more intuitive
ok thx, then I'll use prisma
Share the link
what link
isn't this github?
ah
i feel like someone asks me: who asked?
the errors & bugs: nothing part is something i can never relate to
same :(
yea
well, just a warning
could be problematic in future versions
well, still not good
what part of Code does this warning come.from?
come.from
reason for the warning
uhm? no current even loop
you could do
name, value, inline = ("Content", message.content, False)
tuple unpacking
yea in newer python versions its functionality will change
Deprecated since version 3.10: Deprecation warning is emitted if there is no running event loop. In future Python releases, this function will be an alias of get_running_loop()
so you might consider using creating a loop manually first
for name, value, inline := field in fileds: 💀
bruh
Well, the list doesn't even make sense
well at least it will work... but.. nothing...
use dict based cursors when
where's it best to create a loop?
if i have to do it manually...
Hello, I have kinda weird problem, lets say that I have this piece of code
@client.command()
@commands.cooldown(RATELIMIT, PER_SECONDS, commands.BucketType.default)
async def getdifficulty(ctx):
request = requests.get("https://blockchain.info/q/getdifficulty") print(request)
print(request.content)
await ctx.send(request.content)
When I call the command, it prints the response on discord and in my terminal, but when i change the code, for example like this
@client.command()
@commands.cooldown(RATELIMIT, PER_SECONDS, commands.BucketType.default)
async def getdifficulty(ctx):
request = requests.get("https://blockchain.info/q/getdifficulty") print(request)
print("Test")
await ctx.send("Test")
save it and then run it again, it still prints the same thing as before. What should I do? Thanks
!d asyncio.new_event_loop
asyncio.new_event_loop()```
Create and return a new event loop object.
bruh, that's only for ifs ig :(
ik, do I just put it right there in my code?
im just unsure if there is gonna be a problem
probably i should tias
put it at the entry point of your program, where the first async function needs to be called
because this should be called only once
hm... okay, got it
it would depend
**text**?
why not use description so all can be same
how could i make slash commands any documentaion?
i cant make that in desc
because there's a loop that changes every horse
its literally just embed.description+= "part to add"
oh... my... gosh...
i want a rep kind of thing for my bot i just dont know how i can keep track of everyones rep what should i do put have a var for every single one?
db
create your own database and store it there
To host them, yes. The engines are FOSS
google it
SQLite works
does mongoDB cost money
"google it" how useful
theres a free tier
could i just store them all in a file
Can use json, not ideal
well, 1) learn how to make database 2) come with a specific problem rather then "how do i create database", this seems like a good plan dont you think
should use SQLite with an async driver
^
wat is a async driver
Connection to a database is I/O, so you'll need it to not block the asynchronous event loop. Async drivers let you connect to your database without blocking
If someone asks a question about something you suggested shouldnt you help them as you gave them the suggestion? either way you should follow the code of conduct of this server. #code-of-conduct
me?
its for making CRUD operations async so concurrency can be possible with the event loop
You're right that "How do I create a database" is a bit open-ended, I think definitely do a little bit of research, narrow your questions down, and we can help you out
How do I get the token for my bot? I am at the bot page yet there is no copy token only reset token
well, good answer requires good question so... but i dont want to overflood this channel with our nonsense argue so i wont continue in it
You can't copy token anymore. They won't show it to you. You'll have to reset your token and keep it safe somewhere
Or if you're like me just reset it every time
which your answer wasnt good to his question, atleast redirect him to documentation
reset it and get the new one
Why would they do that tho
like robin said i reset it everytime i lose it
security
clearly ineffecient but it works for me
just save it in an env file or a python file or a json config file
if no one sees it then why reset it every time 🦆
Yeah I used to code python bots like a year ago, it's just this token not showing thing is new
It's more secure, though. That's a +
The one time being lazy pays off
he deleted his account
In depth tutorial on how to set all available presence to your bot!
Thanks
Anyone that could help with with my VPS, I just got it and got some problems with it. It's for my discord bot
Really need it 
is there a way to set the api version you want through aiohttp? i've done it before but forgot how
I don't know anything about VPS, but you should either try here or see #❓|how-to-get-help
I already got it to work, thanks anways.
Don't think that's possible as that would introduce a host of new bugs
discord.py v2 is now on pypi btw
async def get_json_info():
json_path = Path("/home/runner/disnake-testing-playground/IrusuBot/config.json")
async with aiofiles.open(json_path, mode='r') as f:
data = await f.read()
return json.loads(data)
def get_prefix(bot, message):
loop = asyncio.get_event_loop()
data = loop.run_until_complete(get_json_info())
loop.close()
return data[str(message.guild.id)]["prefix"]
Traceback (most recent call last):
File "/home/runner/disnaketest/venv/lib/python3.8/site-packages/disnake/client.py", line 612, in _run_event
await coro(*args, **kwargs)
File "/home/runner/disnaketest/venv/lib/python3.8/site-packages/disnake/ext/commands/bot_base.py", line 618, in on_message
await self.process_commands(message)
File "/home/runner/disnaketest/venv/lib/python3.8/site-packages/disnake/ext/commands/bot_base.py", line 614, in process_commands
ctx = await self.get_context(message)
File "/home/runner/disnaketest/venv/lib/python3.8/site-packages/disnake/ext/commands/bot_base.py", line 518, in get_context
prefix = await self.get_prefix(message)
File "/home/runner/disnaketest/venv/lib/python3.8/site-packages/disnake/ext/commands/bot_base.py", line 457, in get_prefix
ret = await disnake.utils.maybe_coroutine(prefix, self, message)
File "/home/runner/disnaketest/venv/lib/python3.8/site-packages/disnake/utils.py", line 578, in maybe_coroutine
value = f(*args, **kwargs)
File "./IrusuBot/main.py", line 30, in get_prefix
data = loop.run_until_complete(get_json_info())
File "/nix/store/p21fdyxqb3yqflpim7g8s1mymgpnqiv7-python3-3.8.12/lib/python3.8/asyncio/base_events.py", line 592, in run_until_complete
self._check_running()
File "/nix/store/p21fdyxqb3yqflpim7g8s1mymgpnqiv7-python3-3.8.12/lib/python3.8/asyncio/base_events.py", line 552, in _check_running
raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running
today these two functions were working fine
the loop is already running, you cannot call run_until_complete again...
and whats the point of having a normal get_prefix function when you want to perform async operations?
how can i make , !help and ! help both work ?
i need to pass get_prefix to commands.Bot(command_prefix=...) how can it be async
bot = commands.Bot(..., strip_after_prefix=True)
why can it not be?
discord.py allows both normal functions and coroutines for that kwarg
await keyword can be used only inside function, how can i do that
!d discord.ui.Button.emoji
property emoji```
The emoji of the button, if available.
you aren't calling the function there sir, you are just providing the function object, discord.py calls it for you ```py
async def get_prefix(bot, message):
return "..."
bot = commands.Bot(command_prefix= get_prefix)
Usually for custom emojis, you need to provide an ID too, in this format:
<:name:id>
Does it still just show as text?
!d discord.Client.get_emoji try this
get_emoji(id, /)```
Returns an emoji with the given ID.
Changed in version 2.0: `id` parameter is now positional-only.
okay ill try
I don’t think that’ll make much of a difference, it just makes the same string
did you use \ and get the escaped name of the emoji or copy the ID with some other method?
yep
i did slash
\
then :emojiname:
and it gives me this for example \🚁
bad example
like that and i copy n paste that
and the bot is in the server where emoji is from?
no its not
i thought it didnt have to be
it doesnt with webhooks
well, it does for bots
rip
thats okay ig
ye it works now
thanks sarth
can someone help with how to make a button within a button
i want to have this button but after they've pressed on it they can go back to the main button they started with
https://paste.pythondiscord.com/qotezovave
Hello, I have this slash commands code with the discord_slash module (i don't like to use discord.py v2 and all my bot is with that module) and when I put the options the command does nothing even if i put all the fields in it
what hosting plan a music bot need for a single server 24*7 ?
jesus is that really how they make you do it in discord_slash 😭
anyone know explicitly when cog_load gets called? not seeing anything when bot boots or when commands are executed... https://discordpy.readthedocs.io/en/stable/ext/commands/api.html#discord.ext.commands.Cog.cog_load
How are you subclassing it?
class CustomCog(commands.Cog):
def __init__(self, bot):
I mean how are you subclassing the cog_load method?
async def cog_load(self):
And this cog is being loaded? Commands belonging to it work?
yea
Then it should definitely be firing
this is what it's doing
async def cog_load(self):
print("cog_load")
print(self.bot.guilds)
frustrating then =T
A weird one. Not sure what else could be happening
"the cog gets loaded" means when you do
self.add_cog(CustomCog(self))
right?
oh I guess i could do
@commands.Cog.listener()
async def on_ready(self):
print('Custom Command Online')
add_cog is a coro in 2.0
make sure you're awaiting it
This is bot ready not cog ready
yeah my cog is created in a custom bot
not quite sure if that's a good pattern, still trying to figure things out
which is best for a 24*7 music + modration + economy in 300k single server ?
anyone mind linking me an example of await self.add_cog? all examples are non coro
????????????????????????????????????????????????
@full lily
just found it, nevermind
it's the very same you just add await at the start
the last one is the best
lol pls gimme a correct suggestion
what suggestion? You asked which is the best VPS
24*7 music + modration + economy in 300k single server ,,, things
i mean effecent
like 100% use
If you mean which would be adequate for your use
if i buy 160 or 320 most of CPU will be uselesss
yesssssssssssssssssssssssss
depends on how well you've coded it. But the third one should be sufficient
I coded it in very bed lol !
lol
well you should go for the 320$ one then
3rd ok
oh, didnt know 2.0 just got released, stuff workin now I updated
class MusicCog(commands.Cog, name='Music'):
'''play'''
def __init__(self, bot):
self.bot = bot
async def node_connect(self):
await self.bot.wait_until_ready()
await wavelink.NodePool.create_node(bot=self.bot,host= 'lavalinkinc.ml',port=443,password='incognito',https=True)
@commands.Cog.listener()
async def on_ready(self):
self.bot.loop.create_task(node_connect())
can someone help me with my music code? it says that node_connect() is undefined in the last line of code, and im not sure where to move it
it's a method of the cog class, you can access it through self
and we're not really allowed to help with wavelink and ytdl stuff because of rule 5
depends where you get the music from
!ytdl has the fine details if you want
updated to 2.0, awaited my add_cog, now commands not working -.-
import os
import json
import discord
from discord.ext import tasks, commands
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
class CustomCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
async def cog_load(self):
print("cog_load")
@commands.command()
async def test(self, ctx):
print('test invoked')
await ctx.send('test')
class CustomBot(commands.Bot):
def __init__(self):
intents = discord.Intents.default()
intents.members = True
intents.messages = True
super().__init__(command_prefix='!', intents=intents)
async def on_ready(self):
print(f'{bot.user} has connected to Discord!')
await self.add_cog(CustomCog(self))
bot = CustomBot()
bot.run(TOKEN)
Uhh
Did you try python async def setup(client): await client.add_cog(staffapps(client))?
whoops. replace staffapps to whatever your class is called
It's not an extension though, just a cog
I assume he merged them just for the paste
He's using the class in on_ready
the whole thing confuses me tbh
Is it printing the login message correctly but not the cog load one?
this is why I asked for examples and people just said, "just add await to it"
it's printing login message and cog_load
Want me to send you a blueprint you can use?
that's likely because your message content intents aren't enabled
nothing to do with the cog
!e
code
!eval [python_version] <code, ...>
Can also use: e
*Run Python code and get the results.
This command supports multiple lines of code, including code wrapped inside a formatted code block. Code can be re-evaluated by editing the original message within 10 seconds and clicking the reaction that subsequently appears.
If multiple codeblocks are in a message, all of them will be joined and evaluated, ignoring the text outside of them.
By default your code is run on Python's 3.11 beta release, to assist with testing. If you run into issues related to this Python version, you can request the bot to use Python 3.10 by specifying the python_version arg and setting it to 3.10.
We've done our best to make this sandboxed, but do let us know if you manage to find an issue with it!*
does discord have an invite api? to track invites?
track in what way?
well to know who invited who
Discord discourages invite tracking
why so?
In their official API server they tell people not to do it
iirc it's due to some advertising stuff or whatever
You can join the server to check it
hmm, do you have the link of it with you?
tysm
Ah here it is
how can i check wather the input is url or not ?
you can use regex - it has a somewhat steep learning curve but im sure you could find an example for url searching online
messages should be changed to message_content
!traceback ?
Please provide the full traceback for your exception in order to help us identify your issue.
While the last line of the error message tells us what kind of error you got,
the full traceback will tell us which line, and other critical information to solve your problem.
Please avoid screenshots so we can copy and paste parts of the message.
A full traceback could look like:
Traceback (most recent call last):
File "my_file.py", line 5, in <module>
add_three("6")
File "my_file.py", line 2, in add_three
a = num + 3
TypeError: can only concatenate str (not "int") to str
If the traceback is long, use our pastebin.
thx guess that's kinda new stuff
someone help please
Color instead of Colour
hole line still an error
also you should take ctx as the first arg 🤨
wdym first arg?
the first argument to your command
the message context is always passed first
also ur parenthesis arent enclosing the desc
!d discord.ext.commands.Context
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.
Some basic python would really help 😓
w/ what
Not knowing what an arg is
sir or ma'am can you just please help me
your parenthesis arent enclosing the desc

you haven't closed the outer most brackets
well, you have, but you put description out of the brackets
ngl dude your bio is kinda sus
😇
yes
how would i get my bot to change a nickname without using client.command
because client.command always breaks for me lol
!d discord.ext.commands.Bot you need to use thsi @eager hill
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.
ive used that
so what happens
it says that in terminal when i do ,snipe
you need to do text='test'
async def snipe(message):
if snipe_message_content == None:
await message.channel.send("There is nothing to snipe")
else:
embed = discord.Embed(color=discord.Color.random(), description=f"{snipe_message_content}")
embed.set_footer(test=f"Requested by {message.author.name}#{message.author.discriminator}")
embed.set_author(name=f"Sniped the message deleted by {message.author}")
await message.channel.send(embed=embed)
return```
nothing ```py
bot = Bot("!")
@bot.command(pass_content=True)
async def changenick(ctx, member: discord.Member, nick):
await member.edit(nick=nick)
await ctx.send(f'Nickname was changed for {member.mention}')
you did a type
when i try !changenick @eager hill test, it would never work
when did you last use dpy?
no idea what that is
did a type?
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='!')
@bot.command()
async def nick(ctx: commands.Context, member: discord.Member, *, nick: str):
await member.edit(nick=nick)
await ctx.reply(f'Changed the nickname of {member.mention} to `{nick}`')```
async def snipe(message):
if snipe_message_content == None:
await message.channel.send("There is nothing to snipe")
else:
embed = discord.Embed(color=discord.Color.random(), description=f"{snipe_message_content}")
embed.set_footer(test=f"Requested by {message.author.name}#{message.author.discriminator}")
embed.set_author(name=f"Sniped the message deleted by {message.author}")
await message.channel.send(embed=embed)
return```
the tutorial is outdated, you shouldn't use it
can u explain what i did wrong
you made a typo
i dont see it
you did test= instead of text=
oh
i switched to dpy 2.0 and my bancount command isnt working anymore it returns a error saying "object of type 'async_generator' has no len()"
@commands.command()
async def bancount(self, ctx):
bancount= len(ctx.guild.bans())
embed=discord.Embed(description=f"There are `{bancount}` bans in this server", color=0x6666FF)
await ctx.send(embed=embed)```
code
yuh but that code dont work either
!d discord.Guild.bans
async for ... in bans(*, limit=1000, before=..., after=...)```
Retrieves an [asynchronous iterator](https://docs.python.org/3/glossary.html#term-asynchronous-iterator "(in Python v3.10)") of the users that are banned from the guild as a [`BanEntry`](https://discordpy.readthedocs.io/en/latest/api.html#discord.BanEntry "discord.BanEntry").
You must have the [`ban_members`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Permissions.ban_members "discord.Permissions.ban_members") permission to get this information.
Changed in version 2.0: Due to a breaking change in Discord’s API, this now returns a paginated iterator instead of a list.
Examples
Usage...
theres no error but nothing happens when i try !nick @eager hill test
@commands.command()
async def bancount(self, ctx):
bancount= len(await ctx.guild.bans())
embed=discord.Embed(description=f"There are `{bancount}` bans in this server", color=0x6666FF)
await ctx.send(embed=embed)```
did you create a bot user and add the token?
ahh await i thought about that
ill send entire code in pastebin but yes i did
remove the token when sending
!pastebin
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.
but it still dosent work
what happens
i remember it saying await cnt be used in this expression
object async_generator can't be used in 'await' expression
(im black btw)
did not ask
ok
alright
i was testing a bad word filter
thanks so much that worked Have u a good night
bye
can we not post slurs here please
oh you changed every client to bot
yes
clients don't have commands
only bots
my fault
Also there's an event for this. if you have some kind of filter and don't want to manually change someone's name, you can use on_member_update with some type of filter along with the command you already have set in place
!d discord.on_member_update
discord.on_member_update(before, after)```
Called when a [`Member`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Member "discord.Member") updates their profile.
This is called when one or more of the following things change...
don't do that next time please, even if it's in a pastebin
got it 👍
async def avater(ctx, *, member: discord.Member = None):
member = ctx.author if not member else member
embed = discord.Embed(title=f"{member.name}'s avatar, color = member.color , timestamp= ctx.message.created_at")
embed.set_image(url=member.avatar_url)
embed.set_footer(text=f"Requested by {ctx.author}",icon_url=ctx.author.avatar_url)
await ctx.send(embed=embed)```
Can you tell me why it says command avatar not found
now commads as simple as hello wont work
i know that it now has to use ! but it says py Ignoring exception in command None: discord.ext.commands.errors.CommandNotFound: Command "hello" is not found
is there a method to get a channel from a guild by id in d.py 2.0.0?
docs are a bit confusing
or actually, a list of all the channel ids in the guild
display_avatar.url
def check( m):
return m.content == ('yes'or'Yes'or'T'or 't'or'Y'or'y') and m.channel == ctx.channel and m.author.id == ctx.author.id
why Yes and all not working ?
!d discord.Guild.channels
property channels```
A list of channels that belongs to this guild.
Do I get rid of member or keep and add display
to check if a channel is in a particular guild would it be faster to get all the ids first and then check my channel id against them or first get the channel and see if its in guild.channels?
?? didnt understand
like ids = [channel.id for channel in guild.channels]
thats not how you use or for multiple condition check
@heavy swift when I do url=display.member_url display is an error
The second is faster, for an example the first one means, a list comp which is O(n) then using contains which is also O(n)
You can keep the member, just change the value in icon_url to display_avatar.url
then how ?
But also the second choice isn't the most optimal\
i have a list of ids. wouldnt "fetching" every channel and then checking be multiple slow calls to the api?
For an example if you use Guild.get_channel(id) you can check if it's None
Meaning that Guild has no channel with the specified ID
oh so Guild does have a get_channel method
get_channel(channel_id, /)```
Returns a channel with the given ID.
Note
This does *not* search for threads.
Changed in version 2.0: `channel_id` parameter is now positional-only.
thank you
So just check if it returns None, if it did it's either not cached or it doesn't exists to that guild
Much better than checking against a list of IDs that you create solely for that purpose
@heavy swift did u see this?
member.display_avatar.url
another question. to detect when a member is either banned, kicked, leaves, or otherwise removed from the server, would i need to use both on_member_remove and on_member_ban?
the two events are a little inconsistent in their args
still says command "avatar" is not found
You want to use on_member_remove the other is strictly for bans
🤨 How did you write it and what does the error look like now
The other handles all three that you want
thank you, this was the clarification i needed
async def avater(ctx, *, member: discord.Member = None):
member = ctx.author if not member else member
embed = discord.Embed(title=f"{member.name}'s avatar, color = member.color , timestamp= ctx.message.created_at")
embed.set_image(url=member.display_avatar.url)
embed.set_footer(text=f"Requested by {ctx.author}",icon_url=ctx.author.avatar_url)
await ctx.send(embed=embed)
No problem
!d discord.Member
icon_url still isnt fixed
mfw bot dead
also u made a typo
python bot?
!d
It's alive
uhh context...? lmao
am i blind
i dont see it
you haveter and not tar
what line??
it's the 2nd to last line ctx.author.avatar_url should be replaced with ctx.author.display_avatar.url
in the {} right?
it's the part that's next to it
i meant yea
icon_url = ctx.author.display_avatar.url
#help-grapes help pls : ((
async def avatar(ctx, *, member: discord.Member = None):
member = ctx.author if not member else member
embed = discord.Embed(title=f"{member.name}'s avatar, color = member.color , timestamp= ctx.message.created_at")
embed.set_image(url=member.display_avatar.url)
embed.set_footer(text=f"Requested by {ctx.author}",icon_url=ctx.author.display_avatar.url)
await ctx.send(embed=embed)```
oh oops, you should have author after member, so keep everything you have now just make it member.author.display_avatar.url, that's my bad
Can you specify what line sort
Nvm
that happens
async def avatar(ctx, *, member: discord.Member = None):
member = ctx.author if not member else member
embed = discord.Embed(title=f"{member.name}'s avatar, color = member.color , timestamp= ctx.message.created_at")
embed.set_image(url=member.display_avatar.url)
embed.set_footer(text=f"Requested by {ctx.author}",icon_url=member.author.display_avatar.url)
await ctx.send(embed=embed)```
I'll specify, embed.set_image(url=member.author.display_avatar.url) and you can change your footer back to what it was before
Why my bot says it has no attribute send
how are u sending
Nvm
async def avatar(ctx, *, member: discord.Member = None):
member = ctx.author if not member else member
embed = discord.Embed(title=f"{member.name}'s avatar, color = member.color , timestamp= ctx.message.created_at")
embed.set_image(url=member.author.display_avatar.url)
embed.set_footer(text=f"Requested by {ctx.author}",icon_url=member.author.display_avatar.url)
await ctx.send(embed=embed)```
u don't need the * tho 
just do member or CTX.author
embed.timestamp = datetime.datetime.utcnow()
just do member.display_avatar
for image
icon_url also just do member.display_avatar
async def avatar(ctx, member: discord.Member = None):
member = ctx.author if not member else member
embed = discord.Embed(title=f"{member.name}'s avatar, color = member.color , = datetime.datetime.utcnow()")
embed.set_image(url=member.display_avatar)
embed.set_footer(text=f"Requested by {ctx.author}",icon_url=member.display_avatar)
await ctx.send(embed=embed)```
so this?
umm no
Oh yeah you're right, I didn't see that lol
?
@client.command()
async def avatar(ctx, member: discord.Member = None):
member = member or ctx.author
embed = discord.Embed(title=f"{member.name}'s avatar", color = member.color)
embed.timestamp = datetime.datetime.utcnow() embed.set_image(url=member.display_avatar)
embed.set_footer(text=f"Requested by {ctx.author}",icon_url=member.display_avatar)
await ctx.send(embed=embed)
nvm
btw this error means you dont have dpy 2.0 installed, the equivalent code for dpy 1.7 would be member.avatar_url
ok so basically this is a .json file and say i want to update 6552254 under values and change what it is equal to which is "+0" right now to "+10" then save the json file can anyone help
https://cdn.discordapp.com/attachments/366673247892275221/1010017304928591903/unknown.png
?
Guys I wanna get a message object, so in on_message I wanna get the message and store it, then in a command I wanna make it so it replies to that message but how do I make it know the exact message I want it to reply to?
u didn't even copy paste properly
i did and the whole bottom part was errors
@shrewd apex
sigh just learn some python
copy paste again
bro if I knew how to make it on my own do you think I would be here?
use an if statement to check for the message you want, then use message.content in that if statement and use message.reply("Hello word")
so just go and learn some python ;-;
I wanna have an on_message filtering a word in specific. Then I want it so when I do a command my bot replies to the message that it identified
Its in another command
Can someone help me?
ok so basically this is a .json file and say i want to update 6552254 under values and change what it is equal to which is "+0" right now to "+10" then save the json file can anyone help
https://cdn.discordapp.com/attachments/366673247892275221/1010017304928591903/unknown.png
@shrewd apex
whts the cmd
please dont send the same question across multiple channels - this doesnt seem to fall under any topical chat, so claiming a help channel would be better (see #❓|how-to-get-help)
In the on_message, store the message author id & message id in a dictionary whenever ur check is called. Then in your command, if your dictionary has things in it, get that message id and ctx.reply to it
How do I store it in a dictionary so it can work in another command?
1stly You'd use the author as a key in your dictionary then store their message id as a value:
stored_msg = {}
@on_message(message)
if message.content = "hey":
stored_msg[message.author.id] = message.id
Oh
What’s the command in terminal to upgrade to 2.0
pip install -U git+https://github.com/Rapptz/discord.py
No need, 2.0 is officially on pypi
so what do I do
because I need 2.0 for my cmd to work
pip install -U discord
Now to reply to it
@client.command()
async def dls(ctx):
@heavy swift how would I do this?🧐
discord on PyPI is a mirror of the actual package discord.py, and it seems to be out-of-date for now
pip uninstall discord and pip install discord.py and you should get 2.0
same thing
hm i wonder how those packages would have conflicted
already 2.0
Anyone know how I can do this? I already stored it in a dictionary someone pls help
Like this msgs[message.author.id] = message.id
Now I wanna reply to that message in a command
Like I want to do the command and the bot responds to that message
YouTube is a thing
NO it is not
you're using a not exactly up to date version of 2.0 but if it managed to install correctly that's alright, though maybe its better to reinstall with the -U option again
So just do pip install -U discord
If its a thing go to YT
discord.py
2.0 just dropped so id figure most youtube tutorials for dpy are out of date now
if they werent already before...
it just says this
try it with the -U flag
the bot's role is above my highest role tho
in command: ```py
message_id = stored_msg[author_id] # getting message ID via passing it's author ID
message = await channel.fetch_message(message_id) # Fetching message, because for some reason you are storing it's ID, not the message itself
Use your message, eg. reply to it
await message.reply('Not funny + didn't laugh')
Ohhhh
mmm
now you have the proper latest version of dpy
I still get that error
i dont see a typo there so something seems very screwed with your installation still...
Idk man
make sure you restarted your bot or reloaded your cog
reload vsc too ig
yeah a bot restart is necessary if you havent done that
if yes.... the only thing I could imagine of is reinstall discord.py, maybe it'll help
IDE reloading isnt needed
true, it's not an extension
if restarting your bot doesnt work, can you show the output of pip list to check if there's any libraries that might be conflicting with dpy?
Yea so your using the wrong interpretter
oh good catch
In your screenshot where you pip install it goes to your python 3.9 installation
ill kms if there is py**-**cord 😭
And in your error it says python 3.10
So just set your IDE's interpreter to 3.9 or install to 3.10
ok
39
huh, i never thought of what vscode doesnt do when different global interpreters are selected
just use venvs 😫
Love how we've found like 20 errors trying to fix 1 lol
wth is this
🤨
Not snaps 💀
You have 11 days left 😔
btw how to close the app
i closed discord, I exited it completely, I exited both of my discords
nothing removes this
I got temporarily blocked from accessing the api due to trying to fix an error in my code(got rate limited) around how much it would take to go away?
Is this linux? O'
yes
Okay just pkill discord
Are u using replit
Yes
go to the shell, and type kill 1
Discord likes to not close completely on linux because of some settings or whatever
My window manager closes it properly but sometimes it doesn't
oh, i thought it would delete it completely
Pkill (process kill)
btw is there any command to do so?
because i did snap remove discord
Your using snapcraft so
Sounds like snaps 💀
@slate swift now would be a good time to start using the py launcher so you dont suffer mixing up 3.9 and 3.10 again
for example: ```sh
Using your latest version (3.10)
py my_script.py
py -m pip install discord.py
Using 3.9
py -3.9 my_script.py
py -3.9 -m pip install discord.py```
I just use prebuilt binaries from AUR or use app images
Also just as an fyi, fetch_message is an api call so extensive use could get you ratelimited (50 in a second, which is hard to hit alone) but replit, as you may or may not know uses shared ip address, so if 1 person abuses the api, everyone on that ip gets temp banned @grizzled reef
I did but it just sent
Are u still ratelimited?
Let me see
I used snap for long time, now installed it via flatpak, but snap is... annoying... just like windows. and doesnt let me delete it's discord, however when I do flatpak uninstall discord it easily removes the flatpak discord. So... now i dont like snap
It can be used 1 time per 50 secs? ..
😳 imagine yes
It can be used multiple times, but as long as you aren't sending the message like 50 times in a second you're fine
Ohh lmao
but since replit uses shared ips, you could be reaching that threshold a lot easier
Fetching messages are 5/5s
Ok ok
Lmao
Message fetching ratelimits also depend on buckets
So it's pretty much gonna be very hard to get ratelimited just fetching messages alone
Yeah there's also sending the message on top of that
It'll depend on the bucket
If you were to send a message in, lets say CHANNEL1 it'll take a request out of x-ratelimit-remaining for that channel bucket, e.g CHANNELS/:CHANNEL_ID/MESSAGES
Then if you were to send a message in CHANNEL2 it'll be a different bucket, so it'll have a different limit pool
Oh I get you
POV: no
when you need sudo just to remove snaps that speaks a lot
lolmao
Yea it's very simple but makes a huge difference
Imagine trying to share requests over many guilds
now when I do sudo apt remove discord it says me to install it via snap
i think that's just unreachable :(
sudo apt?
i think i found something nice
yes?
I don't know much about ubuntu
And you're bot is in over 300 servers, and you're sending a message to each 1 of those servers each second, you'd get ratelimited a hell of a lot easier but since each server has their own bucket, you avoid that consequence
Am I understanding this correctly
arch 💀
Each server has many buckets
It sent but looks like it did nothing
Buckets are based on the endpoints of the API
The messages endpoint has it's own bucket, a response callback has it's own bucket
ETC, Your wrappers' will form buckets off major parameters
Major parameters being defined from the discord API as channel_id, guild_id and webhook_id
A message doesn't appear or anything, it restarts your terminal but you should be able to start your bot (if you can't then type it again until you can, the alt is to wait abt 20mins)
Oh ok
discord/http.py line 308
return f'{self.method} {self.path}:{self.metadata}'```
Heres what discord py does IG
lmao
got you, I'll research it once I have time
async def test(ctx):
message_id = msgs[author_id]
print("1")
message = await channel.fetch_message(message_id)
print("2")
await message.reply("fck")
print("3")``` this command seems to not be running
I do ;test
author_id isn't defined
😂
ctx.author.id
Hmm
But its the author from the dict
that variable isn't defined though, you're accessing the key in the dict by using ur own id
because that key is the same as ur id
So how should I do it then?
Guys i saw many people have a folder called utilis in their discord bot . Whats use of that?
just replace author_id to ctx.author.id
Usually it's just to house functions/classes which can be used in other parts of the code to make things easier
@grizzled reef How do you have your on_message and dictionary setup btw, just so I know there's no issues there
Hm it didnt run, let me send full
I use view as
Class MyView(view)
@button.... {Stuff}
@bot.command()
{Stuff}
view = MyView()
Await ctx.send("ok" , view =view)
Is this good way or i missing some batter way ?
@client.event
async def on_message(message):
msg = message.content
if "not" in message.content:
print("hi")
msgs[message.author.id] = message.id
@client.command()
async def test(ctx):
print
message_id = msgs[ctx.author.id]
print("1")
message = await channel.fetch_message(message_id)
print("2")
await message.reply("fck")
print("3")```
correct, but it looks like you want to reply regardless of the channel
Looks weird
Ye
I mean its only gonna be in ine channel
One*
I also want to do it.
So what should I add in that?
Tell me any common thing that's people mostly use
Yeah true, I'm not sure how using that command in a separate channel would turn out but ctx.fetch_message(message_id) would work
The command aint running
It dont send the prints
OH
oh i should've caught this lol you need to process
Oh yeah right below the event
yep
have you considered just storing message objects directly from on_message? its easier to reply to since you dont have to care about fetching, but if you need to persistently store the channel+message id then its a bit harder to handle both data sources at once
Would love if discord.py added a cache driver class so you could, for an example just write an async redis cache
Well you would need to serialise which is no big problem, but discord.py objects are at best half serialisable for some reason iirc
Plus you could also add a weakref cache instead of the normal one for memory efficiency
I might try that
async def on_message(message):
msg = message.content
if "not" in message.content:
print("hi")
msgs[message.author.id] = message.id
await client.process_commands(message)```
shouldnt be in the if statement
Finally
nice u got it to work?
Yeah im testing some other stuff
What client.process_commands dose ?
It lets you use other commands without having on_message have all the spotlight
I believe you can just use @bot.listen() without having to worry about that
Ohh
Will take more cpu
there any place that lists all the global discord emojis? keep getting sights that want to give you emojis...
(other then discord itself, kinda hard to get a good look at them all)
thanks!
Guys how to fix this cogs error?
There's an issue with your eval cog, do you load cogs in try-except block
Ye
async def setup_hook(self):
print("Loading cogs . . .")
cogs = []
try:
for f in os.listdir("./cogs"):
if f.endswith(".py"):
cogs.append("cogs." + f[:-3])
for cog in cogs:
await bot.load_extension(cog)
print(f"{cog} was loaded")
except Exception as e:
print(e)
I did this
What's the point of handling cog loading exceptions anyway, all components must function
Quick way is except ...: raise e but you'd better remove the try-except surrounding at all
mmm i'm trying to do slash commands ( / ) because i guess that's the way to do them nowadays? but when I try and use them in DMs with the bot i get this
completely uninstalled snap, if now rich presence won't work ill... idk what ill do
how....
Any help?
what are you trying to do?
Give a user role on button click
It’s a persistent view btw*
I guess something out of this list:
- Your bot doesn't have these permissions (need at least one to work):
Administrator, Manage Server, Manage Roles - Your bot's role is lower than your's in hierarchy
if not that, send the code
My bot’s role is having admin + manage role perms and is above my role

k wait
class PersistentView(discord.ui.View):
def __init__(self):
super().__init__(timeout=None)
@discord.ui.button(emoji=":blackOne:", style=discord.ButtonStyle.grey, custom_id='persistent_view:green')
async def green(self, interaction: discord.Interaction, button: discord.ui.Button):
button.disabled=False
try:
eman = interaction.user.guild.get_role(960601299529904218)
if eman in interaction.user.roles:
await interaction.user.add_roles(eman)
embed = discord.Embed(description="You'll shortly recieve <@&960601299529904218> role.", color=0xffffff)
await interaction.response.send_message(embed=embed)
else:
if eman not in interaction.user.roles:
await interaction.user.remove_roles(eman)
embed = discord.Embed(description="Removed <@&960601299529904218> role from you.", color=0xffffff)
await interaction.response.send_message(embed=embed)
except discord.Forbidden:
await interaction.response.send_message("I don't have enough permissions to give you the role oryour highest role is above my role.", ephemeral=True)
- this if (screenshot) is completely useless
- You are doing exactly the opposite of what you want to do (i think so): if user HAS a role it will GIVE it to him, and if the user DOESN'T HAVE a role it will REMOVE it
I’m blind 💀
lol
Still I’m getting this :
I don't have enough permissions to give you the role oryour highest role is above my role.
How can I remove view from a message?
Do view=None

Or i want to turn of button of that message
What you trying to say?
No
Need to pass content ?
if you want to remove the button then View.remove_item(), if disable it, then button.disabled = True
and if remove view completely then yes .edit(view=None)
Ohh k k
man discordpy is so convoluted, spending so much time trying to figure out permissions issues, patterns using bots/cogs -.-
what's the problem with discord.py? If you give bot wrong permissions, discord itself will deny you to execute some action, that's not API wrapper problem
trying to use slash commands, dont know if discordpy supports them?
it does
this is what I'm getting
#discord-bots message
dont know what permission that requires to get a list of slash commands in a DM
I'll check that stuff out tho thanks
@silk fulcrum
no idea why
what does self.tree.copy_global_to supposed to do here?
async def setup_hook(self) -> None:
await self.add_cog(MySlashCog(self))
self.tree.copy_global_to(discord.Object(id=123456789098765432))
await self.tree.sync()
read the explanation part below the example
shock: owner of gist replies
lmao
I tried reading the explanation, I dont see anything exactly on that, but I might be looking at the right area -.-
oh, i was reading explanation for cog
thus why I said might not have been in the right area heh
ufff that's why it is recommended not to skip the reading part
eh I try and read as much as I can, but need to read the parts that are pertinent to ensure I'm looking at the right solution for my problem heh
kinda hot and frustrated as it is heh
yeah most of the explanation is in the SlashClient example so
@grizzled reef why without fetch
skill issue
fine, tinme to bel;dn back into the shadows
professional phyone typo moment
Guys i want to make such that all the commands can be used by the bot owner and i can provide it ids even the owner have member role it can use all command
How can I do that?
you need a check function
have a list containing all the ids that u want to have perms
If you use check decorators such as @has_permissions you can customise them and add something like if ctx.author.id == bot.owner_id: return True
I saw many people make a permissions.py file and make owner function. I also want that how to make?
what 😳
what does that owner func do
That allows the owner of bot to use all commands in all server even they have low role