#discord-bots
1 messages · Page 579 of 1
Hey everyone! I'm trying to run this code:
import discord
from discord.ext import commands, tasks
bot = commands.Bot(command_prefix='<')
@bot.event
async def on_ready():
print('I am ready!')
@tasks.loop(seconds=60)
async def is_still_sub():
guild = bot.get_guild(900888494304538644)
treasure = guild.get_role(905285009873731605)
twitch_sub = guild.get_role(905284976109580319)
print(treasure.members)
for member in twitch_sub.members:
if treasure in member.roles:
pass
else:
await member.remove_roles(treasure)
is_still_sub.start()
bot.run('My token is here')```
but I keep getting this error:
```py
Unhandled exception in internal background task 'is_still_sub'.
Traceback (most recent call last):
File "/Users/me/Library/Python/3.7/lib/python/site-packages/discord/ext/tasks/__init__.py", line 101, in _loop
await self.coro(*args, **kwargs)
File "/Users/me/Python/SubBot.py", line 15, in is_still_sub
treasure = guild.get_role(905285009873731605)
AttributeError: 'NoneType' object has no attribute 'get_role'```
Does anyone know what's going on and how to fix it? Thanks!
Oops I didn't realize my message was that long, sorry 😦
guild is none
What do you mean?
whatever you defined guild as is none
I defined my guild to be: py guild = bot.get_guild(900888494304538644)
and I'm 100% sure that the id is the server's id I want my bot to run in. Do you know how to fix it?
!d discord.ext.commands.Bot.wait_until_ready
await wait_until_ready()```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Waits until the client’s internal cache is all ready.
add that
Where should I add it in my code?
on the top of everything in the task
boosts = guild.premium_subscription_count
boostlvl = ""
if boosts == 2 or 3 or 4 or 5 or 6:
boostlvl = ":Boostlvl1:"
elif boosts == 7 or 8 or 9 or 10 or 11 or 12 or 13:
boostlvl = ":Boostlvl2:"
elif boosts > 14:
boostlvl = ":Boostlvl3:"``` the guild that im trying this has 1 boost and it sends the boostlvl1 emoji
why?
If I do this: py @tasks.loop(seconds=60) async def is_still_sub(): await wait_until_ready() guild = bot.get_guild(900888494304538644) treasure = guild.get_role(905285009873731605) twitch_sub = guild.get_role(905284976109580319) print(treasure.members) for member in twitch_sub.members: if treasure in member.roles: pass else: await member.remove_roles(treasure) is_still_sub.start()
It says wait_until_ready is not defined
you're not supposed to copy paste whatever the bot highlights
print boosts
ok
wait_until_ready is a attribute of commands.Bot now, if you know what i mean you should be able to get it
@bot.command()
async def testst(ctx):
await print(guild.premium_subscription_count)``` idk if i need to await 😂
holy shit
You never await prints
😭
wtf?
Oh I see so since I did bot = commands.Bot(command_prefix='<') I should do await bot.wait_until_ready()
?
yep
Bro chill 😭
ok bro, im sorry :/
didnt say nothing he is so agresive wtf
do you expect me to not be agressive?
lol XD
!mute 675414248620294154 1w You need to look at our rules and code of conduct. That is not acceptable behavior.
:incoming_envelope: :ok_hand: applied mute to @kindred epoch until <t:1636665585:f> (6 days and 23 hours).
yes
yes XDDD, especially to me xd
Small side question, why don't you use relative timestamps for the 6 days and 23 hours? Like <t:1636489341:R>
Don't know if you know the answer though.
Oh well, it just gives the days not hours
it gives both the end timestamp and the duration
My bad
Yeah but was wondering why not using relative timestamp for the part in parentheses
But it also gives the hours, which the relative timestamp doesn't
help me please, Nothing happens when I make the order
@bot.command()
async def giveroleallmember(ctx): # b'\xfc'
await ctx.message.delete()
role = discord.utils.get(ctx.guild.roles, name="member")
for member in list(ctx.guild.members):
try:
await ctx.guild.member.add_roles(role)
except:
pass
Don't make an except -> pass
Print the exception
how
except Exception as e:
print(e)
my code is good ?
Just print the exception
Then you will know what's wrong
Since nothing happens you got an error, and your except just does nothing at the moment
@bot.command()
async def giveroleallmember(ctx): # b'\xfc'
await ctx.message.delete()
role = discord.utils.get(ctx.guild.roles, name="member")
for member in list(ctx.guild.members):
try:
await ctx.guild.member.add_roles(role)
except:
except Exception as e:
print(e)```
No..
You're supposed to do member.add_role since you're iterating over the members
Why except except
:x
...
Just once
Also don't use list() on ctx.guild.members, it's already returning a list
And yeah, you need to do member.add_roles
That's not how exceptions work
Hi again everyone, I have an other problem with my code, this bot is meant to check everyone who has a role called treasure if someone who has that role doesn't have a role called twitch sub I want the bot to remove the role treasure from that specific user.
import discord
from discord.ext import commands, tasks
bot = commands.Bot(command_prefix='<')
@bot.event
async def on_ready():
print('I am ready!')
@tasks.loop(seconds=60)
async def is_still_sub():
await bot.wait_until_ready()
guild = bot.get_guild(900888494304538644)
treasure = guild.get_role(905285009873731605)
twitch_sub = guild.get_role(905284976109580319)
print(treasure.members)
for member in twitch_sub.members:
if treasure in member.roles:
pass
else:
await member.remove_roles(treasure)
is_still_sub.start()
bot.run('My token is here')```
But now if I run the code the command `print(treasure.members)` doesn't return any members even though it should because there are some members in my server who has that role
Intents
!intents
Using intents in discord.py
Intents are a feature of Discord that tells the gateway exactly which events to send your bot. By default, discord.py has all intents enabled, except for the Members and Presences intents, which are needed for events such as on_member and to get members' statuses.
To enable one of these intents, you need to first go to the Discord developer portal, then to the bot page of your bot's application. Scroll down to the Privileged Gateway Intents section, then enable the intents that you need.
Next, in your bot you need to set the intents you want to connect with in the bot's constructor using the intents keyword argument, like this:
from discord import Intents
from discord.ext import commands
intents = Intents.default()
intents.members = True
bot = commands.Bot(command_prefix="!", intents=intents)
For more info about using intents, see the discord.py docs on intents, and for general information about them, see the Discord developer documentation on intents.
@bot.command()
async def giveroleallmember(ctx): # b'\xfc'
await ctx.message.delete()
role = discord.utils.get(ctx.guild.roles, name="member")
for members in ctx.guild.members:
try:
await ctx.guild.members.add_roles(role)
except Exception as e:
print(e)```
'list' object has no attribute 'add_roles'
As i said, it's member.add_roles not ctx.guild.members.add_roles
It still doesn't work even if I do this ```py
import discord
from discord import Intents
from discord.ext import commands, tasks
intents = Intents.default()
intents.members = True
bot = commands.Bot(command_prefix='<')
@bot.event
async def on_ready():
print('I am ready!')
@tasks.loop(seconds=60)
async def is_still_sub():
await bot.wait_until_ready()
guild = bot.get_guild(900888494304538644)
treasure = guild.get_role(905285009873731605)
twitch_sub = guild.get_role(905284976109580319)
print(treasure.members)
for member in twitch_sub.members:
if treasure in member.roles:
pass
else:
await member.remove_roles(treasure)
is_still_sub.start()
bot.run('My token')```
Well now it's members.add_roles
Actually members.add_roles since you named your variable for looping members
Since you changed the name of the variable
Did you enable them in the dev portal too?
Read the entire tag, not just the code part
What do you mean?
And you need to pass the intents=intents kwarg
Yeah I did
Read the whole thing
In your bot constructor
The bot added that the role alone
In the bot constructor
Isn't that what you wanted?
I wanted it to add all the members of the server
Need intents all it sees is itself

Intents then
Read this about them
This
Can this be a command instead of an event?
self.is_it_me since the function is defined inside the class.
bot = commands.Bot(command_prefix = '<', intents = intents)
@sudden aspen
Yes?
How so?
Wdym how so
Just make it a client.command()
And add the other stuff ofc
Yeah thats what am talking about not the command
like whats the whole code for that feature
^
You said what now
i am a noob at coding discord bots so this server may be my saving grace when I am having issues
Like the function to where it should do what i wanted it to do
calm
like make the application for apply for staff and making the bot ask questions
and then getting reviewed
and giving feedback
@client.command()
async def command():
This?
no
like the whole code
the whole code after the command
am sorry am kind of terrible at explaining
but am trying my best
like to get the wait_for funtion
I have no idea what your talking about
nvm
i mean
How to make the bot do this
async def on_message(message):
if message.content.startswith('$thumb'):
channel = message.channel
await channel.send('Send me that thumbsup reaction, mate')
def check(reaction, user):
return user == message.author and str(reaction.emoji) == 'thumbsup'
try:
reaction, user = await client.wait_for('reaction_add', timeout=60.0, check=check)
except asyncio.TimeoutError:
await channel.send('thumbsdown')
else:
await channel.send('thumbsup')```
as in like send the dms and make sure for when a member does a command it sends him/her few questions to answer
Try digital ocean
Hi i have a json directory error
Traceback (most recent call last):
File "C:\Users\thoma\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "c:\Users\thoma\Desktop\discord.py\bot.py", line 70, in on_message
with open('users.json', 'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'users.json'```
hang on am confused
someone?
Traceback (most recent call last):
File "C:\Users\thoma\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "c:\Users\thoma\Desktop\discord.py\bot.py", line 70, in on_message
with open('users.json', 'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'users.json'
Are you for reall right now?
Please actually learn before watching how to make a leveling system
The error is so simple
There no such a file called user.json in your files
Well i know but then it is in a directory folder called discord.py
send screenshot
Send screenshot of the discrod.py folder
wait hold on
What?
restart vsc
My discord bot is the owner of a sevrer, does anyone have a command to transfer ownership
I cannot find anything
Yikes
I know discord API allows it because I did it before on bot client
But RIP bot client
shoow the code maybe?
Ok ill show the whole code
I dont need the whole
all i need is when the script
stops
is there any way i can setup an error message without putting it in a seperate part of my source?
for example
@bot.command(name='test')
async def test(ctx, member : discord.Member, reason = None):
#do something
@test.error
async def test_error(ctx,error):
if isinstance(error,commands.MissingRequiredArgument):
embed = discord.Embed(title=f'Error', description=f'Usage - test [member] (reason)', color=0x2f3136)
await ctx.reply(embed=embed)
return
but the error is within the test function
I’m just wanting to make a bot that picks movies from the few you give, say
!pick Baby Driver | Guns akimbo | Your Name
And it randomly selects one of the 3, I’m new to coding bots, that’s why I’m here
Is this me getting rate limeted? https://mystb.in/OverviewAmendmentAppeared.xml
@bot.command(name='test')
async def test(ctx, member : discord.Member=None, reason = None):
if not member:
ctx.reply('Something')
return
would this work with a ban command? cuz i noticed member=None
yes
yes because you check if member is None and return (do nothing in the command) if it is
Any sites that give info on how to do stuff for bots?
yo give me codes
?
codes for whatss
skid
dms
he wants free sources lol
no
youre repping summrs, youre defo searching for free sources
who are u unknown
im known in crisis 666 slay 444 1400 1500 nulled and deathwish, introduce yourself
anyways, ty for this info
np
never heard of u and ive owned half of them LOL
!d discord.on_member_join
discord.on_member_join(member)``````py
discord.on_member_remove(member)```
Called when a [`Member`](https://discordpy.readthedocs.io/en/master/api.html#discord.Member "discord.Member") leaves or joins a [`Guild`](https://discordpy.readthedocs.io/en/master/api.html#discord.Guild "discord.Guild").
This requires [`Intents.members`](https://discordpy.readthedocs.io/en/master/api.html#discord.Intents.members "discord.Intents.members") to be enabled.
new alias lol
dm me whicch half, cuz a lot are still active
i owned og 1500, and 1400
oh want the new 1400 inv?
/ic3
nah they changed it
i quit that stuff
oh youre in it lol
mhm
go dms
Since you said that you're new to "coding bots" and not coding itself, I'll give you a brief idea of how to do it:
import discord
from discord.ext import commands
intents = discord.Intents.all()
bot = commands.Bot(command_prefix="!", intents=intents)
@bot.command(name="pick")
async def pick(ctx: commands.Context, *, picks: str):
... # You continue the code here because from this point on it's just python
bot.run('token')
Now that you can use the .split method on the picks because it's a string, and using the random module you can use it to get a random item from the list that's returned from using the split method on the string
However if you're new to coding itself, then go in #bot-commands and type !resources and learn more about python before you decide to create a discord bot
It’s mainly the bots, is there any functions I should know for bots ?
There's docs
Thanks
yep
can u code a discord app
like lightcord and ripcord
No clue what those are
But if you mean an app like discord then yeah i don't see why not
@commands.command()
async def userinfo(self, ctx, member:discord.Member):
embed = discord.Embed(colour=0x000000, timestamp = ctx.message.created_at)
embed.set_author(name="User info")
embed.set_thumbnail(url=member.avatar_url)
embed.add_field(name="Pseudo", value=member, inline=False)
embed.add_field(name="Surnom", value=member.display_name, inline=False)
embed.add_field(name="ID", value=member.id, inline=False)
embed.add_field(name="Status", value=member.status, inline=False)
embed.add_field(name="Join le", value=member.joined_at, inline=False)
embed.add_field(name="\nCompte crée le", value=member.created_at.strftime("%a, %#d %B %Y, %I:%M %p", inline=False))
await ctx.send(embed=embed)
@slate swan :))
?
not enable
?
Command raised an exception: TypeError: strftime() takes at most 1 argument (2 given)
@slate swan please :/
!docs datetime.datetime.strftime
datetime.strftime(format)```
Return a string representing the date and time, controlled by an explicit format string. For a complete list of formatting directives, see [strftime() and strptime() Behavior](https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior).
Is there a way for a bot to transfer its ownership of a server to someone else
I really want it to leave the server
Like un discord?
You're closing your strftime too late
im making my own non tos breaking version of lightcord
You could try using older APIs
Kick it
I bot it to make its own discord server
yes
Because afaik everything about selfbots is deprecated
wht is this
@slate swan
F
Can you mix and match old version of python
im guessing not
Of python??
Why of python?
Idk what you are saying by trying an older version
Im just trying to transfer ownship haha
pip install discord.py==version
e.g: pip install discord.py==1.7.2
Forgot what dpy's versions were
thats gonna break all my codes though
You can find them if you go to the repo and check the tags
it is, but not removed
You can revert back to the latest after you've given the ownership away
Oh
oof
And yeah, I can send self bot coding here
Then you can do it with the current version by making your own API call
its not hard to do
It's actually against the rules
Lmao
So only do it to fix that ownership, after that don't use anything related to selfbotting 👍
!rule 5
5. Do not provide or request help on projects that may break laws, breach terms of services, or are malicious or inappropriate.
what am trying to do its a self bot though
its a genuine bot that has ownership
!rule 5 again
5. Do not provide or request help on projects that may break laws, breach terms of services, or are malicious or inappropriate.
Then I ain't gonna help you any further
Selfbots are against ToS
Guys
Log in as your bot then with the token
Discord Developer Portal TOKEN
Not user token
not self bot
Ik you love using that but chill you sent it it's literally above his message
bot ideas anyone?
You can still use it
a bot cant own a server can it?
self bot is user account automation
it can
A bot that decides movies
It can
Under 10 servers it can create its own
wifi is trash so no
It's still selfbotting
whats self botting
Those endpoints got deprecated for a reason
Tell me what the difference is between automated user account and a discord bot
Awe, I was gonna make one myself but I’m tired, just something so you do !pick movie | movie 2 | movie 3
etc it randomly chose one
Automating normal user accounts (generally called "self-bots") outside of the OAuth2/bot API is forbidden, and can result in an account termination if found.
pretty easy just make a list of movies and use
import random
Ok that makes sense 
Well yes but no, I want it with inputs, as shown in that message
Anyways, the endpoints that you're trying to use are deprecated so use an older version of dpy or make the API call yourself
like a embed?
what are they trying to do though?
Give ownership from their bot account
await edit(*, reason=..., name=..., description=..., icon=..., banner=..., splash=..., discovery_splash=..., community=..., region=..., afk_channel=..., owner=..., ...)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Edits the guild.
You must have the [`manage_guild`](https://discordpy.readthedocs.io/en/master/api.html#discord.Permissions.manage_guild "discord.Permissions.manage_guild") permission to edit the guild.
Changed in version 1.4: The rules\_channel and public\_updates\_channel keyword-only parameters were added.
Changed in version 2.0: The discovery\_splash and community keyword-only parameters were added.
Changed in version 2.0: The newly updated guild is returned.
owner kwarg
I made it so my bot makes its own server
That's a thing??
But now I cant figure out how to switch ownership
mhm
I didn't know that 💀

Thank you guys
Please dont ban for self bot because it isnt
Even though they keep saying it is
No so you do the
!pick
Then u put the movies you want deciding,
So
!pick input | input | input
But so you can have more than 3, let’s say up to 5
So say I wanted a bot to decide between
Ice age
Flushed away
DOOM
I’d do
!pick ice age | flushed away | DOOM
There are infinite black and white dots on a plane. Prove that the distance between one black dot and one white dot is one unit. I bet you can't
!ot
Off-topic channels
There are three off-topic channels:
• #ot0-psvm’s-eternal-disapproval
• #ot1-perplexing-regexing
• #ot2-never-nester’s-nightmare
Their names change randomly every 24 hours, but you can always find them under the OFF-TOPIC/GENERAL category in the channel list.
Please read our off-topic etiquette before participating in conversations.
⬛
🟦
Bruh
I know its off topic but nobodies even in here
Doesn't matter, this channel is only for help for discord bots
Bruh
I'm so incredibly sorry. The amount of regret I have is unbearable and I can't sleep at night now just thinking about how I have broken the rules inside of the Python Discord Server channel. I truly and deeply apologize, I hope you can come to an understanding and forgive me. I don't know how I can live with myself
💀
👍
Haha
I'm so incredibly sorry. The amount of regret I have is unbearable and I can't sleep at night now just thinking about how I have broken the rules inside of the Python Discord Server channel. I truly and deeply apologize, I hope you can come to an understanding and forgive me. I don't know how I can live with myself
Already said it once
Clone msg
ok?
I found it funny
ok?
Thank you so much for the much needed input! I'm greatly appreciative of it! I hope you live an amazing life and don't get into a horrific car crash killing you and your parents tomorrow at 7:57 PM MST. I'm so happy you said this
Wtf 😂

!rule 7
7. Keep discussions relevant to the channel topic. Each channel's description tells you the topic.
Anyway how would I go about doing this
Who is this man?
I basically already told you
His name is clearly lying
Right here
Do a msg check
I know the rules now due to the much repeated times of me being told to stay on topic! Thank you again for this!
Well yeah but it’s 1:28am I can’t sleep I don’t wanna be reading at this time in the morning
!rule 7
7. Keep discussions relevant to the channel topic. Each channel's description tells you the topic.
I’m new to bot programming
¯_(ツ)_/¯
Check api reference
Today, but later on because I’m too fuckin tired lmao
¯\_(ツ)_/¯
Stop going off topic please, this is not for comedical value but rather for someone to learn how to type code that they can copy and paste off of Google. If you keep going off topic I will have no choice but to report you to the federal government and have you locked up. !rule 7
Sorry this channel is for dpy

For discord bots*
For discord bots*
And that
And dpy forks*
Stop being annoying bruh
Kinda getting unfunny at this point ¯_(ツ)_/¯
!rule 1
1. Follow the Python Discord Code of Conduct.
I've tried everywhere
No cyberbullying please
100% agree
That's basic python, read your code
You have await t.delete()), why is there an extra ")"??
Because of the button
It's in the buttob
Do you actually have a file named "users.json"?
Button*
The whole code looks confusing
Why are you executing functions when you're defining a list of buttons
You're adding link buttons, I only see 2 link buttons
I'm not, your just being an annoying person.
Actually it's only 1 link button nvm mb
ghost pinged
<@&831776746206265384> this guy (@crude crater) keeps being off topic and sending shit post
You aren't even a staff..?
Dude I'm just enforcing server rules?
Thank god
No you're just shit posting and being off topic
Stop going off topic please
I'm trying to enforce rules
You sound 5 please stop
If I were to go to off topic and spam ping recon I’d get muted?
Yes
Hmmmm
Worth it
Nah im good thx
I believe he was asking staff since you do not have sufficient permissions to mute
🤦♂️
Yes please
I swear
No
Please stop going off topic guys
Thats cyberbullying your forcing me so please stop its harrassment and i feel unsafe
@bot.command(ctx, user)
async def who smells like shit?(ctx):
await ctx.send(f'Okimii smells like shit!')
m = await client.wait_for("message", check)
``` can someone help me with a ceck
What's wrong with my code?
check*
learn python pls
My guy you wanna get banned 💀
?
He's obviously trolling
I'm trying to get some help pls
What's wrong with it
Guys I need help
just need help getting started
functions cant have spaces in them
So, what's been going on here?
Did you define what check is
shitposter sir
This is my first discord bot
liar
im gonna make a function called def so check=check
i need help with the check function
Shit posting, trolling, and as you can see harassing okimii
?
!mute 700830338204696651 low effort trolling
:incoming_envelope: :ok_hand: applied mute to @crude crater until <t:1636080376:f> (59 minutes and 59 seconds).
Here's an example ```py
def check(message):
return message.author == ctx.author
This check will only work if the one who sends the message is the ctx.author
make sure the function is in the function
The check function has the message arg which is a discord.Message object
This too
Seems like the dm reports work ig
Or you could also just use lambda ```py
message = await bot.wait_for('message', check=lambda m: m.author == ctx.author)
I thought that pinging the mod role works too 
Both work lmaoo
Ig for a faster response dm reporting is the way 😌
Yup
l = await client.wait_for("message", check=check)
``` how do i get the member mentioned in this just use l.content and hope they only mention a user
l.mentions
Returns a list of discord.Member objects, if no mentions found the list is empty
I noticed the mod ping first actually - it was just taking me a moment to catch up on what was happening.
Understandable 
Guess you were lurking in the shadows
when there's a lot of people talking, it's not always easy to see who's in the wrong.
for a minute, yeah.
Thank you btw.
sure thing, sorry for the delay 🙂
Not a problem
how could I make a custom server prefix from a database I have the database but how would I set the prefix for the server
Yes i do i will show u when i get home cuz am out my dad is doing his 14 day miq
Its hard out here in NZ
you can write a method called get_prefix(message) and pass that to your bot at startup. it will always call that method when trying to determine the prefix
how exactly would that work
would I get the prefix in the function
l = await client.wait_for("message", check=check)
user = l.mentions
us = client.get_user(user)
try:
if us is None:
await ctx.reply("User is invalid!")
else:
try:
embed = discord.Embed(description=f"{text} - sent from {ctx.author}",color=color)
await us.send(embed=embed)
embed2 = discord.Embed(title="wintrs",color=green,description=f"DMed {us}")
await ctx.reply(embed=embed2)
yes, and return it
uhmm i have a feeling theres the worls dumbest error here
it's a function of a message object, because the bot uses the current message to determine what the prefix should be. so you can just find the guild for that message, and lookup the prefix in your database for that guild
any ideas
cluster = MongoClient(mongo)
db = cluster["urls"]
collection = db['urls']
def get_prefix(sid):
collection.find({'_id': sid})
tokino = commands.Bot(command_prefix = get_prefix())
how would I get the id of the server
As i said, .mentions returns a list
!docs discord.Message.mentions
A list of Member that were mentioned. If the message is in a private message then the list will be of User instead. For messages that are not of type MessageType.default, this array can be used to aid in system messages. For more information, see system_content.
Warning
The order of the mentions list is not in any particular order so you should not rely on it. This is a Discord limitation, not one with the library.
async def get_prefix(message):
guild = message.guild
result = collection.find({'_id': guild.id}) # probably, maybe mess with this
return result
@slate swan ^
so how do i get the user from the list
read the code line-by-line, it's pretty clear
so then the prefix code would be
tokino = commands.Bot(command_prefix = get_prefix(what would go here)
nothing
command_prefix=get_prefix
oh that makes sense my bad
you're giving the bot a function to run whenever it needs to find a prefix
?
it is a list of the all the members who were mentioned in the message you waited for
so if I only mention you like this: @slate swan the mentions will be [YourMemberObject]
if you wanna be sloppy, you can just get the first element with myList[0]
how do you find account age
like detect account age
@slate swan huh?
did you ping me?
async def get_prefix(message):
result = collection.find({'_id': message.guild.id})
return result
error:
Ignoring exception in on_message
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/nextcord/client.py", line 351, in _run_event
await coro(*args, **kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/nextcord/ext/commands/bot.py", line 1035, in on_message
await self.process_commands(message)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/nextcord/ext/commands/bot.py", line 1031, in process_commands
ctx = await self.get_context(message)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/nextcord/ext/commands/bot.py", line 941, in get_context
prefix = await self.get_prefix(message)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/nextcord/ext/commands/bot.py", line 886, in get_prefix
ret = await nextcord.utils.maybe_coroutine(prefix, self, message)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/nextcord/utils.py", line 512, in maybe_coroutine
value = f(*args, **kwargs)
TypeError: get_prefix() takes 1 positional argument but 2 were given
is there any specific reason you need linode?
i mean other than that
quite biased here but imo aws is better due to it's insane scalability
EC2 is pretty nice
hm
EC2 is quite expensive, to be honest.
Once my free-tier expires its estimated to 14$/month, for that i plan to switch to a different host. I can get the same for a third or fourth of the price.
A W S
though AWS scales really well
even if your bot gets huge, you can scale it relatively easily
How so
i.e the EC2 auto scaling one
scalability is a concern for a lot of companies that use AWS, so it's in their best interest to be scalable
?
i won't argue with that, after all it's a discord bot 😂
compared to huge companies like netflix or twitch
yeah, exactly
heck just buy a raspberry pi for it, runs a discord bot well as anything
once you get over the initial investment the electricity cost is negligible
get_prefix takes a bot and message
async def get_prefix(bot, message):
return whatever
quick note i'd like to add here is not NOT make a database call inside get_prefix
CATTTT!
AAAAAA

AA how did i find you
then where would I add it?
caching mechanism
perhaps redis but that might be overkill

nah im good
a simple dictionary would work just fine
yep
and depending on the database it wouldnt be an issue even
for example mongodb is quite fast
and depending on the bot
that true also
does anyone know the numbers as to how many reads sqlite can do per second?
I assume read speeds are faster, so a bit more than 50k reads per second on average?
yeah
as for postgres, as it seems quite popular,
If you're simply filtering the data and data fits in memory, Postgres is capable of parsing roughly 5-10 million rows per second (assuming some reasonable row size of say 100 bytes). If you're aggregating then you're at about 1-2 million rows per second.
when you're talking about this small amounts of time, ssd/hdd also plays quite a big part
yeah unless you're getting millions of messages per second it theoretically shouldn't be an issue
but this is purely the database, there are other factors that affect it i.e the disk speed, overhead speed of the system, etc...
yeah. some cache like Redis is only good for those bots that are in thousands of servers
a dictionary is probably the best and simplest idea
yeah of course
a simple dict or some other datastructure of that sort will suffice in most cases
or a defaultdict(list)
to not have to handle the whole keyerror
and just call append and so on, on the thing
im getting the error
command_prefix must be plain string, iterable of strings, or callable returning either of these, not NoneType
get_prefix returned None
async def get_prefix(tokino, message):
result = collection.find({'_id': message.guild.id})
for i in result:
return i['prefix']
why is that happening
probably result is empty, and it's not entering the for loop
Then it would have raised an error that NoneType isn't iterable
m
?
we don't know if it's noneType or an empty list
Print i["prefix"] @slate swan
Ah yes. That's also a possibility. Wait, my bad. Got confused between yours and Leo's message smh
result = collection.find({'_id': message.guild.id})
result is none
the collection is empty
result can't be None...
hm
eval?
nah with @unkempt canyon
@maiden fable :white_check_mark: Your eval job has completed with return code 0.
1
!e
mylist = []
for i in mylist:
print(i)
@sick birch :warning: Your eval job has completed with return code 0.
[No output]
i see
Yea
But if it's None, then would raise an error haha
!e
mylist = None
for i in mylist:
print(i)
@maiden fable :x: Your eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "<string>", line 2, in <module>
003 | TypeError: 'NoneType' object is not iterable
did this raise an error or just didn't give output
No output
Since there's nothing to loop over haha
yeah then if collection.find returns an empty list, it just won't do the for loop
{'_id': '905993828752846888', 'prefix': 't'}
What did u print? Result or what?
for i in result:
print(i)
hm
Hey @tiny ibex!
It looks like you tried to attach a Python file - please use a code-pasting service such as https://paste.pythondiscord.com
how to make discord bots send pictures?
PLease help
!local-file
Thanks to discord.py, sending local files as embed images is simple. You have to create an instance of discord.File class:
# When you know the file exact path, you can pass it.
file = discord.File("/this/is/path/to/my/file.png", filename="file.png")
# When you have the file-like object, then you can pass this instead path.
with open("/this/is/path/to/my/file.png", "rb") as f:
file = discord.File(f)
When using the file-like object, you have to open it in rb mode. Also, in this case, passing filename to it is not necessary.
Please note that filename can't contain underscores. This is a Discord limitation.
discord.Embed instances have a set_image method which can be used to set an attachment as an image:
embed = discord.Embed()
# Set other fields
embed.set_image(url="attachment://file.png") # Filename here must be exactly same as attachment filename.
After this, you can send an embed with an attachment to Discord:
await channel.send(file=file, embed=embed)
This example uses discord.TextChannel for sending, but any instance of discord.abc.Messageable can be used for sending.
Your bot got API banned
Wait for like, 2 hours iirc before u restart your bot
Why tho
Using replit?
Ooo
Haha
if you're using replit, don't cuz replit is really bad
it's gonna get your bot ratelimited more frequently or api banned like this
My bot got 2 parts one of them is on repl and another on heroku
I can't host both of them on heroku
Cuz dynos
both are pretty eh imo
😕
perhaps consider switching to AWS/Linode or something of that sort?
if you're planning to deploy of course
All of a sudden I am poor
if you're only testing it it's not an issue, more of an annoyance than anything
haha yeah i feel you, in which case a raspberry pi might serve you well
the only problem is the initial investment, which can vary depending on the model
Yes but it's slow
a 4 or 8 gig is slow
for normal uses, yes
And you can't have gbps speeds on your raspberry pi
which is why you should put something such as ubuntu server on it and SSH into it
(that's what I do)
:0
You still can't have GBPS speeds
No I mean your wifi won't give you gbps speed
lol
difficult to get gigabit on wifi imo
Yup
even on normal devices, i'm subscribed to gigabit internet atm, but i only get about 300-500mbps
ethernet boosts it up to basically 960+
I am subscribed to 200 mbps
-,-
well it's not all that bad
lmao
async def temprole(ctx, member: discord.Member = None, *, time, role: discord.Role = None):``` Let's say I do `.temprole @Someone#0171 5d 1264787129` would it keep the role integer (`1264787129`) stored as `{role}`?
It seems to throw me an error without the * which is quite bizzare
Non-default argument follows default argument
who codes selfbots here
what is tmep role?
Is it kinda thing for makin' role for some time and deleting that role?
I'm interested in python algorithms.
Okay
!rule 5
5. Do not provide or request help on projects that may break laws, breach terms of services, or are malicious or inappropriate.
against the ToS
ok
So noone does
who codes bots
grammar
almost eveyone in here
hmm
XD
can u nuke a server without perms
What
@dusk pumice
It's hard
@fathom cipher
you need perms or can't do that
i thought u a pro coder
hello
And stop pinging people
So you can do that?
stop begging for nitro broke boi
bro fix ur grammar
I will never beg nitro to ya
Hello
use grammarly
u too
...
Soo unkind.
i do i have to
!ot
Off-topic channels
There are three off-topic channels:
• #ot0-psvm’s-eternal-disapproval
• #ot1-perplexing-regexing
• #ot2-never-nester’s-nightmare
Their names change randomly every 24 hours, but you can always find them under the OFF-TOPIC/GENERAL category in the channel list.
Please read our off-topic etiquette before participating in conversations.
when I'm using it
youre the skid who came in here saying "give me code bro" earlier arent you?
XD
i was asking for bot codes lol
ye, skid
"hack" 😭
youre not gonna get anything free here
what codes
hes a skid and hes looking for code to copy
he wants to get spoonfed
cringe
very
k
agree
like music code
that's quite complex
well that's not the right term
quite nuanced, requires a fair bit of time to get it working just right
its not something for his level
you may read the Docs
wht docs
the github page contains excellent examples
^
(i authored one myself)
python docs
no
python docs won't help write a music bot, the github page and the discord.py documentation will
Hmm.. That's right too
you dont get it, he literally wouldnt know what a string is
?
Well there is code for music bot on replit so search for it too
or how to call a function
what sort of programming background do you have?
Melon
Yes?
wdym by that
how did you highlight your text in your about me?
😬
have you coded before? if so what language? what do you know?
linux or window like this. I guess(Well. This doesn't care
and codes
or are you completely new to programming in python?
ik only import
windows
K
Ugh
you said you made a page yourself, are you Rapptz?
No, I made a PR with one of the examples
and "*" Too.
Search for discord markdown
/examples/views/dropdown.py is by me :D
Cool
Afraid we can't do that.
I hope there is no spoonfeed
i mean this
People here don't give you the code that you need, we help you understand and write your code yourself.
this
Copying random bot code off GitHub will not work well for you either.
Yea here is just for help
they were asking for help with that specific section of their code
fix this code
You gotta understand the code so it will work
do you have a specific section of your code that needs fixing?
if so, we can help with that
!ot
Off-topic channels
There are three off-topic channels:
• #ot0-psvm’s-eternal-disapproval
• #ot1-perplexing-regexing
• #ot2-never-nester’s-nightmare
Their names change randomly every 24 hours, but you can always find them under the OFF-TOPIC/GENERAL category in the channel list.
Please read our off-topic etiquette before participating in conversations.
Here is not for memes
Please only come here with serious code questions relating to discord bots.
fix this
Hey @fluid sand!
Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:
• If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)
• If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:
We won't fix it for you, we'll walk you through fixing it yourself
Hey @fluid sand!
Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:
• If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)
• If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:
We'll also need a full traceback, and what you want it to do to be able to help as effectively as possible.
Hey @fluid sand!
Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:
• If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)
• If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:
XD .txt file for python code? LOL
They're defenetely a troll, I'm humoring them in the dms just to see haha
When you try to send a message on Discord that is over 2'000 characters it converts your message in a text file called by default message.txt. In that case the user sent their code which was over 2'000 characters, so nothing to laugh about...
lot of stuff to laugh about, it's crappy code copy pasted from github
Not talking about the code, talking about the fact that Melon laughed about sending a .txt file for Python code
hm
the guy was being a skid anyway, what with the demanding for bot code, sending random memes and whatnot
😄
Dont demand anything from anybody here we do it on are free will
no 1 talking to u random any way i got helped
Who cares if im a random?and good for you
"random" whats a string lmao
youre coming here begging for help but youre biting the hand that doesnt feed
So what?
ooh i see it is a 2v1
Im so offended for being called a random
man ur weird
no youre just calling for attention
hope in dms

btw, i'm not actually helping you i know you're a troll
i haven't blocked you, just removed
not u from my friend wintrs
Im so offended
lol
i suggest you go waste people's time somewhere else
but if you really want to learn to make bots, learn basic python first
lol
🥴
accept
don't
same
it u wanna 2 v 1
the guy's gonna post stupid questions in your dms
everyone stays pending on my account lmao
skids smh
let him, im from the same community hes from and he is a serious embarrassment
Man stay quite this inst a game nobody is gonna add you chill out
u wanna 2v1
isn't it
What are you gonna do spam ping me
Can you just move on and stick to topic, please..
yes please
hes gonna yell at you in a discord call and pack you with his friends as he cranks his mic input to 4000000DB
Im so scared
it's clear you have 0 idea what you're talking about, i doubt you've even done programming before, so either 1. go do something else, 2. learn basic programming
Fr
ur the one who is 2
Linx has the vibe of a 16 year old in their room selling robux for nitros or paypal
Right😔
!mute 722723151708160030 Investigating.
:incoming_envelope: :ok_hand: applied mute to @fluid sand until <t:1636092314:f> (59 minutes and 59 seconds).
Has a scam discord server of 5k child members
thank you
🕊
if you want a mod, you should ping the moderators role
🙏
Thank you
oh okay thanks, i was just afraid after the last time i accidentally pinged all the admins... hehe
What was the punishment 😭
Spanking
luckily i got off, i just hit the wrong key and pinged all the admins rather than a guy i meant to ping
Oh no
anyway back on track
Yes sir
oh well that's sad, sent a dm to @novel apex exactly at the same moment
Happened to me when a guy was harrassing me with kraots
Was resolved tho

Anybody have command ideas i have 0
@slate swan@sick birch@slate swan do note that some of your comments were disruptive or disrespectful - please ping moderators in the future and disengage
My bad next time ill leave it all to you guys
understood
😂

tweet?
Yeah, not sure if I can request for it
Yes you can, by using the library tweepy
https://www.storybench.org/how-to-collect-tweets-from-the-twitter-streaming-api-using-python
Here is a tutorial.
Note that the filter should be .filter(follow="") instead of track=... since you want to get the tweets from a user, and not based on the tags of the tweet. And you also probably don't need/want the saving into a .csv file function, so you can just skip that.
Any one help me with my error
Whats the error
Wait no error but am trying to make a levelling system
If you don't give code and/or errors we can't do anything for you, sorry
hey there, actually I was trying to read a image using aiohttp, and writing to the file using aiofiles but I was continuously getting this error
a bytes-like object is required, not 'StreamReader'
My code -
async with aiohttp.ClientSession() as session:
async with session.get(f'https://some-random-api.ml/canvas/jail?avatar={user.avatar_url}') as r:
async with aiofiles.open('image.png', 'wb') as resp:
try:
await resp.write(r.content)
except Exception as e:
print(e)
please read the documentation before creating/developing bots.
I think its
await add_reaction()
youd need to assign your message to a variable
and use add_reaction() on it (with await)
Yeah i gaved him the simple command tho
still, youre missing the message object
!d discord.Message.add_reaction
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.
?
Ok thnx
can anyone help me with this
"This is the message" what can i do to consider this is a message between " " as 1 msg or phrase?
!e
import re
x = re.findall('"([^"]*)"', '"Hello world"')
print(x)
@slate swan :white_check_mark: Your eval job has completed with return code 0.
['Hello world']
yes
Yes
No

yes
yes
barely three words lol
async def show_help():
await message.channel.send('-rpm hunt/mine')
await message.channel.send('-rpm craft')
await message.channel.send('-rpm boss/defraid')
await message.channel.send('-rpm cd')
await message.channel.send('-rpm p')
await message.channel.send('-rpm inv')
if message.content.startswith('rpm help'):
asyncio.run(show_help())
message is undefined
Ah
what the fuck is that
how do i do it correctly
No need of asyncio.run inside an async function
i messed up this thing
Just do await show_help()
someone call me to do that
:)
lemme try ur method
Then they told it wrong 😐
what about this
async def show_help():
await message.channel.send('-rpm hunt/mine')
await message.channel.send('-rpm craft')
await message.channel.send('-rpm boss/defraid')
await message.channel.send('-rpm cd')
await message.channel.send('-rpm p')
await message.channel.send('-rpm inv')
this is error
define message
I also said so lol
how to define
yes he didnt do it still
in the parentheses.
And why making your bot spamming messages
then how do do it in one message
i cant do ('''
''')
oo ok thanks lol
You can
!e print("1\n2")
@maiden fable :white_check_mark: Your eval job has completed with return code 0.
001 | 1
002 | 2
or subclass help command

who doesnt
subclassing help is overrated
Kai
Danny
Stella
Everyone from dpy server so that people in dpy server doesn't kill them
whos Kai
if message.content.startswith('rpm hunt'):
await message.channel.send('looks like there is no animals around')
why syntax error
on the :
it shouldnt be
!d discord.ext.commands.Command use this please
class discord.ext.commands.Command(*args, **kwargs)```
A class that implements the protocol for a bot text command.
These are not created manually, instead they are created via the decorator or functional interface.
lemme read it
bruh that is wrong
Let's fix this
async def show_help():
await message.channel.send('-rpm hunt/mine\n-rpm craft\n-rpm boss/defraid\n-rpm cd\n-rpm p\n-rpm inv')
is it like this?
or should i do spacing
@bot.command() # define our command
async def hi(ctx):
#however this works
await ctx.send("H")
Like this
or @client.command(), however you've defined it
=.=
client = discord.Client()
bot = discord.Client()
The way you defined it..
It should work though...
i do it this way
import discord
import os
client = discord.Client()
############################################################
async def show_help():
await message.channel.send('-rpm hunt/mine\n-rpm craft\n-rpm boss/defraid\n-rpm cd\n-rpm p\n-rpm inv')
message is not defined tho?
no
That is incorrect
i mean
If you use message then incorrect
Wait, yes!
why is this getting syntax error

