#discord-bots
1 messages Β· Page 175 of 1
also i agree with zippy instead of him spoonfeeding yall he's giving u docs to actually learn β
I'd use a raspberri pi.
that's fine then
am doing
i'm not 'hosting' it as such right now
because it's not finished
okay
literally just running it on visual studio with the idle interpreter xd
@steep wedge lol, it just hit me, you are thinking I'm telling him to figure it out, ain't you?
lol, I was asking if they got it after linking them the docs.

ah lol
πΆβπ«οΈ
Naw, I kinda agree with ray, some coders can be just total dicks like that.
Do you know which model(s) are ideal for Discord bot hosting? If that's not off-topic for this channel.
yeah i had to self teach myself lua (not that hard to be fair but yeah) because of people like that
bear in mind i had no idea back then
That's why I'm here and not on the discord.py server.
is there even any reason to change this
the server has 20 members
Do you ever want to shut off your computer/let it go to sleep?
Well to be honest 20 isn't much I'd say older versions of the raspberri could easily handle it. However it's a "nice to have" if it's a bit faster.
it's on a raspberry pi, not my main pc, plus the bot likely won't be up 24/7
I would say no, VS eats a lot of resources.
Obviously you won't "run" it like that.
well in contrast to what i just said right now it's running on my pc and has been for several hours without me noticing... lmao
Sorry?
I don't really think it matters, it's the simplest of simple bots which probably has flawed code
I assumed you meant pi models?
That- and "what", I'm not expecting him to do anything crazy like using PIL or other heavy workloads.
Run it on a pregnancy test for all I care. it's your bot, you know what you need from it. Β―_(γ)_/Β―
Stole my joke smh
lol
yeah, it won't even exist for much longer so
I dont need a host? I can just buy a pregnancy test? Time to get a gf ig
what's happening here
pregnancy tests can be bought by anyone- you don't need a girl to do it for you :)
You don't need a gf to buy one.
Time for a TIL 
Lol
Yeah, but I'm not the 20-member server person :P
(For context I have a couple bots in-the-works, I'm using the aiosqlite library and both bots will probably be making frequent database queries. One is primarily a general-purpose, quality-of-life bot for a large server. The other is a game-bot.)
I'm coding in c# rn I've got to compensate here for the boringness.
I want to hear more about the game bot.
never mixed inter language syntax
Yeah but I prefer the impossible way
Just stop playing Roblox or FiveM.
β
i don't play roblox
i see it as- if i'm making enough money from it, why stop?
Texas Hold'em, Blackjack, etc. It is currently online and operating but I am in the middle of a re-write.
Why else would someone voluntarily code in LUA?
because it's easy
Card games, nice.
it requires practically no effort, and roblox luau is even easier
but the military community on roblox is unable to do jack shit themselves so they pay people like myself to do it for them
why would i complain
Do you get more than min wage?
or just robux?
based on monthly income, just a little below min wage, but i have a rl job also
min wage differs per country.
UK
Ouch
yeah i agree
but in all fairness- it's not that bad for a relatively easy task
Depends on how much time you spend on it and if you enjoy it.
meh it's okay
I'm trying to make it so that when a user responds to my discord bot, it stores their message in a variable, any idea how I can do that?
Here's the code:
@client.event
async def on_message(message):
if isinstance(message.channel, discord.DMChannel):
global tempVar
tempVar = message.content
return tempVar
await client.process_commands(message)
@client.event
async def on_member_join(member):
embed = discord.Embed(title="Verification", description="Please type your in game name:", color=discord.Color.blue())
await member.send(embed=embed)
inGameName = on_message(message).message.content
print(inGameName)
await member.send(inGameName)
@client.event
async def on_message(message):
if isinstance(message.channel, discord.DMChannel):
global tempVar
tempVar = message.content
return tempVar
await client.process_commands(message)
@client.event
async def on_member_join(member):
embed = discord.Embed(title="Verification", description="Please type your in game name:", color=discord.Color.blue())
await member.send(embed=embed)
inGameName = on_message(message).message.content
print(inGameName)
Your_Message = await member.send(inGameName)```
I've got no clue I asked my CS teacher and he gave me a solution but it didn't work
it doesn't even print anything for inGameName
what are you trying to do? like as a whole
on_message would have no message to retrieve-?
User joins >> Bot dm's them >> User responds >> Bot stores response in a variable
this has nothing to do with their issue??
I've got await client.process_commands(message) to fix that
not yet, but as soon as they try adding commands it will be.
they already process commands
I've got a whole bunch of commands already, just didn't send the whole file haha
yea
Β―_(γ)_/Β―
!d discord.ext.commands.Bot.wait_for perhaps use this or a modal
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.11)"). 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.11)") 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.11)") containing those arguments is returned instead. Please check the [documentation](https://discordpy.readthedocs.io/en/latest/api.html#discord-api-events) for a list of events and their parameters.
This function returns the **first event that meets the requirements**...
im playing with pandas for some reason
not entirely sure how but I'll have a look
the first example in the docs my work, though you would have to change the check a bit
Is my issue maybe that it's checking as soon as the user has joined, but there's no message the second they've joined so there's nothing to print
does anyone have a basic code that will make my bot respond? Like the total code
inGameName = on_message(message).message.content
You don't call this function, it's something that happens automatically, and even if you did try to call it you don't have a message from this function to send to the other one.
So I need to do the wait for thing to wait for a response, then run it?
you send the message in their DMs, call wait_for, then do whatever you need with the message
import discord
from discord.ext import commands
import asyncio
intents = discord.Intents.default()
client = commands.Bot(command_prefix = 'YOUR PREFIX', case_insensitive=True, intents=intents)
async def main():
async with client:
await client.start("TOKEN GOES HERE")
asyncio.run(main())
You'll have some settings to enable in the developer portal but that will work
Alright thanks :)
sure thing
Hey I'm currently coding a discord bot that will alert me in my channel every time a stock has a 13EMA cross over/cross under the 48EMA. Ive ran the code and there are zero problems but when the stock has a cross the bot doesn't alert in the channel or send anything. Any help?
Respond to what?
No errors?
anything, like just something
Correct when I ran it on VScode there are no problems and it runs fine. It just isn't sending alerts to the discord channel when the EMA's cross
I'm gonna need glasses lol
it's bigger if you open the original.
Try changing your main() into a command you can trigger.
I'm back again, it's now detecting the message and storing it but I can't get on_member_join to know what the message is
show code and elaborate pelase
@client.event
async def on_message(message):
if isinstance(message.channel, discord.DMChannel):
global tempVar
tempVar = message.content
print(tempVar + "ON MSG")
return tempVar
await client.process_commands(message)
@client.event
async def on_member_join(member):
embed = discord.Embed(title="Verification", description="Please type your in game name:", color=discord.Color.blue())
await member.send(embed=embed)
await client.wait_for('message', check=check)
print(tempVar + "ON MJ")
inGameName = on_message()
print(inGameName)
await member.send(inGameName)
you don't need the on_message
I'm getting tempVar + "ON MSG" but not tempVar + "ON MJ"
and you need to define a check
I don't need inGameName = on_message()?
you don't need to call on_message
you don't call inGameName = on_message()
what would I put there then
just delete it
nothing
wait_for returns a message object if it finds one. You can use that to define your inGameName var
For the check function what do I do?
def check(m):
return m.content == 'hello' and m.channel == channel
Do I keep it at hello? There isn't meant to be a set reply
if all the person said was hello
and in the right channel
What about if I need their response, not them to say a set thing?
you'll have to change it to check if the message is firstly inside a DM, and if the authors match
so
def check(m):
return m.content and m.channel == discord.DMChannel
It's also not in a lot of use so checking author has no point
close
you should check author
I've not coded in a while sorry haha
use isinstace, don't compare
and m.content will realistically never return a falsey value (assuming you've got message content enabled)
if isinstance(message.channel, discord.DMChannel):
...
yeah, but do that in your check
o
Yeah
I've already got that in on_message btw
@client.event
async def on_message(message):
if isinstance(message.channel, discord.DMChannel):
global tempVar
tempVar = message.content
print(tempVar + "ON MSG")
return tempVar
await client.process_commands(message)
im a beginner to python im failing it in school
yup, but you're not going to use on_message because that's not its intended use case
no if
How can we help you?
okay
you still have to check if the authors match btw
how haha
m.author == member?
I'm looking forward when the bot will reply to the user..
with using MU
in your check...
thought so just checking
This https://codewith.mu/ ?
I'm testing it and it's still doing just fine with the message in on_message but on_member_join still doesn't know what the message is. I've got this now:
@client.event
async def on_message(message):
if isinstance(message.channel, discord.DMChannel):
global tempVar
tempVar = message.content
print(tempVar + "ON MSG")
return tempVar
await client.process_commands(message)
@client.event
async def on_member_join(member):
embed = discord.Embed(title="Verification", description="Please type your in game name:", color=discord.Color.blue())
await member.send(embed=embed)
def check(m):
if m.author.id == member.id:
return isinstance(message.channel, discord.DMChannel)
inGameName = await client.wait_for('message', check=check)
print(inGameName)
await member.send(inGameName)
ye
What are you getting stuck on?
stop using global
and where do you even use tempVar anyways
basically so
i js get confused copying the instructions
you don't need on_message in this case. on_message still gets fired on DM messages. Also, in your check you have message.channel, but your check's param is called m
Was using it before this, I was trying to set inGameName equal to tempVar but been told to not haha
the check's fine....
okay right I deleted on_message and changed that, sorry for being dumb
don't even try to use global really, you should use a bot variable in your case anyways
I hate global just prayed it would work
(nvm I won't confuse you, Mr. Lee will help)
What have you made so far?
and what's a bot variable
isinstance(message.channel, discord.DMChannel) no?
oh yeah didn't notice that
Mr. Lee hehehe
π
So I got my brother to test it and I got this response
<Message id=1062087505698111558 channel=<DMChannel id=1061463231975133204 recipient=None> type=<MessageType.default: 0> author=<User id=424623683961749515 name='OutlawElite' discriminator='0642' bot=False> flags=<MessageFlags value=0>>
his message was 'bad' lol
wait_for will return a message object
if you need the contents of the message use Message.content
that's what I was using in on_message
you don't need to handle it in on_message
so is this right?
@client.event
async def on_member_join(member):
embed = discord.Embed(title="Verification", description="Please type your in game name:", color=discord.Color.blue())
await member.send(embed=embed)
def check(message):
if message.author.id == member.id:
return isinstance(message.channel, discord.DMChannel)
await client.wait_for('message', check=check)
inGameName = message.content
print(inGameName)
await member.send(inGameName)
well you're just ignoring the output of wait_for
no, it's a message object, and messages have a content attribute
it has what you need
when I printed it there's no content attribute
proof?
<Message id=1062087505698111558 channel=<DMChannel id=1061463231975133204 recipient=None> type=<MessageType.default: 0> author=<User id=424623683961749515 name='OutlawElite' discriminator='0642' bot=False> flags=<MessageFlags value=0>>
that's the repr of a Message object
it's just not printed in the repr lol
don't rely on the repr of an object, check the docs instead
the heck is a repr
google will tell
representation for the developer, in simple terms
and yes, searching the web helps in its own way
alr, so how do I get message.content?
bro
Yeah
Even I'm chuckling at this one.
aaaahhh nvm 
I'm probably being stupid but my brain is shut off rn lol
That was a mistake
get some rest, highly suggested then
guys what do you think is the best of way keeping track between commands for example when one command is running another different command is blocked cause first command affects the result of the second command
No worry, brain drain is real. might be time to take a break and get some water.
It's only 7:30 I'm just dead from school and monday
cache
or just don't make the second command
I'm still confused where message.content goes lol, can it go on the end of the await client.wait_for line or smth?
so a dictionary...
!d discord.discord.ext.commands.on_command perhaps? and set a custom attribute to the first one preventing the second one from being run
discord.ext.commands.on_command(ctx)```
An event that is called when a command is found and is about to be invoked.
This event is called regardless of whether the command itself succeeds via error or completes.
thats a good idea
before and after invokes
check in the docs what wait_for returns first
oh that exists too, right
Have you though about starting on a simpler project to lean python with? Discord.py is kinda the deep end.
or go to sleep first
a highly commendable action for developers
This function returns the first event that meets the requirements.?
π―
negative
have you actually looked at the docs yet?
it even has examples
I've been coding for years just not rlly done functions much or discord bots
touching grass too
Imma do that now 
I don't know how to respond to this.....
not to worry, we all started somewhere
I copy pasted that from the docs
that's.. honest...
right?
Or did we? 
let's get you to understanding functions first then.
you were born an expert? sign me up
also guys I promise I'm at least slightly literate with python
,
I get how they're used, just not getting variables out of them xD
where "requirements" is the check function returning True, yes
abort
return Your_Var
I will I will dw, my main motive is your will 
learning how to read the documentation is 80% of the work
10% is thinking
10% is questioning how tf to implement it if there aren't any code examples
surely the last one has a much higher percentage
I hate reading documents it takes so much effort to actually understand what's happening there vs with mine lol
yeah, but I'd have to rewrite my percentages then, and that's me being lazy (productive?)
yeah, so we play the documentation for you? won't go that way with every library though, you're quite lucky this one has lots of developers willing to guide
just increase the percentage for the examples, 100 isn't your best bet
ok I need sleep π just ignore that
ah yes, getting over 100% when adding up, this is some 0.1 + 0.2 stuff
Yeah, I mean I can struggle through it which is what I usually do but there's really not much I've found for my issues with this haha
lmaooo
as long as you don't go to YT tutorials, you're on the right path
But I still got no clue where to put the message.content
But brackeys (I'm hoping you mean copying tutorials word for word and script kidding them)
bro got back to where he started 
if wait_for returns a message object
and you only need the content of that returned object...
then the rest of the thinking work is yours
I'll give you an example π
if the tutorials are from official documentation, I could understand
Not going to lie, just reading the traceback is more than most people learn to do.
So I take the def check(message) function out of the on_member_join function I think
I've not completely new despite what it seems I swear
wait_for_method_in_discord_py_returns_a_message_object_which_is_contained_in_this_variable_and_discord_Message_has_a_content_attribute = await the_bot_or_the_client_you_are_using_to_create_your_bot.wait_for("message", check = lambda: message_that_you_have_been_eager_to_get: message_that_you_have_been_eager_to_get.author == the_author_you_want_to_compare_to_and_hope_this_is_a_User_or_a_Member_object)
the_message_content_you_have_been_dying_for_since_long_is_now_contained_in_this_variable = wait_for_method_in_discord_py_returns_a_message_object_which_is_contained_in_this_variable_and_discord_Message_has_a_content_attribute.content
Here's an example to accessing the content of a Message object
hope it helps you out and can solve your issue
that's enough for me for today

you know how much newcomers hate to read long texts, right?
it's like it doesn't exist to them
,
especially if it's coming from a bot
discord bot*
makes brain hurty
make me scratchy
double on that
that hurt my eyes but I understood it, idk why I'm being so dumb rn lol

i copy random codes online
welcome
nothing
the confidence π
Because as much as people want to say this kind of stuff is intuitive, it's not.
yea but for as much code as I've done I should've figured that out
for sure
tysm
Good luck
thx
@lofty cedar you might get use out of this too.
I'll have a look after this, so far only thing relating to my error is all french variables or smth so that's taking a bit
french variables?
yea the stack overflow thing I found, the variables are all french idk
I think ik the issue tho but maybe not
mr worldwide copy over here
YO GUYS IT WORKS
I think I'm going to write a little command line number guesser, then walk new people though how it works and why.
Thanks guys :)
Good luck with the rest.
Rest should just be repeating this for now, but ty
wait until he finds out about edge cases π
like his bot restarting and the new member not verifying before the restart
Don't make me cry
Saying should always doubles the amount of time a job will take.
People honestly copy and paste code they don't understand π
hey, which category in this help area does selenium go into in this topical chat/help area?
π
people be asking questions about the title lmao
You sound like you have worked in UI/UX before.
apparently
everybody did/does at some point
Don't normally get complements, do you?
I'm a guy
what do you even expect π
Well I'm sure you are a good guy.
you have a bad hunch on that one
I tried Β―_(γ)_/Β―
Anytime
Hello everyone
Sup Amon?
i want to call these 3 functions BUT when i do i get errors
how can i divide on_message function to a bunch of smaller ones
What errors?
Just give the entire traceback
You are searching though a string somewhere, you need to use numbers to do that.
Line 29
lol
I see what is going on
command['today']['rand_num']
in order to access the lower levels of the dictionary you need to tell it level by level what path to take.
So command is the dict, 'today' is the key you want to access to get to 'rand_num'
It's always the little things that you get caught on.
Come on back when you get caught again.
yep, been coding with python for over a year now and these things still get me
kk (if the problem is what i dont see)
I spent 3 days because I was forgetting to put something in a list first, so ya, if people claim to not have that problem every so often, stop lying.
π
Hi can someone tell me why all except one slash cmd of mine are disappearing after 6 hours
Thereβs no errors and it keeps happening
Buttons still work
cant tell without code perhaps you are syncing multiple times
Not from here. Would need more info, like your code.
!paste
Pasting large amounts of code
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the floppy disk icon in the top right, or by typing ctrl + S. After doing that, the URL should change. Copy the URL and post it here so others can see it.
@shrewd apex https://paste.pythondiscord.com/ohukifahih
sorry was on mobile couldnt send it
create_verify_button is the one that only works after 6 hours (before 6 hours, everything works as intended)
how get all the bot guilds?
using the api it self not libs
nevermind, this is prolly what is causing the error:
!d discord.Client.guilds
property guilds```
The guilds that the connected client is a member of.
But can anyone tell me why create_verify_button is the only one that works and also the cause of the unknown interaction for the defer msg
u need custom id for each component time out as none add the views also respond to each interaction between 3 seconds if not defer it after that u can edit it with edit_original_response
also srsly the whole code base needs a re haul
wdym
yeah prolly
heya, does discord.py work with aws ec2?
"u need custom id for each component time out as none" so i removed the custom id for every button view?
"also respond to each interaction between 3 seconds if not defer it after that u can edit it with edit_original_response"
So howo do I know if it responds between 3 seconds, do I use is_done or? Like idk what I would set the contition to respond send msg
just use the endpoint https://discord.com/developers/docs/resources/user#get-current-user-guilds
Integrate your service with Discord β whether it's a bot or a game or whatever your wildest imagination can come up with.
yes
u need custom id and timeout both the timeout must be None and custom id unique for each component
i'm getting
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
whenever i try
u dont so based on ur host u have to make decision to defer or not
logs
I did have a custom id that are unique for each component and have them as none
also once u have responded u can respond again unless u use the followup u can only edit ur response
is it the same every time?
i was telling my observations cause currently the state of code is not too optimistic plus i am on mobile
yeah
Using cached discord-2.1.0.tar.gz (1.1 kB)
ERROR: Command errored out with exit status 1:
command: /usr/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-xwqHsE/discord/setup.py'"'"'; __file__='"'"'/tmp/pip-install-xwqHsE/discord/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-33YLzi
cwd: /tmp/pip-install-xwqHsE/discord/
Complete output (5 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-xwqHsE/discord/setup.py", line 5, in <module>
with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
TypeError: 'encoding' is an invalid keyword argument for this function
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.```
do u have python installed
so after I respond with either defer and send_msg, you mean that I should use respond edit msg or something idk?
yes
am a lil confused what u mean by that
with version 3.8 or greater
yes
pip works for other packages as well
!d discord.Interaction.edit_original_response
await edit_original_response(*, content=..., embeds=..., embed=..., attachments=..., view=..., allowed_mentions=None)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Edits the original interaction response message.
This is a lower level interface to [`InteractionMessage.edit()`](https://discordpy.readthedocs.io/en/latest/interactions/api.html#discord.InteractionMessage.edit "discord.InteractionMessage.edit") in case you do not want to fetch the message and save an HTTP request.
This method is also the only way to edit the original message if the message sent was ephemeral.
!pypi discord.py u sure u are installing this package and not some mirror?
oh i was using this already
ah, its 2.7
any idea on how to update python on an ec2 instance?
so see just remember this in an interaction u can use the .response to perform an action only once
after that u have to use the interaction instance
lol i never used ec2 but i can try is it like a vm/vps u have acess to it's terminal?
are u able to like write commands?
yeah ik that
dosent reflect in code which causes those errors
that is why I had response defer, then edit original response, then followup
Is it running amazon linux or what?
yeah, googled a guide, thanks for the help
but it gave error in defer so im guessing i haev to use respond msg
yes
the errors were bc of the defer so ill try the thing you said, but i solely changed to defer beacuse it had an error for response msg
used azure never ec2 coz no cc
Ah damn, I can't put discord.ui.TextInput onto a post like you could a button can I?
its not able to find the message to defer
u can add textinput only in modals
I was afraid you would say that.
what for tho? u wanted to add it in embed or something?
just use a button send the modal
how, there is an interaction response defer msg
btw u can also add selects in modals apparently but last time i tried a few months ago it didn't show up on mobile client so i ditched the idea u can try it out if need be
Thanks for the ideas.
Do you guys know why I can't run my bot?
Traceback (most recent call last):
File "blitz.py", line 11, in <module>
from discord.ui import Button, View
ModuleNotFoundError: No module named 'discord.ui'
Requirement already satisfied: discord-ui in /usr/local/lib/python3.7/dist-packages (5.1.6)```
defer in first line then just use edit_original throughout and tell if u get any errors
install the latest discord.py and update ur python version
u need python 3.8+
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.```
you don't need import discord.ui
just import discord
yeah i can see itz 3.7 
The GCC 8.3.0 isn't the Python version btw

So I don't need from discord.ui import Button, View
for my buttons?
u can dosent affect the root cause
ur python version and dpy lib version
thats the problem
You need to have discord.py 2.0+ to use components. And to have discord.py 2.0+, you also need Python 3.8+
I don't need to,
I just run import discord
and
class Stats(discord.ui.View):
def __init__(self):
super().__init__()
@discord.ui.button(label="Stats", style=discord.ButtonStyle.green, disabled=False)
async def StatsButton(self, interaction, button):
embed = discord.Embed(title=interaction.user.name)
works just fine
can you help with this code please? its giving me an error
it says this
disabled is false by default
Good to know.
i created a embed but it says that
I'm using
button2 = Button(label="Ban Appeal", url="LINKHERE", style=discord.ButtonStyle.link, emoji="βοΈ")
view = View()
view.add_item(button2)```
my command prefix is β/β
command not found i don't know how to explain it better Β―_(γ)_/Β―
You don't have a command in your bot named embed
bro read thats not the issue
heres my code
we have tried to explain multiple times
That's not the latest nor newest version

3.11.1 is the latest version π
import discord
from discord.ext import commands
class MyCog(commands.Cog):
def init(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print("Mycog.py is online")
@commands.command()
async def embed(self, ctx):
embed_message = discord.Embed(title="Axd is the move", description="Axd is gay", color=discord.Color.blue())
embed_message.set_thumbnail(url=ctx.guild.icon)
embed_message.set_image(url=ctx.guild.icon)
embed_message.set_author(name=f"requested by (ctx.author.mention", icon_url="https://media.discordapp.net/attachments/1061002034364547074/1062094710224736288/IMG_3440.jpg?width=468&height=468")
embed_message.add_field(name="field name", value="field value", inline=False)
embed_message.set_footer(text="this is the footer", icon_url=ctx.author.avatar)
await ctx.send(embed = embed_message)
async def setup(client):
await client.add_cog(MyCog(client))
maybe higher idk
let me make it better for u to read
How do I install it on linux? The OS is already saying its the latest
from discord.ext import commands
class MyCog(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print("Mycog.py is online")
@commands.command()
async def embed(self, ctx):
embed_message = discord.Embed(title="Axd is the move", description="Axd is gay", color=discord.Color.blue())
embed_message.set_thumbnail(url=ctx.guild.icon)
embed_message.set_image(url=ctx.guild.icon)
embed_message.set_author(name=f"requested by (ctx.author.mention", icon_url="https://media.discordapp.net/attachments/1061002034364547074/1062094710224736288/IMG_3440.jpg?width=468&height=468")
embed_message.add_field(name="field name", value="field value", inline=False)
embed_message.set_footer(text="this is the footer", icon_url=ctx.author.avatar)
await ctx.send(embed = embed_message)
async def setup(client):
await client.add_cog(MyCog(client))```
thats my command code heres the prfix one
go google how to update python verison to 3.10 ubuntu
follow the steps online
from discord.ext import commands
client = commands.Bot(command_prefix="=", intents=discord.Intents.all())
@client.event
async def on_ready():
print("Success: Bot is succesfully loaded.")
@client.command()
async def ping(ctx):
await ctx.author.send("Pong!")```
```py
at the top for python highlighting
You're not loading the extension
wym
ubuntu official release is not out so u will have to get from a mirror repo ppa:deadsnakes iirc
import discord
from discord.ext import commands
class MyCog(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print("Mycog.py is online")
@commands.command()
async def embed(self, ctx):
embed_message = discord.Embed(title="Axd is the move", description="Axd is gay", color=discord.Color.blue())
embed_message.set_thumbnail(url=ctx.guild.icon)
embed_message.set_image(url=ctx.guild.icon)
embed_message.set_author(name=f"requested by (ctx.author.mention", icon_url="https://media.discordapp.net/attachments/1061002034364547074/1062094710224736288/IMG_3440.jpg?width=468&height=468")
embed_message.add_field(name="field name", value="field value", inline=False)
embed_message.set_footer(text="this is the footer", icon_url=ctx.author.avatar)
await ctx.send(embed = embed_message)
async def setup(client):
await client.add_cog(MyCog(client))```
!d discord.ext.commands.Bot.load_extension you're not calling this
await load_extension(name, *, package=None)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Loads an extension.
An extension is a python module that contains commands, cogs, or listeners.
An extension must have a global function, `setup` defined as the entry point on what to do when the extension is loaded. This entry point must have a single argument, the `bot`.
Changed in version 2.0: This method is now a [coroutine](https://docs.python.org/3/glossary.html#term-coroutine "(in Python v3.11)").
```py
import discord
from discord.ext import commands
class MyCog(commands.Cog):
def init(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print("Mycog.py is online")
@commands.command()
async def embed(self, ctx):
embed_message = discord.Embed(title="Axd is the move", description="Axd is gay", color=discord.Color.blue())
embed_message.set_thumbnail(url=ctx.guild.icon)
embed_message.set_image(url=ctx.guild.icon)
embed_message.set_author(name=f"requested by (ctx.author.mention", icon_url="https://media.discordapp.net/attachments/1061002034364547074/1062094710224736288/IMG_3440.jpg?width=468&height=468")
embed_message.add_field(name="field name", value="field value", inline=False)
embed_message.set_footer(text="this is the footer", icon_url=ctx.author.avatar)
await ctx.send(embed = embed_message)
async def setup(client):
await client.add_cog(MyCog(client))
```
What does dpy lib mean?
u need to call it async
at this point how did u even find this channel...
!pypi discord.py
You doing ok Asher?
can i dm you something?
someone uses dpy across whole project and asks what dpy means ;-;
discord.py library??
I rather not, you can send whatever you need here
ok
Not everyone knows as much as you, expecting them to is unfair to them and yourself.
so can you help me call it im very very new to this
its just name of the library tho 
I can show you how I do it.
I would say such behavior makes helping better
First of all, do you know how to call functions/methods?
Ok, I don't expect you to understand this, but I will try and explain what it does
if sys.platform == "win32" or sys.platform == "win64":
for file in os.listdir(f"{FilePath}\\Cogs"):
if file.endswith("Cog.py"):
await Bot.load_extension(f'Cogs.{file[:-3]}')
print(f"{file} Loaded")```
try being the key word
pathlib best
Then we've got ourselves a problem
Nevermind, starting smaller.
def Function(X):
X+=1
return X
Y=4
NewNumber = Function(Y)
print(NewNumber)
Understand any of this?
if i say no will you get mad π
Not at all, it's best if we are both on the same page
ah yes, CamelCase for function names and variable names
you also forgot 1 more line after the function definitionπ‘
You get what you pay for around here Β―_(γ)_/Β―
ok lets get on the samepage
what if you dont have money? Is chocolate a valid currency?
automatic cog loaders, unless you specifically need a drop-in hot reload functionality, are a waste of brain power
Just put the names in a tuple and be done with it
is it best if we go to dms?
import pathlib
async def setup_hook():
for file in pathlib.Path("Cogs").glob('*.py')
if file.name.startswith('_'):
continue
await client.load_extension(f"Cogs.{file.name.split('.')[0]}")
client.setup_hook = setup_hook
alr, seems like its working so ahrd, need more people to test it but i'll let u know if anything happens. Thank you very much for ur help! :pog
man im async ded
Naw, I'm a huge fan of cunningham's law. you will get more info if we stay here.
my emotions rn
np
skill issue
tru need to grind more
if there is one thing nerds like more then being right, it's another person being wrong.
get my immunity level higher
my guy
He's right, if you see this whole server they like proving others wrong and love doing it
alr
@manic knoll u can copy paste assuming cog is in cogs folder and ur bot python file is same directory as cogs folder
Everyone who drivers slower than me is an idiot, and anyone that drives faster than me is a menace
thats why python server op
Really puts into perspective why people are so fast to fix bad code but ignore people that don't post any code.
Only space is faster than me, cuz i got the speed of light
noid be watching science shows
Dont start with tachyon particles though or elseπ«
code fixes are boring. I like talking about solving problems in abstract. Otherwise 90% of the code posted is something that is easily solved by reading the documentation
Got a whole ted talk
Ya, the past can't handle those.
stick ur head in a particle collider
brain fart
true
I don't think they are Anatoli Bugorski.
everyone saw the talk
I'm a dog with a computer, of course not
ok so i have all the stuff done i just dont understand this error like what did i do wrong
I see, makes a lot of sense now.
just like life 
Okay I'm installing python 3.9 since it's the stable version, 3.10 and 3.11 is still under bugfix, right?
indents go brrr
Are you talking about wheels?
3.11 came out u think 10 is under bug fix?
he had python 3.7 asked him to update
Sorry, the peanut gallery has killed my teaching mood. Might ask one of them to step up and help you if they have the gumption to.
alright
Anya is the type of person to go to a peanut gallery
can someone help with this
my teaching mood up there high with anya
Go to sleep
dedent the listener by one level
go to sleep already you indian lad
okie
@shrewd apex I installed it but its still saying I have the old version. Do I have both versions now or what?
python3
Python 3.7.3 (default, Oct 31 2022, 14:04:00)
[GCC 8.3.0] on linux
python3.11 --version
Python 3.11.0```
After you help certified of course
no takesies backsies
I should have put a bet on that.
Still around?
yep
Seeing as how you are brand brand new to python https://automatetheboringstuff.com/#toc
That site will walk you though the basics.
ok so what in that site should i click to help me remove the error
This ain't like that
This site is to teach you python so you don't need to ask that question.
I don't see your full code Certified, so its hard to say, but the indent on the listener is very out of place and means there could be more of an issue. The actual command overall looks fine
makes me wonder if the cog is even loaded
It's not, we tried walking them though it about 5 times now. I'm just trying to get them to learn basic python.
ah
hey how could I fix this?
It's hard to tell without the entire traceback/report
that was all it
no it's not
@bot.command()
async def verify(ctx):
sender = ctx.author
image = ImageCaptcha(width=280, height=90)
captcha_text = random.randint(100000, 999999)
data = image.generate(captcha_text)
role_has = discord.utils.get(ctx.guild.roles, name='User')
if role_has in ctx.author.roles:
await ctx.respond('You are verified!', ephemeral=True)
else:
await ctx.respond('Check your DMs!', ephemeral=True)
image.write(captcha_text, 'captcha/CAPTCHA.PNG')
await sender.send('Write what the captcha has!', file=discord.File('captcha/CAPTCHA.PNG'))
print(captcha_text)
while True:
msg = await bot.wait_for("message", check=lambda check: check.author.id == ctx.author.id)
if msg.guild == None:
break
print(msg.content)
if msg.content == captcha_text:
await sender.send('Correct, you should be verified!')
role = discord.utils.get(ctx.guild.roles, name='User')
await sender.add_roles(role)
else:
await sender.send('Incorrect, try again!')```
can't find the problem
Discord.py and nextcord are fighting, you can only use one or the other.
Oh
Error?
it could possibly be an intents problem then because when I tried to make my own welcome message I had no errors in the console too!
Where does print show up at?
know how to codeblock?
code ^^
Yep
@commands.Cog.listener()
async def on_member_join(self, ctx, member: nextcord.Member):
embed = nextcord.Embed(
title= f"Welcome {member}",
description=f"""> Welcome to Eagle Bird LLC
> A quick tour around the server!
[#1059268832956518415](/guild/267624335836053506/channel/1059268832956518415/)
> γ Make sure you obey those rules in order to avoid any consequences.
[#1059268832956518416](/guild/267624335836053506/channel/1059268832956518416/)
> γ Stay tuned for news & updates!
[#1059268833124298824](/guild/267624335836053506/channel/1059268833124298824/)
> γ Chat and engange with the community.
[#1059268833124298828](/guild/267624335836053506/channel/1059268833124298828/)
> γ Take your enjoyment to the max by using our bots!
""",
colour = (nextcord.Color.green()))
channel = ctx.bot.get_channel(1059268833124298822)
embed.add_field(name="Created at:", value=datetime.strftime(member.created_at, "%A, %B, %D-, %Y"))
embed.set_thumbnail(url=member.avatar)
await member.add_roles(Member_role)
await channel.send(embed=embed)
Member_role = nextcord.utils.get(ctx.guild.roles, name="Members")
await member.add_roles(Member_role)
```
nope discord.py
Oh, good luck then, I don't know anything about nextcord.
nextcord is very similar to discord.py
you could just tell me in discord.py terms
@crimson mauve
didn't understand (bad english)
when you call print("string"), where does it print to?
can't speak spanish either π
Does anyone know how to help with the Eof while parsing error?
Your DMs, here on discord?
Now I'm just confused.
oh, you don't know what print() is, do you?
sigh
What is the latest discord.py version?
i just cant figure out anything
Where are you hitting a wall?
thanks
ERROR discord.ext.commands.bot Ignoring exception in command None
discord.ext.commands.errors.CommandNotFound: Command "embed" is not found
there is where i am
Good luck, enjoy the adventure.
like bro how am i not done with that
ty
i have a command and everything
@commands.command()
async def embed(self, ctx):
embed_message = discord.Embed(title="Axd is the move", description="Axd is gay", color=discord.Color.blue())
embed_message.set_thumbnail(url=ctx.guild.icon)
embed_message.set_image(url=ctx.guild.icon)
embed_message.set_author(name=f"requested by (ctx.author.mention", icon_url="https://media.discordapp.net/attachments/1061002034364547074/1062094710224736288/IMG_3440.jpg?width=468&height=468")
embed_message.add_field(name="field name", value="field value", inline=False)
embed_message.set_footer(text="this is the footer", icon_url=ctx.author.avatar)
await ctx.send(embed = embed_message)
Ah, still on that.
Know the difference between a string and an integer yet?
nope
I tried giving you what you need, we are not going to write your code for you, this place is here to get you to the point you can write it yourself. Β―_(γ)_/Β―

This is my first video in the series βKids Python 101β. I will share my experience of learning Python courses that my Dad has developed on http://kidspython.com with you. In this lesson, you will learn how to write your first line of Python code.
Just use RealPython which has more information and is more explicit
I'm getting the feeling they don't want to learn, they want to already know.
Traceback (most recent call last):
File "/root/blitz.py", line 1, in <module>
import discord
File "/usr/local/lib/python3.11/site-packages/discord/__init__.py", line 23, in <module>
from .client import *
File "/usr/local/lib/python3.11/site-packages/discord/client.py", line 49, in <module>
from .user import User, ClientUser
File "/usr/local/lib/python3.11/site-packages/discord/user.py", line 29, in <module>
import discord.abc
File "/usr/local/lib/python3.11/site-packages/discord/abc.py", line 59, in <module>
from .voice_client import VoiceClient, VoiceProtocol
File "/usr/local/lib/python3.11/site-packages/discord/voice_client.py", line 49, in <module>
from . import opus, utils
File "/usr/local/lib/python3.11/site-packages/discord/opus.py", line 30, in <module>
import ctypes
File "/usr/local/lib/python3.11/ctypes/__init__.py", line 8, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'```
What does this mean?
What is _ctypes?
I don't know. But do you know why my bot won't running?
There is nothing in basic python called _ctypes
Look at what you are typing, now look at the example in the link I sent you.
!e
import _ctypes
@primal token :warning: Your 3.11 eval job has completed with return code 0.
[No output]
Also, what are you doing with ctypes anyway? Why do you need access to dll files on windows?
I don't know what you are trying to say. But I received this errors after updating python.
I'm just wondering what you had been using _ctypes for to start with. Where did you get this code?
There is no _ctypes in my code.
This says otherwise.
discord/opus.py line 30
import ctypes```
Beerhunter are you on linux?
Yes
Oh, they must be using some old discord.py then
Hope this article helps
https://www.pythonpool.com/modulenotfounderror-no-module-named-_ctypes-solved/
Its an issue related to ubuntu
Good eye, here I was thinking they downloaded a script that was going to mess with them
Never actually encountered it since i haven't used ubuntu
So from my understanding it's because I updated Python without installing the libffi-dev package beforehand
When updating python to a version of 3.7.0 >, yes
Thanks noid
π
7 months.
Dodging is OP, balance changes requested
Well I feel like being able to dodge an attack and simultaneously hit for 5 is quite a lot
how do i make it so like i do !add (value) and then it adds the amount of (value) to a different embed
idk if that makes sense
so like
!add 7 (user)
!view (user)
(in the embed it says user has 7)
and then if u do it again it adds the 2 numbers
.
@client.command()
async def level(ctx):
member = ctx.author
xp = levels_data[str(member.id)]['xp']
level = levels_data[str(member.id)]['level']
await ctx.send(f'{member.mention} is level {level} with {xp} XP')
print("Done")
question, when i run !level it doesnt do anything, it doesnt even print done in the console, any ideas why this wont work?
doesnt do anything at all, its like it doesnt even see the command
^
Do you have any on_message functions?
not sure if yall need more context but-
why is this command showing up twice
can some1 help me? ^
Probably because you've synced the command specifically to that guild as well as globally.
so how do i fix this?
how do i make it so like i do !add (value) and then it adds the amount of (value) to a different embed
so like
!add 7 (user)
!view (user)
(in the embed it says user has 7)
and then if u do it again it adds the 2 numbers
make sure you dont have a guild command of the same name or used tree.copy_global_to() on that guild, then use tree.sync(guild=...) to delete the duplicated command
https://paste.pythondiscord.com/nopiwacefo
this is my current sync command- how would go about making sure no more dupes occur?
well you have two options for storing the number for each user:
- put it in memory with some python data structure like a dictionary (not persistent)
- put it into a database on disk and then grab the number from it when you need it
dont use copy_global_to()
or at least have a way for your command to sync a guild without using that method
ffff
i have this code
@client.command()
async def viewlogs(ctx, member: discord.Member = None):
if member == None:
member = ctx.author
embed=discord.Embed(title=f'{member} Logging', description="_ _", color=0xBB1A24)
embed.add_field(name="Total Shifts", value="N/A", inline=False)
embed.add_field(name="Total Sessions", value="N/A", inline=False)
embed.add_field(name="Weekly Logs", value="N/A", inline=False)
embed.set_author(name = f'{member}', icon_url = member.avatar_url)
await ctx.send(embed=embed)
@client.command()
async def addshift(ctx, member: discord.Member = None):
if member == None:
member = ctx.author
await ctx.send(f"Added 1 shift to {member}")
@client.command()
async def addsession(ctx, member: discord.Member = None):
if member == None:
member = ctx.author
await ctx.send(f"Added 1 session to {member}") ```
this is what i have, i have no clue how to do it. i was wondering if u could possibly help me and tell me what to put in the value area if possible?
you need to decide how you want to store your data
if you want to start simple, use a python dictionary and see how you can make your commands update the values in your addshift/addsession commands and how to retrieve them in your viewlogs command
do u have one?
dictionaries are a very helpful data structure and its worth reading about them
https://realpython.com/python-dicts/
but they are simply a way to associate values to different things
is there a way to make a function that always sends a message after the last message in chat?
Example:
Bot message: type !support for help
User message: !support
Bot message: type !support for help
and the first bot message get deleted
tbh i'd just use a dictionary for that too
store the last support message for each channel, and delete it whenever the !support command is used
im like super confused still
you can add mentions in the title of embeds right? or is it only description
only description and field value
do u think u can like give me an example code or something
Apparently
is that title or description?
Title
bruh no way it works for title and field name on mobile
Try it with a webhook π€·
delete this now, the FBI is coming for you
consider how a dictionary can be used to track the number of donuts for different people: ```py
person_donuts = {"Luke": 4, "Andy": 7}
Add a donut for Luke:
person_donuts["Luke"] += 1
^^^^^^ ^ this is the "value"
\ this is the "key"
Add a new person, Rea, with 9 donuts
person_donuts["Rea"] = 9
Print the number of donuts for Andy:
donuts = person_donuts["Andy"]
print(donuts)
7
print(person_donuts)
{'Luke': 5, 'Andy': 7, 'Rea': 9}``` do you see how dictionaries work? and how it applies to the shift/session counter you're trying to write? instead of arbitrary people, you'd use the "member" of your command as the key, and an integer count as the value
πΏ title mentions hmm
aw man
discord do be weird with designs πΆββοΈ
sadge
on_error should be a coroutine π€
Modals are supposed to close on their own after hitting summit, right?
the lambda returns a coroutine
someone know how i can install discord components?
:looli: the code is tested ofc
oh, asyncio.sleep 
don't use discord components, discord.py has views for buttons and other components
!d discord.ui.View
class discord.ui.View(*, timeout=180.0)```
Represents a UI view.
This object must be inherited to create a UI within Discord.
New in version 2.0.
thought you'd block too
yes
Welp, time to fine out what I screwed up this time.
actually
i just want my application to be error free, but functional π
they close if they've got a successful interaction response, otherwise they error

this server has some... unique custom emojis
That's the funny thing, everything under async def on_submit(self, interaction): is working just fine, the window just won't close on its own.
sounds like a Discord issue to me 
it wont close if you don't respond to the interaction properly
i.e. your callback is faulty
It's closes when you respond to it
can't import select from discord
class discord.ui.Select(*, custom_id=..., placeholder=None, min_values=1, max_values=1, options=..., disabled=False, row=None)```
Represents a UI select menu with a list of custom options. This is represented to the user as a dropdown menu.
New in version 2.0.
yh my bad, i imported it from discord not from discord.ui
Select is a read only class, while ui.Select ( which subclasses Select ) is the constructor
oh ok
https://pastes.dev/VZG9E2Vi3f i cant find errors in the code and in console
lol, it's not
What's the problem
What is a challenging command to create?
idk
Then how would people help you if you don't even know what's wrong
Also why's your ticket command in on_ready listener
its a cog
i don't have an error logger
You need to respond to the interaction in the modal callback
lol, knew it was going to be somthing dumb
I just said it closes after you respond to it
thanks, I'll go find out how to do a modal callback then.
It was interaction.response.defer() for the record.
how do I create something that constantly checks for messages between two users when they execute a command (tic tac toe)
it's client.command**(), not client.commands**
oh tysm
Lee is right, discord.ui is such a gamechanger.
But that being said. https://github.com/Rapptz/discord.py/blob/master/examples/views/tic_tac_toe.py
could anyone help with this
you have to be a specific role to ping someone
a / command
does this allow everyone to click buttons? Oh I don't see where it is user specific 
oblique command 
do you want to make the user argument optional?
yea
Hello, I hope this is the right channel for this. I was wondering if there is anyone that can help me work through an issue Iβm having with my discord bot code. We can do it in dm or in here, whatever is the most comfortable.
Hello! We prefer to keep things in-server. Go ahead and ask your question
so just deleting it would solve my problems?
sounds good, tyvm for your time first of all.
so there isn't an error that pops up, so given my lack of experience, it kinda leaves me without much to go on. what i'm going for is a to pull a random monster from a list (the list is a bit extensive but i don't think that should effect anything) with a command and eventually after that i would like to make it pull a response from 2 different lists, but first got to get it to work. my issue comes from when i do the command nothing pops up in discord. below is the code:
import discord
import random
from discord.ext import commands
#intents for the new update for discord devs.
intents = discord.Intents.default()
intents.message_content = True
#command to talk to the bot
bot = commands.Bot(command_prefix='!', intents=intents)
@bot.event
async def on_message(message):
if message.content == "Hi".lower():
await message.channel.send("Hey, good to see ya!")
@bot.command()
async def rando(ctx):
monster = ['m1',
'm2',
'm3',
'm4',
'm5']
await ctx.send(f'here is your target{random.choice(monster)}')
Change your @bot.event to @bot.listen() and you should be good to go
will try now!
oh, ok sorry for the confusion, the issue comes to the command one
Yes, but your @bot.event stops all other commands from running
which has the list to pull the random from the list, i just linked the whole code to incase if there was something that was messing it up
will try now!
could anyone help me code something like this? okay so this is basically something where i select a user to ping and i will have a embed that says βYou have been offered by (author)β but i have to have a certain role to do this
YOU ARE AMAZING!!!!
I take it it worked? π
absolutely!
Awesome, glad to hear
thank you so much!
No worries. Have fun!
@sick birch
use a check
sorry im very new to all this so im a little confused
a moment
first of all, what library are you using for slash commands?
i do @woeful haloent.tree.command()
right so you need to use a check
https://discordpy.readthedocs.io/en/stable/interactions/api.html#discord.app_commands.checks.has_role
@app_commands.checks.has_role(role_id/role_name)
``` above your command
for a slash command, i want the user to pass in a enum- basically, a str that can only take a set range of values (like apple and banana only)
is this possible? if so, how would i go about doing it?
I would like to code a command where a member enters a hexadecimal (e.g. FFFFFF) and the bot replies with an embed that contains just that colour. How can I go about doing this?
@bot.tree.command(name='color', description='Displays a color using a hexadecimal')
async def color(interaction: discord.Interaction, color: str):
embed = discord.Embed(title=(f'{color} is displayed as:'), color=0xf6ff00)
embed.set_image(url=color)
await interaction.response.send_message(embed=embed)```
async def command(inter: discord.Interaction, option: typing.Literal["apple", "banana"])
``` works
but you can use an enum too
!d discord.Color.from_str
No documentation found for the requested symbol.
classmethod from_str(value)```
Constructs a [`Colour`](https://discordpy.readthedocs.io/en/latest/api.html#discord.Colour "discord.Colour") from a string.
The following formats are accepted...
forgot discord.py uses british english mainly
W
you basically pass the user input in this classmethod to get the color for that value
πΆββοΈ even tho discord asks for color
so the enum.Enum? and i do it through type annotations?
oh lol, thx
the type annotation is the easy way to do that,
but if you still want to use an enum this would be the format ```py
class MyEnum(Enum):
apple = ...
banana = ...
async def command(inter: discord.Interaction, arg: MyEnum) -> None:
ok so couldnt i also do something like @commands.has_role(ββ)
Sorry for the late reply
@client.event
async def on_message(message):
if message.author == client.user:
return
No prob. You have this same issue: #discord-bots message
so instead of client.event switch it to client.listen()?
Yeah
pog thankies ill test it out in a bit
what part to be specific? what are you unable to do
allπ
How do I set the embed thumbnail to be just the colour the user provides? (e.g. if they provide ffffff the thumbnail is just pure white)
@bot.tree.command(name='color', description='Displays a colour from a hexidecimal')
async def color(interaction: discord.Interaction, color: str):
int_color = int(color,16)
RGB = tuple(int(color[i:i+2], 16) for i in (0, 2, 4))
embed = discord.Embed(color = int_color)
embed.set_thumbnail()
embed.add_field(name='Hexadecimal', value = f'#{color}')
embed.add_field(name='RGB', value = f'{RGB}', inline=False)
await interaction.response.send_message(embed=embed)```
you'll have to use some api or something for that
or pillow to create an image with your color
Any guides I can follow for that?
if you create a request to this url, you'll find an image field
which has the url for an white image
you can do it that way
https://singlecolorimage.com/get/<your hext>/100x100
and use embed.set_thumbnail to set it
You can type hint discord.Color
Oh I misread the question
Would this work? Embed.set_thumbnail(url=f'https://singlecolorimage.com/get/{color}/100x100')
if Embed is your discord.Embed class, yes
I have this:
@bot.tree.command(name='color', description='Displays a colour from a hexidecimal')
async def color(interaction: discord.Interaction, color: str):
int_color = int(color,16)
RGB = tuple(int(color[i:i+2], 16) for i in (0, 2, 4))
embed = discord.Embed(color = int_color)
embed.set_thumbnail(url=f'https://singlecolorimage.com/get/{color}/100x100')
embed.add_field(name='Hexadecimal', value = f'#{color}')
embed.add_field(name='RGB', value = f'{RGB}', inline=False)
await interaction.response.send_message(embed=embed)```
yes it will work
Doesn't send thumbnail
also as robin said, improvement can be made in your code! ```py
async def color(interaction: discord.Interaction, color: discord.Color):
hex_of_color = str(color)
rgb_of_color = (color.r, color.g, color.b)
ill check wait
the api seems to be case sensitive, use color.lower() that should fix it
Only works with white? wha
@bot.tree.command(name='color', description='Displays a colour from a hexidecimal')
async def color(interaction: discord.Interaction, color: str):
int_color = int(color,16)
color = color.lower()
RGB = tuple(int(color[i:i+2], 16) for i in (0, 2, 4))
embed = discord.Embed(color = int_color)
embed.set_thumbnail(url=f'https://singlecolorimage.com/get/{color}/100x100')
embed.add_field(name='Hexadecimal', value = f'#{color}')
embed.add_field(name='RGB', value = f'{RGB}', inline=False)
await interaction.response.send_message(embed=embed)```
do you know how to make a request?
web request with aiohttp i.e.
It works fine in the browser.
You can use pillow to create your own thumbnail then
the io is not worth it when it can be done with a simple aiohttp request
a simple get req
I disagree. The image is generated quickly, and using an API request introduces a dependency on a third party service which comes with its own set of problems
Nope
just wanted to avoid a dependency and extra executors
do you use pillow or any image generator in your bot already?
@bot.tree.command(name='color', description='Displays a colour from a hexidecimal')
async def color(interaction: discord.Interaction, color: str):
async with aiohttp.ClientSession() as session:
data = await session.get(f'https://singlecolorimage.com/get/{color}/400x400')
await interaction.response.send_message(hk.Embed(title='color').set_thumbnail(hk.Bytes(data.content,'color.png')))```
Oh, right
1 minute, ill have to see how discord.py takes bytes
!d discord.File
!local-file
import io
file = discord.File(io.BytesIO(data.content), filename="color.png")
embed.set_image(url="attachment://color.png")
await interaction.response.send_message(embed=embed, file=file)
@pulsar kettle this should do
*set_thumbnail
file = discord.File(io.BytesIO(data.content), filename="color.png") the data in data.content "is not defined Pylance
Whole code:
@bot.tree.command(name='color', description='Displays a colour from a hexidecimal')
async def color(interaction: discord.Interaction, color: str):
int_color = int(color,16)
RGB = tuple(int(color[i:i+2], 16) for i in (0, 2, 4))
file = discord.File(io.BytesIO(data.content), filename="color.png")
embed = discord.Embed(color = int_color)
embed.add_field(name='Hexadecimal', value = f'#{color}')
embed.add_field(name='RGB', value = f'{RGB}', inline=False)
embed.set_thumbnail(url="attachment://color.png")
await interaction.response.send_message(embed=embed, file=file) ```
you still need that py async with aiohttp.... lines
just the way you send interaction changes
so like this?```python
@bot.tree.command(name='color', description='Displays a colour from a hexidecimal')
async def color(interaction: discord.Interaction, color: str):
int_color = int(color,16)
RGB = tuple(int(color[i:i+2], 16) for i in (0, 2, 4))
file = discord.File(io.BytesIO(data.content), filename="color.png")
async with aiohttp.ClientSession() as session:
embed = discord.Embed(color = int_color)
embed.add_field(name='Hexadecimal', value = f'#{color}')
embed.add_field(name='RGB', value = f'{RGB}', inline=False)
embed.set_thumbnail(url="attachment://color.png")
await interaction.response.send_message(embed=embed, file=file)```
um no
async with aiohttp.ClientSession() as session:
data = session.get("the url")
file = discord.File(io.BytesIO(data.content), filename="color.png")
# rest of your code
# embed = discord.Embed....
Also you need to await the .get to get the response object
And close using .close to release the connection
Or just use the context manager 
just don't use aiohttp 
just set the default value of user argument to None
how do i make it so like i do !add (value) and then it adds the amount of (value) to a different embed
!add 7 (user)
!view (user)
(in the embed it says user has 7) and then if u do it again it adds the 2 numbers i have this code
@client.command()
async def viewlogs(ctx, member: discord.Member = None):
if member == None:
member = ctx.author
embed=discord.Embed(title=f'{member} Logging', description="_ _", color=0xBB1A24)
embed.add_field(name="Total Shifts", value="N/A", inline=False)
embed.add_field(name="Total Sessions", value="N/A", inline=False)
embed.add_field(name="Weekly Logs", value="N/A", inline=False)
embed.set_author(name = f'{member}', icon_url = member.avatar_url)
await ctx.send(embed=embed)
@client.command()
async def addshift(ctx, member: discord.Member = None):
if member == None:
member = ctx.author
await ctx.send(f"Added 1 shift to {member}")
@client.command()
async def addsession(ctx, member: discord.Member = None):
if member == None:
member = ctx.author
await ctx.send(f"Added 1 session to {member}") ```
this is what i have, i have no clue how to do it. i was wondering if u could possibly help me and tell me what to put in the value area if possible?
how can i import this class without needing to declaring bot in the file where i import it to
why would you import a cog?
you can simply load it
i made contraption for my database function
so i dont need to do the large chunk of sql syntax
i just need some parameter to make the code cleaner and readable
then why's it a cog 
wait make sense
wtf am i thinking
and btw how do i define bot
^
you want to make a class that does database stuff for you?
Sarth's gonna help 
sarth's getting away in a minute
can you elaborate
average kota person 
@loud junco like this one https://github.com/BobuxBot/BobuxAdmin/blob/master/utils/database.py
im just gonna sleep, havent slept in last 2 days
so if i were to use !addshift @(user) and then used !viewlogs @(user) it would of added 1 shift to the specified user
π oh well
have a good sleep 
thanks
you would need a local cache or database for that, preferably a dictionary
i think someone told you about this earlier a few hrs ago?
yeah but like i was super confused and also tired, i didn't understand and i lost the message
!e ```py
shifts = {}
def _shifts(user_id):
print(shifts.get(user_id))
def add_shift(user_id):
shifts.setdefault(user_id, 0)
shifts[user_id]+=1
_shifts(580034015759826944) # with no shifts
add_shift(580034015759826944) # adding a shift
_shifts(580034015759826944) shift was added
π€ wtf
oh
weird, gimme a moment
what r the ids at the bottom
a random user id
oof
its just my id, you'll have to use ctx.author.id in your code
ok
you can see the output in #bot-commands
as i call the add_shift with a user id, the count of shifts get increased
the implementation will be pretty much same for your code
but all this data will get lost when you restart the bot
bot = commands.Bot(command_prefix = prefixxx, case_insensitive=True, activity=discord.Game(name="rpm start"),intents=intents)
can i just copy paste this on top of the file to end my misery
no
you can't
how do i define bot ;-;
you dont need to do all this messy stuff at all
then how do i define it
change the implementation, give me a minute
is bot.db your connection object?
When the
!pypi exenenv
I like this so much
# database.py
class Database:
def __init__(self, bot):
self.bot
async def do_something(self, arg):
return await self.bot.db.fetch(".....")
``` ```py
# bot.py
from database import Database
bot = commands.Bot(...)
@bot.event
async def setup_hook():
bot.db = await asyncpg.create_pool(...)
bot.database_handler = Database(bot)
cause I made it
and then you can use bot.database_handler.do_something anywhere you want to
@slate swan do i necessarily have to have the part at the bottom?
bot.py π
no
ok
your commands will work as those parts
ok
whatever you call it lol
so what would i add to the value in the top embed?
my __.py is just 3 lines πΆββοΈmain__
is it main.py
i mean like when do i do the thing in bot.py
wherever your bot is located
yea
@slate swan
This is an interesting effect fr ____
where are you storing the data of the shift and sessions and stuff
help idk hwo to do that π
the viewlogs command is supposed to show the logs of a member, correct?
yeah


