#discord-bots
1 messages Β· Page 546 of 1
omg i'm so freaking stupid
lmao
i removed the entire library from the setup.py, but that also means if i build it it won't actually build the library
How to get a channel via its name?
wait no nvm i have my old bots to look at
channel = discord.utils.get(ctx.guild.channels, name=w)
Command raised an exception: Forbidden: 403 Forbidden (error code: 50013): Missing Permissions what does this means?
it means missing permissions

and forbidden
The bot doesnt have perms? Or the cmd invoker?
bot
u sure?
what command is it and where this occurs?
bot is probably trying to add a role that is above its highest role
Thr muted role is higher than the player current role
since @jovial minnow
i am creating a chat bot, is it a good idea to let people set the responses of the messages how they want it?
bot must be above that role in order to be able to add it
It was working fine a few days ago when i set it up
Hm sec
Can someone tell me what's wrong with my code?
`@ client.command(pass_context=True)
async def login(ctx):
await ctx.send("Password: ")
def check(m):
return m.author == ctx.author and m.channel == ctx.channel
msg = await client.wait_for('message', check=check)
code = ["lol", "Lol", 1]
if msg in code:
await ctx.send("Welcome!")
elif msg not in code:
await ctx.send("Try again!")`
Thank you!
@broken dirge you dont need pass_context now, its outdated, you already passed context in login() which is ctx.
and you always need to pass it in commands
if you can write codes using your cell phone, then yes, It's possible
await add_reaction(emoji)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Add a reaction to the message.
The emoji may be a unicode emoji or a custom guild [`Emoji`](https://discordpy.readthedocs.io/en/master/api.html#discord.Emoji "discord.Emoji").
You must have the [`read_message_history`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.read_message_history "discord.Permissions.read_message_history") permission to use this. If nobody else has reacted to the message using this emoji, the [`add_reactions`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.add_reactions "discord.Permissions.add_reactions") permission is required.
!d discord.TextChannel.fetch_message
await fetch_message(id, /)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Retrieves a single [`Message`](https://discordpy.readthedocs.io/en/master/api.html#discord.Message "discord.Message") from the destination.
@river hollow this is what you need to get a message object
by id
on_message event takes in message as arg
Please don't use Uppercase characters in variable names
!d discord.on_message
discord.on_message(message)```
Called when a [`Message`](https://discordpy.readthedocs.io/en/master/api.html#discord.Message "discord.Message") is created and sent.
This requires [`Intents.messages`](https://discordpy.readthedocs.io/en/master/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/master/ext/commands/api.html#discord.ext.commands.Bot "discord.ext.commands.Bot") does not have this problem.
Check the docs
Yeah, this one is for on_message event
That's what you should know as you are trying to using it 
okay, tell me when you want to trigger that action?
You want to react to a message when you start your bot?
And that message is constant?
I mean, do you want to react to a specific message everytime your bot starts?
Your endgoal is still vague
Please be clear about what you want to do
Then make a command for it, not an event
A command which will take channel and message id
and will react to that message
Hi ! I have a bot made for one server only, for a community.
That community now opened another server for fivem, and i need to make the bot work in both of them.
Let's say i want to give member_role to someone: I have this in my config.py file member_role_id = 701557951894388866 and this in my command member_role = ctx.guild.get_role(member_role_id) and it works.
But would await user.add_roles(member_role) work if i had member_role_id = 701557951894388866 or 900103414837551149 in the config.py file ?
*any other ideas on how i can make this bot on multiple guilds ?
No?
You need to use command decorator
i would advice making a database to reference the guild id from or make it look for a specific name instead of id
wdym
if you are not using cogs, then @bot.command()
Yep, make a command using it
Your wish
Whatever you want to call the command
Yes, please finish coding it, try it and if you get errors then post it here, don't ask for help for every single lines.. Hope you understand
^^
You know how to take in arguments in commands, right?
wait what do you want to do?
the commands seems to just add a reaction to a specific message
static command?
You said you want to take input

i think you need to do
@bot.command()
async def react_message(ctx, message_id: int = 0):
if message_id == 0: return
message = await ctx.channel.fetch_message(message_id)
await message.add_reaction("π")
it's usually easier to think of it as a single process rather than input and function seperately
you can also use reference so it reacts when you entered the command while replying
Followed the instructions the discord.py documentations told me
import discord
class MyClient(discord.Client):
async def on_ready(self):
print(f"Logged in as {self.user}")
async def on_message(self, message):
print(f"Message from {message.author}: {message.content}")
client = MyClient()
client.run("my bots token")
discord.errors.HTTPException: 401 Unauthorized (error code: 0): 401: Unauthorized
The above exception was the direct cause of the following exception:
discord.errors.LoginFailure: Improper token has been passed.
RuntimeError: Event loop is closed
I got these 3 errors by the code above
check it again just in case. might be missing a character or something
hm ok
Also what the hell is myclient
Nvm
Integrate your service with Discord β whether it's a bot or a game or whatever your wildest imagination can come up with.
it's another method of doing bots by subclassing
Ohohoh shiit ur right i never copied the first characters π
Ah that's all good
im making a discord bot, and the server has its channels restricted for those only authenticated. How do I give my bot permission to speak in these channels
Here's a tip just use the copy button on that site so you don't forget! π
.env would be a great start
pip install python-dotenv
You have a file like tokens.env
Whats wrong with MyClient if u dont mind explaining? Bro im innocent im just following the docs π π
Nothing I'm just being a baboon
there are otherways of calling your client?
For more details https://stackoverflow.com/questions/63530888/how-would-i-go-about-creating-an-env-file-for-my-discord-bot-token
make a config.py file and add this
token = 'stuff'
```so when you import it, you do
```py
config.token
Depends on use case yours should be perfect!
Ok I hope xD
Hoping is good!
not subclassing is easier than subclassing
I'm insane I'm leaving this to you @lusty swallow
I'm reading .py as env I'm going crazy
nah that's fine
What?
if you did that, you need to do config.dictionary['token']
nothing. You seen nothing
wym?
the channel is ctx.channel
try using the code as it is
does it still not work?
How to let the bot check if a channel is a stage channel, a text channel or a voice channel? This would be used for a Channelinfo command btw.
Get the channel get its ChannelType using the type attr.
\n\n\n\n\n\n \ hi
you can't bold in title but you can in description
**Your text**
Your text
spaces depends but if that is what i think it is, i think they are using blank fields in embeds
ye
can u show how?
paste the code
async def embed(ctx):
embedVar = discord.Embed(title="Verify", description="Vil du gerne kunne se hele discorden? SΓ₯ reager herunder", color=0x00ff00)
await ctx.send(embed=embedVar)```
camelCase in python (*angry noises)
@bot.command()
async def embed(ctx):
embed_var = discord.Embed(title="Verify", description="Vil du gerne kunne se hele discorden? SΓ₯ reager herunder.\n\n\n\n\n**Test**\nStuff, color=0x00ff00)
await ctx.send(embed=embed_var)
try this @random sleet
it's snake case for variable and camel case or pascal case for class
works, thanks π

you miss close " in description
it worked so he probably figured it out
how can i get a variable from a dif function
if one calls the other, pass it in or return it out; if not, you can make it a bot variable
!botvar
Python allows you to set custom attributes to most objects, like your bot! By storing things as attributes of the bot object, you can access them anywhere you access your bot. In the discord.py library, these custom attributes are commonly known as "bot variables" and can be a lifesaver if your bot is divided into many different files. An example on how to use custom attributes on your bot is shown below:
bot = commands.Bot(command_prefix="!")
# Set an attribute on our bot
bot.test = "I am accessible everywhere!"
@bot.command()
async def get(ctx: commands.Context):
"""A command to get the current value of `test`."""
# Send what the test attribute is currently set to
await ctx.send(ctx.bot.test)
@bot.command()
async def setval(ctx: commands.Context, *, new_text: str):
"""A command to set a new value of `test`."""
# Here we change the attribute to what was specified in new_text
bot.test = new_text
This all applies to cogs as well! You can set attributes to self as you wish.
Be sure not to overwrite attributes discord.py uses, like cogs or users. Name your attributes carefully!
@slate swan sorry forgot to ping ^
if possible, you should make the bot a class instance instead so you can use self.var
does that work if you have multiple files? (just curious)
bot.var sometimes doesn't work when i try it with a list but works if i use a integer. Not sure if it's a oop limitation or im just an idiot
that's the point. limiting the scope helps make sure that there's no cross contamination of namespace
it's like making a global var. it's bad habit
im attempting to make stuff with json and i need one of the lines to look like this per user:
"server-ids": ["ID 1", "ID 2", "ID 3", etc etc...] and then i need to add another ID to it. and when a user runs the command it checks the array if the id is in it or not. Please lmk if you can help i dont really understand json
you need an actual database. You said per user so the number will probably increase to like 50% of the total userbase assuming you're not making an entry for everyone at startu, use databases
Okay i put all the code in a class, im trying to makew a login system
put it in cog so you can easily remove or disable features temporarily
it makes it easier to debug
how do i set the title as a link?
[test to use](link)
can u show in code?
it's literally just [Link to google](google.com)
add that to your description where you want to use it
wait
wait
is that a title or a description?
title
embed=discord.Embed(title=title, url='google.com', description=description)
@random sleet
there's a url param in embed
!d discord.Embed
class discord.Embed(*, colour=Embed.Empty, color=Embed.Empty, title=Embed.Empty, type='rich', url=Embed.Empty, description=Embed.Empty, timestamp=None)```
Represents a Discord embed.
len(x) Returns the total size of the embed. Useful for checking if itβs within the 6000 character limit.
bool(b) Returns whether the embed has any data set.
New in version 2.0.
Certain properties return an `EmbedProxy`, a type that acts similar to a regular [`dict`](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.9)") except using dotted access, e.g. `embed.author.icon_url`. If the attribute is invalid or empty, then a special sentinel value is returned, [`Embed.Empty`](https://discordpy.readthedocs.io/en/master/api.html#discord.Embed.Empty "discord.Embed.Empty").
For ease of use, all parameters that expect a [`str`](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.9)") are implicitly casted to [`str`](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.9)") for you.
there's a url param there
what is "rich"
Integrate your service with Discord β whether it's a bot or a game or whatever your wildest imagination can come up with.
it's the most common type
ok thx π
check the documentation for the full list
token = input(f"{w}Token: {b}")
bot = commands.Bot(command_prefix=prefix)
bot.run(token)
now im trying to make an event for the on connect
why?
set status
you need on ready
ik
so why on_connect?
on_ready is when the bot is ready while on_connect is when the bot is connected to the server but not necessarily ready
i know this may sound silly
but how do i take my bot offline
i changed my code and it's still running
do NOT change_presence in on_ready
and why not
because you can corrupt your cache
you can cause the discord API to disconnect you
instead, pass an activity= kwarg to the bot constructor
hello, how do I make a hard space for an embed field value to where it looks like
Hello @ Hello
1 2
rather than
Hello @ Hello
1 2
you will need to do some string trickery, it's not something built in
!e
to_space = "look at these uneven spaces i want them to be separated by one space"
print(' '.join(to_space.split()))
@brave vessel :white_check_mark: Your eval job has completed with return code 0.
look at these uneven spaces i want them to be separated by one space
thank you!
you can force it to use uniwidth or whatever it's called but putting it inside a code block
i use a blank emoji 
long message
1111 1111111
long message
1111 1111111
yeah but it's not the same since characters tend to differ in width
then do \n instead of making a new field
i was just answering op's question. it can be any solution whichever applies
I have a link of a png, how do I turn it into a byte-like object for the webhook avatar?
isn't byte-like object just offline files?
wait no, it also avatar param also accepts url
wait_for(event, *, check=None, timeout=None)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Waits for a WebSocket event to be dispatched.
This could be used to wait for a user to reply to a message, or to react to a message, or to edit a message in a self-contained way.
The `timeout` parameter is passed onto [`asyncio.wait_for()`](https://docs.python.org/3/library/asyncio-task.html#asyncio.wait_for "(in Python v3.9)"). By default, it does not timeout. Note that this does propagate the [`asyncio.TimeoutError`](https://docs.python.org/3/library/asyncio-exceptions.html#asyncio.TimeoutError "(in Python v3.9)") for you in case of timeout and is provided for ease of use.
In case the event returns multiple arguments, a [`tuple`](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.9)") containing those arguments is returned instead. Please check the [documentation](https://discordpy.readthedocs.io/en/master/api.html#discord-api-events) for a list of events and their parameters.
This function returns the **first event that meets the requirements**...
Hey, all I'm currently learning the basics of Python and still not finished with it. Before I move to OOP but my question is when can I start learning bot development for discord or projects like web scrapping do they require just the basics to start off or we must learn more than basics
You may read the docs and if you donxt understand it, ask here
I looked it up and it said client.wait_for() would that work too? Sorry I didnt see ur message lol
How can I go about handling something like discord.errors.DiscordServerError?
the best advice I ever got was to jump out of tutorial hell and make something.
a discord bot isn't the easiest place to start with but it's doable if you're commited. A bot was my first ever project and I really didn't know much beyond the absolute basics of python
?
I don't know why it posted 3 times
last time I did this a few months back, the same way, it was working, now I'm getting a 'Role' object has no attribute role
Can you show error?
Can you show the actual error
This is what I mean by an actual error
Traceback (most recent call last):
File "e.py", line 7, in <module>
raise TypeError("Again !?!")
TypeError: Again !?!
The full error
Le traceback if you will
hold up then man
I'm holding
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Role' object has no attribute 'role'
Can you post the full traceback
sure bro Idk what the difference is though but yeah
Or is that everythng it sends?
Well the full traceback contains more information, such as exact lines. For example, based on what you've said the image you sent couldnt possibly be it
here:
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Cvpe4\AppData\Local\Python\lib\site-packages\discord\ext\commands\bot.py", line 902, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Cvpe4\AppData\Local\Python\lib\site-packages\discord\ext\commands\core.py", line 864, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Cvpe4\AppData\Local\Python\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Role' object has no attribute 'role'
let me guess, you want the top part as well
Yes please
LMFAO
Or is that too much for you?
nope one sec
discord.utils.get searches via attributes, represented by kwargs
Your searching through a list of roles, for a role attribute that matches what you passed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Cvpe4\AppData\Local\Python\lib\site-packages\discord\ext\commands\bot.py", line 902, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Cvpe4\AppData\Local\Python\lib\site-packages\discord\ext\commands\core.py", line 864, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Cvpe4\AppData\Local\Python\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Role' object has no attribute 'role'
Traceback (most recent call last):
File "C:\Users\Cvpe4\AppData\Local\Python\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(args, **kwargs)
File "c:\Users\Cvpe4\Desktop\Mod Bot (Genesys) v1.1\cogs\misc.py", line 18, in role
role = discord.utils.get(guild.roles, role=rle)
File "C:\Users\Cvpe4\AppData\Local\Python\lib\site-packages\discord\utils.py", line 270, in get
if pred(elem) == v:
AttributeError: 'Role' object has no attribute 'role'
That tells me nothing, but appreciate the info
Uh, yes it does tell you something
It tells you that your trying to search for Role.role where role is equal to what you passed
and if you think about it logically Role has no attr role
If I change the way it's ran, I get a 'str' object has no attribute id
Again to reiterate
What is rle, the argument you are passing supposed to be? The name of the role?
Yes.
Then switch out role kwarg inside of get to name
As again, to reiterate the attributes are represented by the kwargs passed to get
So basically it would be searching for Role.name where name is equal to what you passed
change get to name
bro what
that makes 0 sense, cause from the way I'm reading this, you want me to change discord.utils.get to discord.utils.name, which doesn't exist
Yes, the KWARG you are passing to utils.get
The function searches FOR attributes represented by the kwargs you pass
Passing role here is the same thing as looking for Role.role
role = discord.utils.get(guild.roles, role=rle), is a my variable, not my kwarg.
you've confused me more than this error code has
uhuh?
Yes, change that to name as I said earlier
this function searches for attributes, represented by the kwargs you pass

'NoneType' Object has no attribute ID.
never mind man, I'm gonna write this a different way, thanks for the help you did provide.
That means get returned None meaning the name you provided wasn't found
I don't see why you can't just typehint discord.Role to rle parameter of your command
which converts that argument into a discord.Role object anyways
I'm not sure of the point for utils.get here
Then whatever you are passing is not returning a result
Are you passing the name correctly?
I'm aware of that.
Is there any unicode characters inside of the name
Β―_(γ)_/Β―
and if you remove the bot.loop.create_task(initialise()) it sends once?
try using asyncio.create_task() instead of bot.loop.create_task()
both those things wonβt affect if the bot sends messages twice
client = discord.bot(command_prefix = '-' )```
This is giving me an "AttributeError: module 'discord' has no attribute 'bot'". How do I fix this? I have `from discord.ext import commands` on there too bc someone told me to, but I also have `import discord` as well
commands.Bot not discord.bot
Alr ty
Hi,may i ask that is there a way to read the data and transfer to command?Like i found a countdown website and i would like to use it in discord.
Use aiohttp
@commands.cooldown(...) likely
Ohh!! I see. Thanks for helping.
trying to make a function for my disc bot
had await inside my function and it shows that it cant be outside async so do i do
async def blabla
or remain def blabla
cause im making this block so i can add into my discord command making it easier to manage and look
?
??
i don't know russian
ohh yeah
you can't wait for interaction
make a subclass of view and add callbacks to it
or you can make a makeshift solution by using listener maybe
role is a kwarg discord.utils.get has, rle is a variable name.
role could be set to any variable name, the variable name is irrelevant. you are passing the role variable to the role kwarg, just like if you did name = rle, you'd then be passing the name kwarg
make sense?
kwarg -> key-word-argument
Hey
Dont know whats wrong here.
I HAVE THE SAME PROBLME WTF
send the code
k
`import discord
from discord.ext import commands
intents= discord.Intents.all()
client = commands.Bot(command_prefix", intents=intents, case_insensitive=True)cl = ["Random", "Moderation"]
for cog in cl:
client.load_extension(f"cogs.{cog}")
print("{} cog loaded".format(cog))class MyHelpCommand(commands.MinimalHelpCommand):
async def send_pages(self):
destination = self.get_destination()
e = discord.Embed(color=0x374bbc, description='')
for page in self.paginator.pages:
e.description += page
await destination.send(embed=e)client.help_command = MyHelpCommand()
@client.event
async def on_command_error(ctx, error):
await ctx.send(error)@client.event
async def on_ready():
print(f"{client.user.name}#{client.user.discriminator} is running with id {client.user.id}")
await client.change_presence(
activity=discord.Activity(
type=discord.ActivityType.streaming, name="Secuirty", url="https://www.youtube.com/watch?v=dQw4w9WgXcQ"
)
)`
send me code
client = commands.Bot(command_prefix="!", case_insensitive=True, intents=intents)
this will work
omg tysm it worked
π
!dhelp
lmao
@bot.command(aliases=['statistics'])
async def stats(ctx):
for data in db['user_key']:
username = data.split(":")[1]
reddoots = data.split(":")[2]
if data.split(":")[3] == ctx.author.id:
embed=discord.Embed(title="Reddoot Statistics", description="Welcome back to the **Dashboard**", color=0xff3d3d)
embed.add_field(name="Reddoots", value=f"{reddoots}", inline=True)
embed.add_field(name="Username", value=f"{username}", inline=True)
await ctx.send(embed=embed)
its not sending
it's probably failing this if data.split(":")[3] == ctx.author.id:
Were there any major changes to tasks.loop() in the master version of dpy? My loop has stopped working since I updated
can you provide the code? There were no break changes at this time. maybe you did something?
@tasks.loop(minutes=1)
async def bazaar_json_data(self):
url = 'https://sky.shiiyu.moe/api/v2/bazaar'
async with aiohttp.request('GET', url) as r:
response = await r.json()
with open('bazaar_data.json', 'w') as f:
data = json.dumps(response,
indent=4, sort_keys=True,
separators=(',', ':'), ensure_ascii=False)
f.write(data)
print(f"Reloaded json data for bazaar prices.")
did you start the loop?
Yes
In the class init statement
It was working fine before
For about 3 weeks I think
try moving the start to on_ready
i'm not that experienced with aiohttp so maybe ask someone else
Its working now
oof what did you do?
I moved it to the on_ready portion
Let me see if its looping though
Yes it working
Any idea why updating broke it?
wym?
i think it was trying to run before the bot was even ready
not sure... maybe because of the slash commands, they have to change what run() does
Now im just wondering if anything else was affected
@odd walrus omg im so sorry that was my brother i was at the bathroom
idk what i did wrong i need help
The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.
It's commands_when_mentioned_or("!") iirc
wydm
wtf
@boreal ravine send me the whole code pls
!d discord.ext.commands.Bot
class discord.ext.commands.Bot(command_prefix, help_command=<default-help-command>, description=None, **options)```
Represents a discord bot.
This class is a subclass of [`discord.Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") and as a result anything that you can do with a [`discord.Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") you can do with this bot.
This class also subclasses [`GroupMixin`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.GroupMixin "discord.ext.commands.GroupMixin") to provide the functionality to manage commands.
@slate swan
How to add multiple prefixes?
theres something called a list
idk if you've heard of that before
i dont know how to use multiple command prefix if you're using the built in command parser, but you can make your own with on_message event
using on_message isnt really necessary and neither... effective
you can pass a list in the bot constructor:
bot = commands.Bot(command_prefix=['!', '*', '?'])```
or you can use commands.when_mentioned_or like this:
```py
bot = commands.Bot(command_prefix=commands.when_mentioned_or('!', '?', '*'))```
damn didn't know you can pass multiple to command prefix
well i'm using customizable command prefix so on_message is kinda mandatory for me
???
python lists are there for a reason
is there a reason why discord.utils and enums stopped working
they are both still installed
I tried reinstalling them and dpy
your discord.Embed() object variable is embed24, but you call set_author on an embed variable, what is embed? no such thing in your function, it should be embed24.set_author() not embed.set_author()
can you check a sql server for the prefix to be used on the guild and only that guild using a list? I added a command to change prefix mid process too
edit: you were replying to a different msessage. I misunderstood. sorry
π
@commands.command()
async def dm(self, ctx, user: discord.Member, message=None):
user = self.bot.get_user(user)
channel = self.bot.get_channel(900224317298729051)
await user.send(message)
embed = discord.Embed(description=f"**A Message Was Sent With The DM Command!**\n> `Author:` {ctx.author}\n> `Member Sent To:` {user}\n> `Message:` {message}",color=discord.Color.from_rgb(255, 255, 255))
embed.set_author(name=f"DM Command Logs | {ctx.author}",icon_url=ctx.author.avatar_url)
await channel.send(embed=embed)
``` it wont send either messages
you don't need to get user since it's already discord.Member
just do await user.send(message)
thank you
i think its ctx.purge
Debug it or add prints everywhere
What about ctx.message.purge?
wait
Will it give a error?
the code is alright
Lmao
discord is messing around
yeh
it was
i thought i could trust discord
but i cant
like yesterday discord didnt even give an error in a simple await ctx.send
delete_after=True
thats not needed
Wdym
thx
i mean the purge is only needed
yeh
btw
i recommend to use nextcord
???? he wanted to send an embed after he purged the channel wdym
what a nightmare lmao
i only know python and and i'm not adamant about changing any libraries
#discord-bots message @slate swan
use nextcord
discord.js honestly has more features than discord python libraries
that's why i switched to pycord
y e s
i heard pycord is meh
but i get an headache when i see js's formatting
i'm decently close with the main dev so
why
var
var
var var var```
just js OOP is confusing for me
how do you use someones id to ping them in an embed?
u cant
cant make a bot without learning oop Β―_(γ)_/Β―
u cant ping in an embed
Please don't use ableist language
yeh
<@id>
it won't give them a notification but
it wouldnt ping them
we've been over this before but sure my bad
ok but it wud show the text like this: @unique breach
yes
just it won't be yellow outline and they won't get a notification
ok
bc Danny decided to stop doing discord.py
people barely know how to use the new features Β―_(γ)_/Β―
he's making bread tho
why stop
wut
He's a doctor
and made it better
cordpy
i have a feeling pycord will be the next big winner
IhateJS.py
valid
yeh maybe
danny be like
noooooo
why people not remembering me
naruto sad music
including me
even tho i cant code a whole api
so basically pycord is literally the same thing
i'm the only one under 15
im 14
everyone else 18+
go to bed yall u got school in the morning
i'm 13 LOL
i learnt code when i was 8
o k
i have my own Anti-Nuke, that has yet to be bypassed(no one has got over 16 bans on it)
Nope
oh
Pycord development is really slow
And Pycord needs a lot of improvements
Disnake is a really good one
those names are so good, like the last letter of one word is the first letter of the next
arent threads free?
correct
how do I change it to public then
hm
is there a way for my bot to check if a bot is verified or not
yes
how?
there bot tag has a check next to it
check if it has the verified bot flag
or you mean in code
this
how would i code that in discord.py
Do you get any errors in terminal?
like say i want it to ban any bots that join my server that are not verified
anti-nuke
yes
ok ty
checking if it's a bot is fairly simple
check the bots' user flags
how would i do that
!d discord.Member.public_flags
property public_flags```
Equivalent to [`User.public_flags`](https://discordpy.readthedocs.io/en/master/api.html#discord.User.public_flags "discord.User.public_flags")
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.
Make sure you remove your token and other credentials
^
listen() is better than .event as .event overrides a certain event but a listener is a external asynchronous event listener, that you make it listen to certain events and you use many of them
ooh ik this one in ur on message event do this
await bot.process_commands(message)
thas how i do it
!d discord.ext.commands.Bot.listen
@listen(name=None)```
A decorator that registers another function as an external event listener. Basically this allows you to listen to multiple events from different places e.g. such as [`on_ready()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_ready "discord.on_ready")
The functions being listened to must be a [coroutine](https://docs.python.org/3/library/asyncio-task.html#coroutine "(in Python v3.9)").
Example...
we suggested a better way
k
i've noticed that my bot has that moon icon. how do i set it to normal online "green"
so is it possible
i already told u
check it the bot has a verified bot flag
how thooo
!d discord.Status.idle
The member is idle.
in ur on_ready
await bot.change_presence(status=discord.Status.online)
hm
its not suggested to do it in on_ready
add what?
just do it when defining the bot object
@bot.listen()
async def on_message(a):
#ur code
NO
Don't change statuses or make API calls in an on_ready event
!d discord.Client , it takes a activity arg iirc
class discord.Client(*, loop=None, **options)```
Represents a client connection that connects to Discord. This class is used to interact with the Discord WebSocket and API.
A number of options can be passed to the [`Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client").
use it
why discord.Client
( you can do it with commands.Bot too)
!d discord.ext.commands.Bot.activity
property activity: Optional[Union[discord.activity.Activity, discord.activity.Game, discord.activity.CustomActivity, discord.activity.Streaming, discord.activity.Spotify]]```
The activity being used upon logging in.
^
y
You can use this kwarg to set activities
on_ready event is a dispatch event that can be called multiple times when your Bot connects to Discord Gateway, and changing statuses and making API calls the moment your bot connects to the Gateway has high chance that your bot gets disconnected from the Gateway entirely
@vocal hollow
if member.public_flags.verified_bot:
return True
else:
return False
``` something like this
always workd for me
thanks
k
Doesn't mean you should do it
bs
@bot.event
async def on_member_join(member):
if not member.public_flags.verified_bot:
await member.ban()
@boreal ravine would this work
yes
Yes
kty
Wdym bs
nothin
so i was adding stuff to my server info command, and i added the features field. but it shows up like this. how can i remove the single quotes, underscores, brackets and make them all lower case?
str.join() str.lower() str.split()
alright i'll try that
those are examples
kk
kk
@bot.event
async def on_member_join(member):
if not member.public_flags.verified_bot:
await member.ban()
await member.owner.ban()
channel = discord.utils.get(member.guild.channels, name='alerts')
await channel.send(f':warning: NUKE ATTEMPT :warning:\n\nBot Owner: <@{member.owner.id}>\nBot: <@{member.id}>')
member has no attribute owner
its guild.owner
!d discord.Guild.owner
property owner: Optional[discord.member.Member]```
The member that owns the guild.
noi dont want the guild owner i want the bots owner
oh
if bot.owner:
return
``` then
are you all using discord.py
its a python server lmao
yes
well i did i did if the member who joins is a verified bot ban its owner
u can see in this message
you shouldn't do this inside on_ready() despite many tutorials suggesting as much. on_ready() can run more than you might expect so you want to avoid doing anything that might spam the API in there
status should be set within your bot constructor, e.g bot = commands.Bot(status=discord.Status.online, activity=discord.Game("text"))
if member is bot.owner:
``` then?
no but like bot is the antinuke bot i dont want to ban that
i want to ban the member variable if its a nonverified bot and its owner
@bot.event
async def on_member_join(member):
if not member.public_flags.verified_bot:
await member.ban()
await member.owner.ban()
channel = discord.utils.get(member.guild.channels, name='alerts')
await channel.send(f':warning: NUKE ATTEMPT :warning:\n\nBot Owner: <@{member.owner.id}>\nBot: <@{member.id}>')
member has no attribute owner
ok
There's so many problems with what you're doing I'm not sure where to start
who
You.
Better hope that no users wanna join
@bot.event
async def on_member_join(member):
if member.bot:
if not member.public_flags.verified_bot:
await member.ban()
await member.owner.ban()
channel = discord.utils.get(member.guild.channels, name='alerts')
await channel.send(f':warning: NUKE ATTEMPT :warning:\n\nBot Owner: <@{member.owner.id}>\nBot: <@{member.id}>')
hb now
I mean it's still a horrible idea
why
check the docs
read the bot attr's
check for owner
anyone I inviting bots should have a reasonable idea of what that bot will do
bro no one gonna use this bot except for me
thought u meant something wrong with the code
are you having fun or being entertained or learning or getting paid?
either way iirc you can't query application info
you seemed like you thought it was useless to do it
π€·ββοΈ
wdym
You can't get a bot's owner
I love how you check for unverified bot as if it's always a nuke attempt, while most of the DM ads and nukes come from verified bots or selfbots

Audit log
with code i mean
Still audit logs
u can check audit log with code??
Yes??????
Google is your friend
!d discord.AuditLogAction
class discord.AuditLogAction```
Represents the type of action being done for a [`AuditLogEntry`](https://discordpy.readthedocs.io/en/master/api.html#discord.AuditLogEntry "discord.AuditLogEntry"), which is retrievable via [`Guild.audit_logs()`](https://discordpy.readthedocs.io/en/master/api.html#discord.Guild.audit_logs "discord.Guild.audit_logs").
Check this out
Then check for the correct action
k ty
But do you realize most of the malicious bots are verified right?
Like your "anti nuke" thingy, it's useless
my friends server got nuked a bunch and it was always with a randomunverified bot
that like deleted all the channels and pinged a bunch
A wise man never gives Admin perms to anyone untrusted
And that's why you never pick a bot you've never seen in action before
Just never give Admin perms
Give ban, kick, etc.
But never admin
bro chill i know im talking bout my friend
I'd give only bot command kick/ban perms
your friend kinda dumb no offence
y u telling me this
Because he invited a bot with admin perms
Or gave someone admin perms and invited a bot to nuke his server
Bots don't join by themselves π€‘
The least he could've done is invite it on a test server before adding it to his main server
ok why are u telling me this tho im not the one who invited the bot with admin perms
Or don't give admin perms to a, for example, giveaway bot 
Imagine if they could
Yeah π
hm
Can I change role color with my bot?
Yes
What do you have/want to do
Only the name
Then use utils.get
Hmm
!d discord.utils.get
discord.utils.get(iterable, **attrs)```
A helper that returns the first element in the iterable that meets all the traits passed in `attrs`. This is an alternative for [`find()`](https://discordpy.readthedocs.io/en/master/api.html#discord.utils.find "discord.utils.find").
When multiple attributes are specified, they are checked using logical AND, not logical OR. Meaning they have to meet every attribute passed in and not one of them.
To have a nested attribute search (i.e. search by `x.y`) then pass in `x__y` as the keyword argument.
If nothing is found that matches the attributes passed, then `None` is returned.
Examples
Basic usage...
Give the roles list in the guild as first parameter, and second parameter check for name="role name"
There's an example for getting a member by it's name, do the same for role
like
@bot.command()
async def test(ctx):
a = get(name="test")
await a.edit_role(color=ff0000)
like this?
Please read the documentation
^^
And what do you want to do?
Yeah but any role?
@waxen palm
Like a command to change the role color based on the name you gave?
Bot crates role,. after restart edit it
Yes
Cind of
So like !color rolename newcolor
Yes
Add a command argument/parameter
Any sample codes?
Then you can do !color @Role or RoleId or RoleName
Okay tnx
@waxen palm
No uhm this guy needs discord py help
Are you this guy?
No
this guy
stop pinging random people
K
Lol I thought u really pinged everyone
Funni 
I'll change my nickname
what are some ways of making a help command because i have a commands.group then have a help.command under it and i think thats really time consuming
^
ty
@client.command(name = "echo")
async def say(ctx, test):
await ctx.send(test)
Will this cmd respond if another bot said ".echo hi" ?
No
Ok thanks
πΏ ^
how to check given parameter is a member or channel ?
Use a typehint
ok trying
typehint it and if the param given wasnt the thing u wanted raise an error
i am passing that from a function
Doesn't matter
modlogs(target=user or channel)
async def modlog(target: Union[discord.Member, discord.ChannelType]) ?
then how i can check what is that target in if condition
if target == ?
Why ChannelType?
Use isinstance
okk
does anyone know how to code a connect 4 discord bot
i just finished with a tictactoe bot
if yes
ping me
we dont spoonfeed we help
ok
@boreal ravine
help with this pls
idk how
I recommended using a fork instead of a 3rd party lib
And asking in their server as you have more chances of getting help with their lib there
You need to subclass ui.Select and define callback for them
selectoption is available in dpy 2.0
They're clearly using a 3rd party lib
.send doesn't have the options kwarg
i use discord_components
mmhm
Use dpy 2.0
Or a fork
discord_components is the worst 3rd party lib
!d discord.ui.Select
class discord.ui.Select(*, custom_id=..., placeholder=None, min_values=1, max_values=1, options=..., disabled=False, row=None)```
Represents a UI select menu.
This is usually represented as a drop down menu.
In order to get the selected items that the user has chosen, use [`Select.values`](https://discordpy.readthedocs.io/en/master/api.html#discord.ui.Select.values "discord.ui.Select.values").
New in version 2.0.
Use this
so, if you want to create a wrapper, you are making these kinds of requests?
Why need an extension when it is already in the lib
Yeah
where to insert it? π
and you make request with something like aiohttps? (not sure if this is even correct lib)
or just request
https://github.com/Rapptz/discord.py/blob/master/examples/views/dropdown.py check this example
Yes
Make sure you install dpy v2.0
hmm
I guess you first need to authenticate(or login) the application before being able to make these requsts
How do i overcome the embed char limit?
Yes, you can do it using the Authorization header
so if you create a super simple code that authenticates the bot, you could alrd start making requests?
If you don't know what you're doing I recommend not doing it
I don't, and I'm not going to do anything for a while
your supposed to join the vc > play the music
Also you don't have a message anywhere in that code
why're u using message but u already have ctx
I'm just trying to find out how it works so I could understand the code somehow
You might have imported discord.message
, which i don't think exists
Show your imports
Oh, well for starters, to make a request to an api using aiohttp you just do
async with aiohttp.ClientSession() as session:
async with session.METHOD(url) as response:
...
METHOD can be put, get, etc, you can see them all in aiohttp's docs
so it would be something like response.request?
No, async with session.METHOD is where you do your request
ooh
coroutine async-with get(url, *, allow_redirects=True, **kwargs)```
Perform a `GET` request.
In order to modify inner `request` parameters, provide kwargs.
ok
then you use the response to get the data you want, eg. message id or something from the json
response is an object, you can do await response.json() to make it into a json format
ooh
Like requests
aiohttp is basically like requests only that it's async which is better
I see
Make sure you stop the script when running the bot again
You have a second instance of your bot running in the background
This is normal
Give it a few seconds to make it appear offline
You have a second instance running in the background
That doesn't matter
Your script is still running
how do i make simple message event like if i send ping bot responds pong
@bot.command()
async def ping(ctx):
await ctx.send("ping")
that'll respond "ping" right?
yes
i can add more than one right?
like one with ping = response "ping"
then another
like pong = response "pong"
sure
thanks
so ive made a command by using commands.is_owner(), but when i try to run those commands, i get this error:
discord.ext.commands.errors.NotOwner: You do not own this bot. This is the code in the main file:
client = commands.Bot(command_prefix = get_prefix, intents = discord.Intents.all(), owner_ids = owners, case_insensitive = True)```
Assuming you made the bot on the discord dev portal you don't need to specify that
IDs are integers not strings
Maybe he want's to add another owner to the bot.
make it integers not strings
same thing as it is in a normal file I guess
https://docs.google.com/forms/d/e/1FAIpQLSfKAh8jB8e1LjaxiwJvgWjGG-b9Ic8kdO4i5COPjNb4rFm2TQ/viewform?usp=sf_link
hey guys
This is a school project. Request all of you to please fill it .
BTW(I AM a python dev too!)
You should have shared that with a relevant server :p
Please guys fill it
Itβs not relevant post it in #ot0-psvmβs-eternal-disapproval
where do i put the message i want it to respond to in (ctx) ?
What?

what
@slate swan like replying to the author of the message?
just so you know my answers
1min lagging bad
Lmfao
anyways this is off-topic so go with your forms in some off-topic channel
please be polite guys
..
I just did #Flex π jkjk
π

i mean if i want it to respond "ping" to the message 1234 the 1234 is what i send and "ping" is what bot responds to 1234
where do i put the 1234
So like β!say hiβ the bot would respond with hi, copying the message?
you can use an event that triggers whenever you say anything specific
@_@
you can use an on_message event for that.
if we make it
!d discord.on_message
discord.on_message(message)```
Called when a [`Message`](https://discordpy.readthedocs.io/en/master/api.html#discord.Message "discord.Message") is created and sent.
This requires [`Intents.messages`](https://discordpy.readthedocs.io/en/master/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/master/ext/commands/api.html#discord.ext.commands.Bot "discord.ext.commands.Bot") does not have this problem.
person = hi
bot = responds somethin cool
Yup, listen for the βhiβ message to ctx respond with hello
oh
@bot.listen()
async def on_message(message):
if message.author == bot.user:
return
if message.content == 'hi':
await message.channel.send("Hello!")
``` something like this will suffice
thanks
yes
class discord.ext.commands.Bot(command_prefix, help_command=<default-help-command>, description=None, **options)```
Represents a discord bot.
This class is a subclass of [`discord.Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") and as a result anything that you can do with a [`discord.Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") you can do with this bot.
This class also subclasses [`GroupMixin`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.GroupMixin "discord.ext.commands.GroupMixin") to provide the functionality to manage commands.
Ye it is
huh?
Unless you use pycord : (
oh
stop hating on pycord when
I know
use commands.Bot()
well , it wont be discord.Bot in that case , its pycord.Bot xd
he realizes that
Itβs my planning
the only reason why pycord got popular is bc the owner is a ytbr
pycord still uses discord iirc
pycord uses the discord namespace still
i know
oh
im in his server
Never, personal grievances with swas haha. I'll get over em eventually
not really his friend made it
I like to think of him as more of the marketing side
^
well , i shifted to hikari so i dont know much about any fork other than disnake
yes disnake ftw π
sure
bot = commands.Bot(command_prefix = "a prefix")



