#discord-bots
1 messages ยท Page 878 of 1
!d discord.TextChannel.last_message_id this gives the channnels most recent message ID, just use a method to get the message object to get the message content if thats what you want ```py
channel = ...
message = channel.get_partial_message(channel.last_message_id) #there are probably easier ways
await message.fetch()
content = message.content
The last message ID of the message sent to this channel. It may not point to an existing or valid message.
no
Ok and then how would i get the one before the most recent
@mellow gulch this
And also channel would be the channel id?
uh no
you need the channel object first
just slap this into your code, pretty simple to understand 
not the samsung emoji

๐ก

CamelCase
PascalCase smh
no CamalCase
Iterate through member.roles and remove the roles using the member.remove_role method. Store the roles somewhere so that you can give the roles back later
PascalCase ๐ฟ
take that badge off, its illegal to impersonate a cop you know that right
!ot 
Off-topic channel: #ot2-never-nesterโs-nightmare
Please read our off-topic etiquette before participating in conversations.
Store all of the users roles in a database, since if something happened and the bot goes offline when the user doesn't have their roles, it would be lost forever. when you run unmute, fetch from the database and give their roles back
await a.add_reaction(u"\u2705") ## yes
await a.add_reaction(u"\u274C") ## no
def check(reaction, user):
return user == member and reaction.message == a and str(reaction.emoji) in ([u"\u2705"], [u"\u274C"])
try:
reaction, user = await bot.wait_for('reaction_add', timeout=30.0, check=check)
except asyncio.TimeoutError:
await a.clear_reactions()
await ctx.send("You didn't respond in time!")
else:
if reaction.emoji == u"\u274C":
embed=discord.Embed(title="UnSuccesful")
embed.set_thumbnail(url=url)
await ctx.send(embed=embed)
if reaction.emoji == u"\u2705":
for members in ctx.guild.members:
if customRole in members.roles:
if members is not None:
memberss.append(members.mention)
await members.remove_roles(customRole, reason=f"Disbanded team by {ctx.author}")
why is the bot not responding to reactions
it would be a many-to-many data relationship so you would need to figure out how to model that data
Give an error
try doing str(reaction.emoji)
alr
i already do that..
I mean in the if statements
None. Try and Expect statements hide most of them.
Ive tried that already aswell. Same Results
send the code that you tried
ok
def check(reaction, user):
return user == member and reaction.message == a and str(reaction.emoji) in ([u"\u2705"], [u"\u274C"])
try:
reaction, user = await bot.wait_for('reaction_add', timeout=30.0, check=check)
except asyncio.TimeoutError:
await a.clear_reactions()
await ctx.send("You didn't respond in time!")
else:
if str(reaction.emoji) == u"\u274C":
embed=discord.Embed(title="UnSuccesful")
embed.set_thumbnail(url=url)
await ctx.send(embed=embed)
if str(reaction.emoji) == u"\u2705":
for members in ctx.guild.members:
if customRole in members.roles:
if members is not None:
memberss.append(members.mention)
await members.remove_roles(customRole, reason=f"Disbanded team by {ctx.author}")
what's the u string for?
That return statement is gonna prevent that try block from even executing no?
Anything after a return statement is blocked
no
Hmm
the return statement is inside anothr function
No. Its inside that function
Variables should be named in snake_case, not camelCase
but would that make a difference (no offense). Since thats what i defined the variable as?
I just prefer seeing my code like that.
ill give it a shot.
Thats not the error though.
The bot is not responding to checks, the code isn't even making it to the if statements. It responds with the timeout error even if I did react.
dude. fucking stop. you keep suggesting shit that has nothing to do. just because one person does something the way you dont like it, dont fucking bring them down for it.
genuinely, unless you have something to actually say towards his question or to help in the slightest, shut the fuck up.
Calm down my guy
To ping mods or to not ping mods
๐คทโโ๏ธ
If you don't like what I'm saying, block me
Quite simple
Also
!rule 7
7. Keep discussions relevant to the channel topic. Each channel's description tells you the topic.
itโs not that, itโs you keep trying to suggest shit thats unrelated to what tjey ask just because of your preference with making variables or classes.
youโre not being helpful to anyone by suggesting those.
It's not my preference
!pep8
PEP 8 is the official style guide for Python. It includes comprehensive guidelines for code formatting, variable naming, and making your code easy to read. Professional Python developers are usually required to follow the guidelines, and will often use code-linters like flake8 to verify that the code they're writing complies with the style guide.
More information:
โข PEP 8 document
โข Our PEP 8 song! :notes:
here we go again
Give this a read
I didn't start it ๐คทโโ๏ธ
Stop getting so hostile please
Ok, but now let's stop it
Sure
when you are using emojis, instead of unicodes, put a backslash before sending them so you can use them in your code.
๐
\๐
":thumbsup:" wont work
"๐" will work
agree
annoying sometimes
they do?
Not just naming things Willy nilly
I'm aware
I think anyways
!ot ๐ฟ
Off-topic channel: #ot2-never-nesterโs-nightmare
Please read our off-topic etiquette before participating in conversations.
ill give it a shot
Ill give it a shot
alright
Thanks, it worked. Howcome unicode doesn't work?
i dont think discord.py supports unicodes
ah ok
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix = "avery ")
bot.remove_command("help")
@bot.group(invoke_without_command=True)
async def help(ctx):
em = discord.Embed(title = "Avery Commands", description = "Use avery help <command> for extended information on a specific command.")
em.add_field(name= "Fun", value = "8ball, happy, sad, meme")
em.add_field(name="Moderation", value = "kick, ban, mute, unmute, unban, warn, purge")
em.add_field(name="Utilities", value= "None")
em.add_field(name= "Currency", value = "none")
em.set_footer(text='[Google](https://google.com)')
await ctx.send(embed = em)
@help.command()
async def kick(ctx):
em = discord.Embed(title = "Kick", description = "Kicks a member from the guild")
em.add_field(name = "**Syntax**", value= "avery kick <member> [reason]")
await ctx.send(embed = em)
Literally everything I try to make masked links isnt working
This is the outcome:
As you can see I am trying to put the mask link in the footer
iirc only add_fields can embed hyperlinks.
Ok! Also, How do I inline th embed?
I did "inline = True"
This is what it looks like
Id like it to look like Wizohd bots in terms of indent
if you want them all in a row like going up and down,
add inline=false
for wizohd type one just do inline=true iirc
Ok, maybe Ill do some research
why is ui not found
this is how its supposed to look, i dont think there is any other way to fix that
do you want https://pypi.org/project/discord-ui/ ?
I fixed it but does anyone know how to change a bots activity to watching and the amount of guilds it is watching?
!d discord.ext.commands.Bot.guilds
property guilds: List[discord.guild.Guild]```
The guilds that the connected client is a member of.
That didnt really help, Im talking about changing the bots status from "playing (bot.gg)" to watching (amount of servers)
it returns a list of guilds?
I tried it on my bot


len(bot_instance.guilds)
Still confused
well its a literal string it has no value its just text and not the length of the list 
i mean it does have a value since its a truthy string 
but why did you put len(botvar.guilds) as a string ๐
and btw dont change presence in ready as it can trigger many times do it in the constructor
!d discord.ext.commands.Bot
class discord.ext.commands.Bot(command_prefix, help_command=<default-help-command>, description=None, **options)```
Represents a discord bot.
This class is a subclass of [`discord.Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") and as a result anything that you can do with a [`discord.Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client") you can do with this bot.
This class also subclasses [`GroupMixin`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.GroupMixin "discord.ext.commands.GroupMixin") to provide the functionality to manage commands.
whats the constructor?
the class construction
how would i do that
class A:
def __init__(self, arg: str) -> None:
pass
A("argument")
the class constructor is how the class is constructed
B = A()
here B is a class instance of A
not sure why i gaved a example on an instance of a class but whatever
yes, but how would i define the presence in the construction
ah sorry the class has kwargs for them
the kwargs fall in to **options as their amount is unknown
Hi i have a question for a profiling system embed. if the user is verified. How do you make the bot know that that user is verified? if that make sense
ill show a ss if u dont understand
This is what i mean
How exactly are you storing the age and gender and, well, everything else? Because it would be the same thing for these two fields
Well i would be storing that in a JSON files for different files like have one file for gender.json, age.json etc
^
well just store it somewhere, how you do it, its up to you ig
Well i dont know how would i do it in json file
do not use json files as dbs
because they arent meant to be used as one
Why shouldnโt I use a JSON file as a database?
โข Performance is deterministic on Data size:
โ As Data increases, reading/writing takes longer
โข No concurrent writing (One write at a time):
โ Effects performance, and can cause corruptions
โข Human readable/Easily accessible by users:
โ This can leave your text vulnerable for attacks
โ If you can read the text, it's not encrypted
What should I use instead?
โข SQL Databases:
SQLite, PostgreSQL, MariaDB, etc...
โข NoSQL Databases:
MongoDB, RethinkDB, ArangoDB, etc...
For similarity, and easier porting, NoSQL is advised.
What can I use a JSON file for?
Storing Static Data (Not changed often), such as:
Configurations, Properties, or User-Defined Data
Tldr; fine now, bad later
Or i can store it in cogs
You would lose the data after every restart
thanks
I was too lazy to write the first topic
how do you plan on storing data in cogs 
Idk

how to check is a user has a role in different server
you can use https://www.deta.sh/ though
what do you mean?
just get the guild and then the member using their id
then use the roles property
if it meets the conditions
@commands.has_any_role("gold patreon") ๐ฟ edit?
....dont really know what you are trying to achieve here, but, are you saying that the command is invoked in one server and the bot checks if the person who invoked the command in one server has a specific role or roles in another server, is it?
yeah
yeah, so first get the guild, then get the member using the Guild object, then use the roles property on the Member object
!d discord.ext.commands.Bot.get_guild
get_guild(id, /)```
Returns a guild with the given ID.
!d discord.Guild.get_member
get_member(user_id, /)```
Returns a member with the given ID.
!d discord.Member.roles
property roles: List[Role]```
A [`list`](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.9)") of [`Role`](https://discordpy.readthedocs.io/en/master/api.html#discord.Role "discord.Role") that the member belongs to. Note that the first element of this list is always the default [โ@everyone](mailto:'%40everyone)โ role.
These roles are sorted by their position in the role hierarchy.
๐ฟwow, ok ty
Np
who
@bot.command()
async def premium(ctx):
s = bot.get_guild(917956425681100801)
u = bot.get_membed(ctx.author.id)``` after this what should i do ๐ฟ
first get the member not the membed
๐ฟ ok
fk typo
then, check if u is not None and use the roles property on the u var representing a Member object
use the roles property on the u var representing a Member object
just u.roles??
yes
it will return a list of Role objects
and what to do with the get guild thing
wait waht :v
is
s = bot.get_guild(917956425681100801)
u = s.get_member(ctx.author.id)
if u != None:
print(u.roles)```
yes, nice
ok ty :)
and use if u: 
oh ok ๐ฟ
um what
use arithmetical operators only for numbers or strings
if u what
it will check if u is not None
if u: awkward, simple
lmao
just if u:??
yes 
holy cow, ok
@bot.command()
async def premium(ctx):
s = bot.get_guild(917956425681100801)
u = s.get_member(ctx.author.id)
if u:
if "gold patreon" in u.roles:
await ctx.send("GGTY!")
else:
await ctx.send(":moyai: u r not a patreon, be one of them to access this command!")``` not send any message
u.roles returns a list of Role objects, at least try printing that, do something on your own 
u.roles returns a list of Role objects, at least try printing that,
no output ๐ฟ
oh god
the member doesnt have any roles then
if the list is empty
i am the member
and no [] output
did you print(u.roles)?
@bot.command()
async def premium(ctx):
s = bot.get_guild(917956425681100801)
u = s.get_member(ctx.author.id)
if u:
print(u.roles)```
yes
see the output then
breh (those 2 not the u.roles output, just indicates that the bot running)
wdym
still no output for the u.roles print
error?
no, no error
do you have any error handler?
no for the premium comand
Check your intents
yeah
which one
They are on your botโs app page in the dev portal
member intents
in where
hey guys... I am trying to create a admin bot. I have a list of words that should not be spoken in channel(slangs) as a table in mysql. How do I traverse the table and see if anyone used that slang?
bot section
They are on your botโs app page in the dev portal
k
wait
bot = commands.Bot(command_prefix=["sal!", "Sal!", "SAL!", "saL!", "s!", "S!"], help_command=None, case_insensitive=True, strip_after_prefix = True)``` this ig?
U need intents too
:v how
!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.
oh, ok
disnake support?
Same
sans discord
lel ye
then how
?
how to do that, i mean that's return an error, what's the real thing to do
u is member right
ye
What error
lol
U want 1 role only right
when i read "any" documentation, ig the "any" func is to check whether a thing in a list is True :V
U missed : somewhere
Show ur full command
So i can see what is u and access
jesus christ, litteraly 2k lines of codes, also i not missed any ":", i just need the real thing to check if the user have any roles in "access"
Just tell what is u and access
if just that then
@bot.command()
async def premium(ctx):
s = bot.get_guild(917956425681100801)
u = s.get_member(ctx.author.id)
access=["gold patreon", ""]
if u:
if any u.roles in access:
await ctx.send("GGTY!")
else:
await ctx.send(":moyai: u r not a patreon, be one of them to access this command!")```
Ok
U can do ctx.author.roles only?
ig nope, since the code is to check whether a user hav specified role in another server :V
Ok
k
Ok got it
ok :v
๐ฟ what host
any idea?
i am searching for new but currently i am in heroku
No.
ok :vvvvvvvvvvvvvvv
Weird
just use pycharm and make ur pc not ded
lol
Huh?
wot ?
make ur pc not ded
i want cheap host with free database
I got this error after creating a command in discord.py
Traceback (most recent call last):
File "/home/runner/NeulBot/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 222, in add
if amount>bal[1]:
IndexError: list index out of range
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/runner/NeulBot/venv/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/home/runner/NeulBot/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/home/runner/NeulBot/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: IndexError: list index out of range```
This is the code of the command
```py
@client.command()
async def add(ctx,member:discord.Member,amount=None):
await open_account(ctx.author)
await open_account(member)
if amount==None:
await ctx.send("Enter the amount in digits!")
return
bal = await update_bank(ctx.author)
amount = int(amount)
if amount>bal[1]:
await ctx.send("Not Enough Money!")
return
if amount<0:
await ctx.send("Amount isn't Positive!")
return
await update_bank(ctx.author, -1*amount,"wallet")
await update_bank(member,amount,"wallet")
await ctx.send(f"{amount} has been added to the users balance")```
can anyone help
ur pc free, sqlite also free
what
Huh?
i am serious here if u don't have idea no need to do stupid talks
and is bal a list ๐ฟ
s q l i t e i s f r e e
i mean host in ur own pc is free :V
heroku can connect with that ?
no
why heroku when u can use pc :v
Who want to increase there bill
๐ฟ then just bal, not bal[1]
i cannot keep my pc 24/7
ok
don't use JSON
also the data get lost when i stop the program
I do
then dont :V
what thing u even use as database
?
If u cant help pls dont try to help
what thing u use as a database
why
Traceback (most recent call last):
File "/home/runner/NeulBot/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 222, in add
if amount>bal:
TypeError: '>' not supported between instances of 'int' and 'list'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/runner/NeulBot/venv/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/home/runner/NeulBot/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/home/runner/NeulBot/venv/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: '>' not supported between instances of 'int' and 'list'```
then dont use pc if ur pc cant 24/7
i got this
Claim a help channel

what is "bal"?
u just said that bal not list ๐ฟ
bru what
PC IS NOT USED AS DATABASE
what??? i said sqlite
PC IS NOT USED AS A HOST EITHER
relax, crikey
me use pc as host lemao
Ur problem
if any u.roles in access: me still need dis
lul ok, have a gud day
if any(role for role in u.roles in acess)
Yes i think
:praise_the_sun:
if any(role for role in u.roles in access):
TypeError: 'bool' object is not iterable
there are 2 ins?
idk :V
Use for loooop
that's a loop? (for role in u.roles in access)
๐ฟ
whats u.roles ?
for roles in u.role:
if roles in access:
f stuff
roles
and whats access?
list
.
Yes
im not sure where the bool is coming from
full code
@bot.command()
async def premium(ctx):
s = bot.get_guild(917956425681100801)
u = s.get_member(ctx.author.id)
access=["gold patreon", "iron patreon"]
if u:
if any(role for role in u.roles in access):
await ctx.send("GGTY!")
else:
await ctx.send(":moyai: u r not a patreon, be one of them to access this command!")
if this, how to implement :V
Try printing roles
u.roles?
whoops
[<Role id=917956425681100801 name='everyone'>, <Role id=947402526410539020 name='gold patreon'>, <Role id=928503038371561542 name='playah'>, <Role id=924915779835691008 name='gods'>]
hbqankwdasd ok
@bot.command()
async def premium(ctx):
s = bot.get_guild(917956425681100801)
u = s.get_member(ctx.author.id)
access=["gold patreon", "iron patreon"]
if u:
if any(role for role in u.roles.name in access):
await ctx.send("GGTY!")
else:
await ctx.send("๐ฟ u r not a patreon, be one of them to access this command!")โ
It willvwork
"it will work"
disnake.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'list' object has no attribute 'name'
@bot.command()
async def premium(ctx):
s = bot.get_guild(917956425681100801)
u = s.get_member(ctx.author.id)
access=["gold patreon", "iron patreon"]
if u:
if any(role for role in u.roles.name in access):
await ctx.send("GGTY!")
else:
await ctx.send(":moyai: u r not a patreon, be one of them to access this command!")``` ๐ i hate error
imagine
Im noob i know
dont
imagine a bot
~JS
role_name_list = [role.name for role in u.roles] #returns a list with role names of the member
if 'rolename' in role_name_list:
#do stuff
else:
return 'uwu'
Huh
yes
using a list comp is generally easier
than writing lambda functions ||dont resist if you wanna look cool||
will this work :V
@bot.command()
async def premium(ctx):
s = bot.get_guild(917956425681100801)
u = s.get_member(ctx.author.id)
access=["gold patreon", "iron patreon"]
if u:
role_name_list = [role.name for role in u.roles]
if any(role for role in role_name_list in access):
await ctx.send("GGTY!")
else:
await ctx.send(":moyai: u r not a patreon, be one of them to access this command!")```
yeah it should
try, why asking before trying 
:praise_the_sun:
TypeError: 'bool' object is not iterable
in this the run bot command is below its just showing syntax error in 18th line
nvm
dont use the any function
use normal conditionals
njdalsdkajsdknasdksaasd what
pls help
I know lmao
hover over it, it sometimes shows the error
hover over it means ?
hi @maiden fable
You answered fast ๐
nvm 
Hi
where
Huni gonna help 
you help pls
ask Hunter, I'm done
in there anything error in my code ?
Sure, ig
I got work and school yknow
helo @maiden fable
I don't really have much time rn, tell me the issue
Understandable
my bot is not showing the embed msg when a person joins the server
Intents?
U need members intent
and also, u r a panda :))
It also has an intents kwarg
can you tell how ? or some help ig
I know?
TypeError: 'bool' object is not iterable
@bot.command()
async def premium(ctx):
s = bot.get_guild(917956425681100801)
u = s.get_member(ctx.author.id)
access=["gold patreon", "iron patreon"]
if u:
role_name_list = [role.name for role in u.roles]
if any(role for role in role_name_list in access):
await ctx.send("GGTY!")
else:
await ctx.send(":moyai: u r not a patreon, be one of them to access this command!")```
!intentd
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.
Ah okay, mb
Are you coding on your phone?
ohhk
nope xd
if any(role for role in role_name_list if role in access)
Why is it so cropped then
The any function is wrong lol
is that possible???
Pydroid exists
i cropped it intentionally
I did tell but well, who doesnt ignore me anyways 
i mean he is using e website so yeah.
wow ok
Me (:
@small igloo yr issue fixed?

๐ถ 
nope, pycharm slow i mean not tested yet
Lol
Okay
yea an e website bcz i coded on atom first of all but eventally i cannot host it for free so now i am coding in replit
Replit 
how can i set slash command visible in specific channel pycord
it's work! ggty
Idk, never used pycord
da fudge, replit
Cool
^_^
sed
u 2, thanks ||and @slate swan 2||
@bot.command()
async def premium(ctx):
if u := ctx.guild.get_member(ctx.author.id):
if any([role for role in ctx.guild.roles if role.name in ["gold patreon", "iron patreon"]]):
await ctx.send("GGTY!")
else:
await ctx.send(":moyai: u r not a patreon, be one of them to access this command!")
I'm just lazy rn, so just told the issue in their code
You can't have per channel commands visable but you can disable a command to only work in that channel.
how?
Im mid pythoner
Could also oneline it
Stop.
Just check the channel id.
ok tysm
if ctx.channel.id == 2939989392939:
No
Wait not str
IDs are int lol
Not from pc u know
Hi, can I make it to that if a message has anything *other than a channel mention in it, it still waits for a channel?
Just set the channel arg to None and check if it's None. If it is, use bot.wait_for
def channelCheck(message: disnake.Message):
return (len(message.channel_mentions) > 0) and (message.author == inter.author)
welcomeChannel = await self.bot.wait_for("message", timeout=30.0, check=channelCheck)
await inter.channel.send(embed = announcementsConfig)
```
Uh
Where would I set that?

@bot.command()
async def premium(ctx):
await ctx.send("GGTY!") if any([role for role in (ctx.guild.get_member(ctx.author.id)).roles if role.name in ["gold patreon", "iron patreon"]]) else await ctx.send(":moyai: u r not a patreon, be one of them to access this command!")
``` kek
sorry if it sounds dumb I legit just woke up
def cmd(..., channel:TextChannel = None):
if not channel:
channel = await bot.wait_for(...)
# use channel converter to convert the channel to a TextChannel instance
...
What
You do know I am already tired and I don't want to kill my brain cells, right? 
They are not going to be pleased if i do a simple if comprehension in asoteric lol
you can use channel without mention it or with id and name
in cmd
!d discord.ext.commands.TextChannelConverter @modest plover
class discord.ext.commands.TextChannelConverter(*args, **kwargs)```
Converts to a [`TextChannel`](https://discordpy.readthedocs.io/en/master/api.html#discord.TextChannel "discord.TextChannel").
All lookups are via the local guild. If in a DM context, then the lookup is done by the global cache.
The lookup strategy is as follows (in order)...
Ok,.
They are meant to be type hinted
You can also just use the text channel object.
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.
data = message.content.split(" ")
user = re.sub("\D","",data[1])
s = bot.get_guild(917956425681100801)
u = s.get_member(user)
access=["gold patreon"]
if u:
role_name_list = [role.name for role in u.roles]
if any(role for role in role_name_list if role in access):
database.give_vote_premium(user)
else:
database.remove_vote_premium(user)``` why not give vote premium ๐ฟ and user output is 828182019841327115 (id)
AttributeError: 'Client' object has no attribute 'fetch_message'
also like before, me alr hav the role
b o t
you fetch from channel
U need an instance of TextChannel
!d discord.TextChannel.fetch_message
await fetch_message(id, /)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Retrieves a single [`Message`](https://discordpy.readthedocs.io/en/master/api.html#discord.Message "discord.Message") from the destination.
channel = client.get_channel(channel id)
message = await channel.fetch_message(message id)
help?
let me try brother
!d any
any(iterable)```
Return `True` if any element of the *iterable* is true. If the iterable is empty, return `False`. Equivalent to:
```py
def any(iterable):
for element in iterable:
if element:
return True
return False
yes?
You are using the any statement wrong. You need an iterable.
am i do the get member wrong
just do
from discord.ext import commands
intents = discord.Intents.default()
intents.member = True
Like this @maiden fable ?
At that point you can also just do ```py
from discord import Intents
intents = Intents.all()
what is iterable ๐
ok so i have to write this code in just starting ??
!d iter
iter(object[, sentinel])```
Return an [iterator](https://docs.python.org/3/glossary.html#term-iterator) object. The first argument is interpreted very differently depending on the presence of the second argument. Without a second argument, *object* must be a collection object which supports the [iterable](https://docs.python.org/3/glossary.html#term-iterable) protocol (the `__iter__()` method), or it must support the sequence protocol (the `__getitem__()` method with integer arguments starting at `0`). If it does not support either of those protocols, [`TypeError`](https://docs.python.org/3/library/exceptions.html#TypeError "TypeError") is raised. If the second argument, *sentinel*, is given, then *object* must be a callable object. The iterator created in this case will call *object* with no arguments for each call to its [`__next__()`](https://docs.python.org/3/library/stdtypes.html#iterator.__next__ "iterator.__next__") method; if the value returned is equal to *sentinel*, [`StopIteration`](https://docs.python.org/3/library/exceptions.html#StopIteration "StopIteration") will be raised, otherwise the value will be returned.
after import statement ?
You need to pass that as a kwarg yeah
in my code where to add
like this @cloud dawn
What does "iter" mean?
Return an iterator object.
Yeah and now pass that kwarg into your Client object.
No that is the function, what would an iter be?
wdym by kwarg ?
why not make the welcome_channel a global variable so you don't have to keep fetching
!arg-kwarg
*args and **kwargs
These special parameters allow functions to take arbitrary amounts of positional and keyword arguments. The names args and kwargs are purely convention, and could be named any other valid variable name. The special functionality comes from the single and double asterisks (*). If both are used in a function signature, *args must appear before **kwargs.
Single asterisk
*args will ingest an arbitrary amount of positional arguments, and store it in a tuple. If there are parameters after *args in the parameter list with no default value, they will become required keyword arguments by default.
Double asterisk
**kwargs will ingest an arbitrary amount of keyword arguments, and store it in a dictionary. There can be no additional parameters after **kwargs in the parameter list.
Use cases
โข Decorators (see !tags decorators)
โข Inheritance (overriding methods)
โข Future proofing (in the case of the first two bullet points, if the parameters change, your code won't break)
โข Flexibility (writing functions that behave like dict() or print())
See !tags positional-keyword for information about positional and keyword arguments
!d discord.Client
class discord.Client(*, loop=None, **options)```
Represents a client connection that connects to Discord. This class is used to interact with the Discord WebSocket and API.
A number of options can be passed to the [`Client`](https://discordpy.readthedocs.io/en/master/api.html#discord.Client "discord.Client").
loop is a kwarg aswell as **options
repetition ig :v the repetition of a process or utterance
options representing most of the time a collection of other kwargs
'NoneType' object has no attribute 'fetch_message'
so i have to do like
client = discord.Client(**Intents)
repetition, so what could that be if we want to check an iterable with an any object?
loop or what u mean :v
hasn't fetched the channel for some reason
happens to me when i try to fetch stuff before the client is ready
client = discord.Client(intents=intents)
``` intents is the kwarg name, now we pass the intents variable to that kwarg.
ooooh understood
Yeah and what can we loop over in python.
bro, I'm just trying to update the message in dms
string, list, tuple, dict, set :V?
list, string, tuple, set can be iterables. You are making a for loop comprehension without using a list.
wait what :V
but u.roles itself is a list?
s = bot.get_guild(917956425681100801)
u = s.get_member(user)
access=["gold patreon"]
if u:
print(u.roles)```
it worked Tysm
if user := re.sub("\D", "", message.content.split(" ")[1]):
if any(role for role in message.author.roles if role.name == "gold patreon"):
database.give_vote_premium(user)
else:
database.remove_vote_premium(user)
if role.name == "gold patreon") what if list
if role.name in ["gold patreon"]
also @cloud dawn how do i mention a person
(member.mention)
like this ?
message.author.roles me check role in different server :V
yes
๐
if user := re.sub("\D", "", message.content.split(" ")[1]): this....
data = message.content.split(" ")
user = re.sub("\D","",data[1])``` and that same or no :V (i mean how it works is same or no)
Yes that is the same
hi tvrsier
ok :v
message.author returns the member object of the guild where the message is sent, if it is in pm it returns an user object which doesn't have any guild permissions
Thus slash commands
||completely unrelated but|| how to say ur name :v
slash commands doesn't have a message object by their own, they have an ApplicationInteraction
:V
data = message.content.split(" ")
user = re.sub("\D","",data[1])
if any(role for role in message.author.roles if role.name in [access]):
database.give_vote_premium(user)
else:
database.remove_vote_premium(user)``` will work?
@cloud dawn syntax error ?
closing parentheses done?
yes
ok
then what error ?
maybe try it?
it isn't mentioning the member
syntax error
that only i am asking what syntax error after closing parantheses ?
jesus christ, not "("")" but "{""}"
{member.mention} not (member.mention)
he said that
if any(role.name in [access] for role in message.author.roles)
Tarsier
sorry
s = bot.get_guild(917956425681100801)
u = s.get_member(user)
access=["gold patreon"]
if any(role for role in u.roles if role.name in [access]):
database.give_vote_premium(user)
else:
database.remove_vote_premium(user)```?
should do
black tarsier?
but why the [] before access?
yes
why is it mentioning like this @small igloo
bcuz........
idk :V
kek i forgor
:/
anyone else knows?
you can even do this:
access = "gold patreon"
if any(role.name == access for role in u.roles):
#stuff
my solution just mention.name
ohh wait a sec
s = bot.get_guild(917956425681100801)
u = s.get_member(user)
access=["gold patreon"]
if any(role.name == access for role in u.roles):
database.give_vote_premium(user)
else:
database.remove_vote_premium(user)
if any(role.name == access for role in u.roles):
AttributeError: 'NoneType' object has no attribute 'roles'
btw if I can suggest you a thing try to allways use the ID of the object to compare them, because if you compare the name and you will change the name of the role your code will not work, if you compare the ID you can change whatever you want, the ID still is the same
u is not a member object
not working :(
yes? :V
Well your bot is sayin that it is a None object ๐
:v then how to fix
error mesage?
!d disnake.Guild.fetch_member
await fetch_member(member_id, /)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Retrieves a [`Member`](https://docs.disnake.dev/en/latest/api.html#disnake.Member "disnake.Member") with the given ID.
Note
This method is an API call. If you have [`Intents.members`](https://docs.disnake.dev/en/latest/api.html#disnake.Intents.members "disnake.Intents.members") and member cache enabled, consider [`get_member()`](https://docs.disnake.dev/en/latest/api.html#disnake.Guild.get_member "disnake.Guild.get_member") instead.
with this
help
@bot.command(aliases=["HELP","Help"])
async def help(ctx):
await ctx.send("De Help Command.",embed = hembed, components=[Button(label="Page 2", custom_id="button1", style = ButtonStyle.blue)])
interaction = await bot.wait_for("button_click", check=lambda inter: inter.custom_id == "button1")
await interaction.respond(type=7,content="De Help Command.",embed=hembed2, components=[Button(label="Page 3",
custom_id="button2", style = ButtonStyle.blue)])
interaction2 = await bot.wait_for("button_click", check=lambda inter: inter.custom_id == "button2")
await interaction2.respond(type=7,content="De Help Command.",embed=hembed3, components=[Button(label="Page 4",
custom_id="button3", style = ButtonStyle.blue)])
interaction3 = await bot.wait_for("button_click", check=lambda inter: inter.custom_id == "button3")
await interaction3.respond(type=7, content="De Help Command.", embed=hembed4, components=[])
how to make this a loop?
umm, about that get_guild?
oh, nvm that
!d discord.ext.tasks.loop
discord.ext.tasks.loop(*, seconds=..., minutes=..., hours=..., time=..., count=None, reconnect=True, loop=...)```
A decorator that schedules a task in the background for you with optional reconnect logic. The decorator returns a [`Loop`](https://discordpy.readthedocs.io/en/master/ext/tasks/index.html#discord.ext.tasks.Loop "discord.ext.tasks.Loop").
then define it :V
async def idk_ur_comand_name(ctx, mention:discord.Member=None):
#blah
?
ohk
lemme try
the option isnt being added to my slash cmd, its been over 12 hrs ๐ฉ
i dont understand?
Is for loops
ls for loops?
am i doin it right
s = bot.get_guild(917956425681100801)
u = await s.fetch_member(user)
access=["gold patreon"]
if any(role.name == access for role in u.roles):
database.give_vote_premium(user)
else:
database.remove_vote_premium(user)
``` if yes, why still not give me premium vote ;-;
read the docs D_D
which?
well check your give_vote_premium method
this is a link
ok
def give_vote_premium(user):
user = str(user)
cur.execute("UPDATE users_data set VOTE_PREMIUM = 1 where NAME = ?", (user,))
conn.commit()```
this doesn't give a role, it just add it to the database
ik, not add role, but it set the vote_premium value in database, BUT DOESNT SET AT ALL ME ANGERRR
Which database are you using?
sqlite
You have a db browser open?
s = bot.get_guild(917956425681100801)
u = await s.fetch_member(user)
access=["gold patreon"]
if any(role.name == access for role in u.roles):
print("yess")
else:
print("no ;-;")```why output-
sqlite viewer?
yes
yes
You have to close it, do the command again and then check
still same but less RAM eaten, ty
?
well, stil not work but at least now an application ded :v
um no?
It was working fine yesterday
Nothing will be true because you are comparing a string to a list
_blame @placid skiff _
send code ๐ฟ
Why aren't you using aiosqlite
Nothing wrong but sure
You using repl.it
Yes
b r u h
Well there lies your issue.
nope, check better. He is comparing if any of the role.name is equals to the string access where role idents through the user roles list
What's wrong?
uhm
da hec
You are probably rate limited since you are on a shared network.
How do I check?
You will get errors, overall repl.it is pretty slow service anyways
!e
string = "abcd"
list_of_string = ["abcd", "abc", "bc", "cd"]
print(True if any(data == string for data in list_of_string) else False)
@placid skiff :white_check_mark: Your eval job has completed with return code 0.
True
r = requests.head(url="https://discord.com/api/v1")
try:
print(f"Rate limit {int(r.headers['Retry-After']) / 60} minutes left")
except:
print("done")```
No errors
@cloud dawn
Where do I add this?
I know, but this is Python D_D
Where do I add this?
end of ur code, before bot.run()
ok
btw in c you can do an any function which does that lol
any returns a boolean
#esoteric-python and have a stroke there, no problem
Yeah, so?
No i like this it's just as cursed, True if True else False
Do I need to import anything?
yes, import request
s
s
result's still the same ๐
but simpler ๐
What even is the issue?
he says not work
My BOT just stopped working
quit replit
It barely even gets any use
We're gonna need more info than that..
What would you like to know?
My BOT is a quotes bot for a private server
I used it a few days ago
it was all good
๐ฟ is the token right
hi :v
I just regenerated the token
BOT went offline and went i put the token in the code
it went back online but the commands don't work
||why u always capitalyze the "bot", kinda annoying tbh|| unrelated warning!!!!
IDK
code again :v but dont paste the link..... fkgys.com :v
Ummm
i bet u still trying
? i'm workin so i'm not totally focussed on the conversation
๐ฟ ok
where to write this command
inline with async def ?
s = bot.get_guild(917956425681100801)
u = await s.fetch_member(user)
access=["gold patreon"]
if any(role.name == access for role in u.roles):
print("yess")
else:
print("no ;-;")``` again
what this print??
stil "no"
๐ฟ what
print u.roles
get is cache
!e
data1 = ["test"]
data2 = "test"
print(data2 in data1)
@placid skiff :white_check_mark: Your eval job has completed with return code 0.
True
Yeah but you are awaiting a cached object
Wait he is right why you are keeping doin access = []? just do access = ""
holy jesus christ finnaly work, GGTY
Better py bool(1).__bool__() if ~None.__bool__() else bool(int()).__bool__()
Whats ~ mean?
bitwise not
What?
invalid syntax ??
what is that 
Wth
more than invalid
~ is the bitwise not operator
cursed
i want to define member where do i do it
How much do you know python?
Probably started immediately with dpy
its mentioning like this
whats that? 
you cant mention in embed titles or name in add_field
wat ?!?!?!?
you can use description since title is optional and can be skipped
ohk
so i can mention in description not in title
am i right @slate swan
UPDATE inventory SET m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, r0, r1, r2, r3, r4, r5, r6, r7, r8, s0val25, s0val50, s0val100, s1val2, s1val4, s1val6, s2val1, s2val2, s2val3, s3val1, s3val2, s3val3 WHERE id = ?```

UPDATE table SET column_1 = new_value_1, column_2 = new_value_2, ..., column_n = new_value_n WHERE search_condition
oh am i just missing a placeholder
so UPDATE inventory SET m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, r0, r1, r2, r3, r4, r5, r6, r7, r8, s0val25, s0val50, s0val100, s1val2, s1val4, s1val6, s2val1, s2val2, s2val3, s3val1, s3val2, s3val3 = ? WHERE id = ?
yup, you're telling to update column but without giving the value
you have to set the value for all the columns xD
pretty useless if so xD
is it right way to use line break ?
it's an periodic save for all the values
comma then line break if that's what youre asking
yes as its not breaking the line
oh i misunderstood the question
the output is coming in continuation
i hv decided i will learn python through discord.py
i have learnt python till functions not more than it
and also the bot i am making doesnt require many new python commands ,
the bot is made using simple commands
but sometimes i get stuck in some silly commands bcz i havent learnt them yet (and i am kinda busy too)
and
when i ask people questions or errors they always ans and help me happily
so i think i will learn it this way eventually will be a good in python
you get stuck because you don't know how typehints works, how OOP works, how decorators works, how async/await function works. Knowing all this of course is not required, but not knowing will get you stuck a lot of times in developing in d.py
ok so i quit dpy
it's not quitting
i will make simple projects and be happy with that
bro everyone started with discord.py from 0, and it is a really mess when you start. But with a base knowledge you can understand more and find help all by your own just by reading discord.py documentation
Can anyone tell me a good website for hosting discord bots except heroku and replit 
well you need a VPS not a website lol. Or a discord bot hosting service, there are plenty, search one for your geo location
yes thats a good idea
ik there are plenty but which one to trust 
as in replit u can hide the token and in heroku u can set if u want your code public or not
what about other sites?
all except heroku and replit can be trusted xD
an hosting is a private space that you buy in a server

no one can read your code except user authorized by you
ya but bot token is public
bruh in hosting you don't paste your code, you export your project in the hosting
i am new a newbie
but in replit u do 
because replit is ||shit||
which makes me remember discord sent me a dm because I mistakenly pushed my bot token to github
Ok 
rip

once happened to me too, but not because my token was in the source code
but because when you create a local repository it creates folder with enviroment variable showed in an xml file
lol
@slate swan did your issue get fixed though?
@slash_command(guild_ids = [849629843745800204])
async def mrps(self, ctx, member: Option(discord.Member, "Whom do you wanna play with", required=True)):
global p1
global p2
p1 = ctx.author
p2 = member
global plist
plist = [p1, p2]
view = MyView()
if member == None:
await ctx.send(f"Invalid syntax\n\n{prefix}mrps <member>\n Mention the member next time")
elif member == ctx.author:
await ctx.send("Bruh, how can you play with yourself?")
elif member == self.bot.user:
await ctx.send(f"Do `!rps` if you wanna play with me")
elif member.bot:
await ctx.send("Imagine trying to play games with a bot")
else:
await ctx.respond(f"{member.mention}")
reply = f"{p1.name} is choosing...\n{p2.name} is choosing..."
global msg
msg = await ctx.respond(reply, view=view)```
option doesn't show up
orait, cool
;-;
Maybe is because of typehints, you are giving discord.Member as first parameter which is a type, but the first parameter is the name of the option
def add_item(name, amount, item):
ae = item.upper()
list = ae.split(" ")
if len(list) > 1:
item = list[0]+"_"+list[1]
else:
item="".join(list)
cur.execute("UPDATE item_list set ? = ?+? where NAME=?", (item, item, amount, name))
conn.commit()``` disnake.ext.commands.errors.CommandInvokeError: Command raised an exception: OperationalError: near "?": syntax error :V why
don't think that you can do operations in query with sqlite
waht :v
that's my past question, is there any way to use it efficiently instead use if elif
first of all, dont use list as variable because list is list class, after that you can do this:
item = lst[0]+"_"+lst[1] if len(lst)>1 else "".join(lst)
done
!e
lst = ["abc", "ab", "ac", "bc"]
item = lst[0]+"_"+lst[1] if len(lst)>1 else "".join(lst)
print(item)
@placid skiff :white_check_mark: Your eval job has completed with return code 0.
abc_ab
gg
def add_item(name, amount, item):
ae = item.upper()
lst = ae.split(" ")
item = lst[0]+"_"+lst[1] if len(lst)>1 else "".join(lst)
cur.execute("UPDATE item_list set ? = ?+? where NAME=?", (item, item, amount, name))
conn.commit()``` right
๐ฟ so the most efficient way just fking do elif?
? this is not the problem of your query
well, if i dont use that, my last choice is elif, nah, i dont want use that again, is there any way i can do it more efficiently
I don't follow you, what are you talkin' about?
wait
are you still stuck on the same thing?
my fking full of elif code: https://paste.pythondiscord.com/joruxuvama
y e s, and now i wanna add item ๐ฟ
BRUH WHAT THE HELL IS THAT HAHAHHAA
uhm i use pycord
uh thought it was disnake, then i dunno, sorry
holy-
๐ฉ
disnake better ๐ฟ
uhm honestly i dunno if there is a way to make it easier, i can study a way but not sure
but not sure
i'll edit
๐ฟ
you can try this:
cur.execute("UPDATE item_list set ? = ? - ? WHERE NAME = ?", (item.upper(), item.upper(), amount, name)
Can't ensure that will work, but you can try
๐ฟ whats the different
Isn't upper a string method
item == "carrot" it is a string till someone prove otherwise
oh wait, there are some underscore
that makes things more complicate
:v
replace ig
elif item == "woter":
cur.execute("UPDATE item_list set WOTER_BOTTLE = WOTER_BOTTLE - ? where NAME = ?", (amount, name))
``` inconsistency is killing me
woter ๐ฅธ
item = item.upper().replace(" ", "_") if " " in item else item.upper()
cur.execute("UPDATE item_list set ? = ? - ? WHERE NAME = ?"), (item, item, amount, name)
well this will not rid off all if-elif from the code
idk why he would make a column for each item, at that point just make a list with int's or dict per user.
that schema doesn't look right, you shouldn't be using placeholders for the columns
yeah and some columns are named differently from the variables tho, @small igloo to rewrite that block of code you have to entirely change that structure in you database
Or just use an int list for inventory since no one likes a lot of work.
waht :V
he is saving them that means he needs them even when he reloads the bot
yes :D
n o
am i doin it right
def add_item(name, amount, item):
ae = item.upper()
lst = ae.split(" ")
item = item.upper().replace(" ", "_") if " " in item else item.upper()
cur.execute("UPDATE item_list set ? = ? - ? WHERE NAME = ?"), (item, item, amount, name)
conn.commit()```
will not work
nuu
!e ```py
item_data = {
"woter": 0,
"cheese": 1,
"ham": 2,
"beef": 3,
"banana": 4
}
user_inventory = [10, 22, 32, 9, 10]
print(user_inventory[item_data["cheese"]])
@cloud dawn :white_check_mark: Your eval job has completed with return code 0.
22
yeah he will have the problem on the database tho cuz sqlite can't save dict
He doesn't need the dict inside the database, only the list of ints
He can keep the dict inside a json and load that on startup and save it in a var.
how to restore the downloaded heroku backup ?
We code Discord bots here.
what if two ints will be the same?
i know but in other channels no one replied
wdym "the same"?
and i am also finding that way for my discord bot
If you have issues with Heroku then this isn't the right server.
user_inventory = [22, 22, 1, 2, 3, 4]
Then you would have 22 woter and 22 cheese
Since it is using indexing to get the data.
hmm heroku don't have their own server and i got many solutions related with heroku in this server
Every "new" user would then have a list like this [0, 0, 0, 0, 0, 0]
yeah and then he can't use anymore ints to find which data he is reference with
What?
firs rule of algorithms: No ambiguity
Give an example why this wouldn't work
You could even create a class and setattr to get even fancier.
Off-topic channel: #ot2-never-nesterโs-nightmare
Please read our off-topic etiquette before participating in conversations.
let's assume that he saves the int value of the dict, then he needs to access one of those data
value = 22
item_data = {"carrot": = 22, "water": = 22, "fish": = 22}
cur.execute("SELECT value FROM item_list WHERE value = ?", (value)
rows = cur.fetchone()
print(item_data.keys()[item_data.values().index(rows)]
#output = carrot
Ambiguity because there are more value with 22
this is the most stupid example, but that's the point
if you need to find the key from the value this method will not work
because is a stupid example as i said hahahaha
https://paste.pythondiscord.com/joruxuvama.py one guy has this block of code in his bot
and he wants to find a way to get rid off all if-elif
I don't think you are understanding.
lol
The list of ints is all he saves in his database
It would have been so fun if dpy allowed us to return custom objects, not just for Context but for other things too
Yes, the problem is when he has more ints with the same value and he needs to find what key that one value is linked to
Well you can it just takes a bit more effort.
monkey patch all the methods to return the custom objects
No since i was using indexing.
I don't wanna monkeypatch dpy :(
:stare: Might as well make my own wrapper
@placid skiff #discord-bots message
Look at this code for a second, then re-evaluate.
you cant ? for column names since the module will add quotes to strings
i gave him the same hint more or less, but there is some problem like this:
elif item == "heal potion":
cur.execute("UPDATE item_list set HEAL_POTION = HEAL_POTION - ? where NAME = ?", (amount, name))```
or this:
elif item == "woter":
cur.execute("UPDATE item_list set WOTER_BOTTLE = WOTER_BOTTLE - ? where NAME = ?", (amount, name))```
๐
yeah, f-strings will be ok here because the column names aren't user input
check item value and then column name
If you gotta use f-strings inside a query you gotta look better at your code
hey, My discord.py bot commands are executing twice, even though I don't have await self.bot.process_commands(message) in the on_message event?
Long time no see rush
๐
we can't give you a diagnosis till we see the code xD
? won't work here because quotes will be added to strings, and the column names are not user input and is being specified by the developer so f-string won't be a problem here (And I also don't see a way that it can be exploited here)
Can someone help me with something
Hi i have a question for a profiling system embed. if the user is verified. How do you make the bot know that that user is verified? if that make sense. for example store info like this one
it ran fine until I added some commands, but after seeing that the commands ran twice, i reverted back those changes but the problem still persists
embed.set_author(url=ctx.message.author.avatar_url) am trying to have the user profile picture and its giving me this error. Command raised an exception: AttributeError: 'Member' object has no attribute 'avatar_url'
avatar.url in 2.0
Well for that i have averification system where the user has to react to the rules to get verified
If thats what ur talking about
yes it adds the verification role
psycopg2 has psycopg2.sql module which fixes this issue
https://www.psycopg.org/docs/sql.html
to the user once they read the rules and
Well ill show u my code
async def start(ctx):
embed=discord.Embed(title="Profile", description="", color=0x00ff00)
embed.add_field(name= f"User: {ctx.author.mention}", value="โ
Verified 18+โ
", inline=False)
embed.add_field(name='Name', value=str(ctx.author.name), inline=True)
embed.set_author(url=ctx.message.author.avatar.url)
await ctx.send("What Is Your Name?")
msg = await client.wait_for('message')
await ctx.send("What Is Your Name?")
msg = await client.wait_for('message')
await ctx.send(embed=embed)
print(f"The embed has been send")
```
Traceback (most recent call last):
File "C:\Users\thoma\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\ext\commands\core.py", line 168, in wrapped
ret = await coro(*args, **kwargs)
File "d:\discord server bot\Bot2.py", line 298, in start
embed.set_author(url=ctx.message.author.avatar.url)
TypeError: Embed.set_author() missing 1 required keyword-only argument: 'name'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\thoma\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\ext\commands\bot.py", line 1055, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\thoma\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\ext\commands\core.py", line 933, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\thoma\AppData\Local\Programs\Python\Python310\lib\site-packages\nextcord\ext\commands\core.py", line 177, in wrapped
raise CommandInvokeError(exc) from exc
nextcord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: Embed.set_author() missing 1 required keyword-only argument: 'name'
set_author(*, name, url=Embed.Empty, icon_url=Embed.Empty)```
Sets the author for the embed content.
This function returns the class instance to allow for fluent-style chaining.
Do i need to add name argument on the async def?
ohh i know what u mean
Dunno they are suggesting f-strings and other weird methods.
I wasn't saying to use psycopg2 for discord bots 
I was saying that psycopg2 has a utility that fixes the issue they were having
embed.set_author(name= client.user.name, url=ctx.message.author.avatar.url) @slate swan ?
Or just use a normal inventory using a list of ints like a sane person.
you could use f-strings which was one of the final conclusions
(i forgor who) he says that f string in sqlite realy not recomended
Or just use a normal inventory using a list of ints like a sane person.
i also store the ids of users :D
I don't think coding 100 elif statements and adding 50 columns is preference.
As you should.
I asked earlier, I think @maiden fable gave an answer but I can't find it. How do I make it so the bot only takes messages containing exclusively a text channel?
I stopped reading after you suggested f-strings yes.
msg.channel.id == id
Honestly we can't be suggesting someone to use f-strings under any circumstances.
Sorry shit internet, so it shouldn't take a message like that
def add_item(name, amount, item):
ae = item.upper()
lst = ae.split(" ")
item = item.upper().replace(" ", "_") if " " in item else item.upper()
cur.execute(f"UPDATE item_list set {item} = {item} - {amount} WHERE NAME = {name}")
conn.commit()```
๐ฟ
then what
That won't work, I don't think, because id would have to be specified, wouldn't it?
Help
@bot.command(aliases=["HELP","Help"])
async def help(ctx):
await ctx.send("De Help Command.",embed = hembed, components=[Button(label="Page 2", custom_id="button1", style = ButtonStyle.blue)])
interaction = await bot.wait_for("button_click", check=lambda inter: inter.custom_id == "button1")
await interaction.respond(type=7,content="De Help Command.",embed=hembed2, components=[Button(label="Page 3",
custom_id="button2", style = ButtonStyle.blue)])
interaction2 = await bot.wait_for("button_click", check=lambda inter: inter.custom_id == "button2")
await interaction2.respond(type=7,content="De Help Command.",embed=hembed3, components=[Button(label="Page 4",
custom_id="button3", style = ButtonStyle.blue)])
interaction3 = await bot.wait_for("button_click", check=lambda inter: inter.custom_id == "button3")
await interaction3.respond(type=7, content="De Help Command.", embed=hembed4, components=[])```
I want to make a loop
like
```py
await ctx.send("De Help Command.",embed = hembed, components=[Button(label="Page 2", custom_id="button1", style = ButtonStyle.blue)])
interaction = await bot.wait_for("button_click", check=lambda inter: inter.custom_id == "button1")```
this is the first line of code
```py
interaction3 = await bot.wait_for("button_click", check=lambda inter: inter.custom_id == "button3")
await interaction3.respond(type=7, content="De Help Command.", embed=hembed4, components=[])```
this is the last line of code
so I want to make a button that will loop back to the first line of code
but discord.ext.tasks.loop doesnt work
what message
Yea...
It's being used across a lot of servers, meaning that I can't specify one id
This is literally the same as my suggestion but with extra steps.
holy not understand what to do
msg.channel == ctx.channel
Slash command, don't have ctx
The channel the interaction was sent from.
Note that due to a Discord limitation, DM channels are not resolved since there is no data to complete them. These are PartialMessageable instead.
help i upload bot to heroku
Do you want to get rid of the big elif's or do you want a slim solution that does require a database edit.
!indention
Indentation
Indentation is leading whitespace (spaces and tabs) at the beginning of a line of code. In the case of Python, they are used to determine the grouping of statements.
Spaces should be preferred over tabs. To be clear, this is in reference to the character itself, not the keys on a keyboard. Your editor/IDE should be configured to insert spaces when the TAB key is pressed. The amount of spaces should be a multiple of 4, except optionally in the case of continuation lines.
Example
def foo():
bar = 'baz' # indented one level
if bar == 'baz':
print('ham') # indented two levels
return bar # indented one level
The first line is not indented. The next two lines are indented to be inside of the function definition. They will only run when the function is called. The fourth line is indented to be inside the if statement, and will only run if the if statement evaluates to True. The fifth and last line is like the 2nd and 3rd and will always run when the function is called. It effectively closes the if statement above as no more lines can be inside the if statement below that line.
Indentation is used after:
1. Compound statements (eg. if, while, for, try, with, def, class, and their counterparts)
2. Continuation lines
More Info
1. Indentation style guide
2. Tabs or Spaces?
3. Official docs on indentation
want to get rid of the big elif's
but also want a slim solution that does require a database edit.
Have you though about a solution? If so what was that solution?
Help
@bot.command(aliases=["HELP","Help"])
async def help(ctx):
await ctx.send("De Help Command.",embed = hembed, components=[Button(label="Page 2", custom_id="button1", style = ButtonStyle.blue)])
interaction = await bot.wait_for("button_click", check=lambda inter: inter.custom_id == "button1")
await interaction.respond(type=7,content="De Help Command.",embed=hembed2, components=[Button(label="Page 3",
custom_id="button2", style = ButtonStyle.blue)])
interaction2 = await bot.wait_for("button_click", check=lambda inter: inter.custom_id == "button2")
await interaction2.respond(type=7,content="De Help Command.",embed=hembed3, components=[Button(label="Page 4",
custom_id="button3", style = ButtonStyle.blue)])
interaction3 = await bot.wait_for("button_click", check=lambda inter: inter.custom_id == "button3")
await interaction3.respond(type=7, content="De Help Command.", embed=hembed4, components=[])```
I want to make a loop
like
```py
await ctx.send("De Help Command.",embed = hembed, components=[Button(label="Page 2", custom_id="button1", style = ButtonStyle.blue)])
interaction = await bot.wait_for("button_click", check=lambda inter: inter.custom_id == "button1")```
this is the first line of code
```py
interaction3 = await bot.wait_for("button_click", check=lambda inter: inter.custom_id == "button3")
await interaction3.respond(type=7, content="De Help Command.", embed=hembed4, components=[])```
this is the last line of code
so I want to make a button that will loop back to the first line of code
but discord.ext.tasks.loop doesnt work
def add_item(name, amount, item):
ae = item.upper()
lst = ae.split(" ")
item = item.upper().replace(" ", "_") if " " in item else item.upper()
cur.execute(f"UPDATE item_list set {item} = {item} - {amount} WHERE NAME = {name}")
conn.commit()``` the
Well that didnt work I want it to where it will add the user profile image
or profile pic ture
someone pls help
I was saying to use f-strings for the column names, not for the values
now you are prune to sql injection
um
waht
Help
@bot.command(aliases=["HELP","Help"])
async def help(ctx):
await ctx.send("De Help Command.",embed = hembed, components=[Button(label="Page 2", custom_id="button1", style = ButtonStyle.blue)])
interaction = await bot.wait_for("button_click", check=lambda inter: inter.custom_id == "button1")
await interaction.respond(type=7,content="De Help Command.",embed=hembed2, components=[Button(label="Page 3",
custom_id="button2", style = ButtonStyle.blue)])
interaction2 = await bot.wait_for("button_click", check=lambda inter: inter.custom_id == "button2")
await interaction2.respond(type=7,content="De Help Command.",embed=hembed3, components=[Button(label="Page 4",
custom_id="button3", style = ButtonStyle.blue)])
interaction3 = await bot.wait_for("button_click", check=lambda inter: inter.custom_id == "button3")
await interaction3.respond(type=7, content="De Help Command.", embed=hembed4, components=[])```
I want to make a loop
like
```py
await ctx.send("De Help Command.",embed = hembed, components=[Button(label="Page 2", custom_id="button1", style = ButtonStyle.blue)])
interaction = await bot.wait_for("button_click", check=lambda inter: inter.custom_id == "button1")```
this is the first line of code
```py
interaction3 = await bot.wait_for("button_click", check=lambda inter: inter.custom_id == "button3")
await interaction3.respond(type=7, content="De Help Command.", embed=hembed4, components=[])```
this is the last line of code
so I want to make a button that will loop back to the first line of code
but discord.ext.tasks.loop doesnt work
Rush is suggesting this ```py
def add_item(name, amount, item):
ae = item.upper()
lst = ae.split(" ")
item = item.upper().replace(" ", "_") if " " in item else item.upper()
cur.execute(f"UPDATE item_list set {item} = ? - ? WHERE NAME = ?", (item, amount, name))
conn.commit()
ooh i see
SOMEONe pls HELp psl
and the expected to be
def channelCheck(message: disnake.Message):
return (len(message.channel_mentions) > 0) and (message.author == inter.author)
I don't think I explained right lmao.
The command called is a config command, meaning that it needs to save the users input. Assuming the message is saved in its entirety a #bot-commands for example, then if I call that from a database, then try to use the message as a channel to send to, it won't.
So inter.channel isn't what I need to use.
TL;DR I need to save the channel to a db, if it has a letter other than the channel, it doesn't work.
yes exactly
async def start(ctx):
embed=discord.Embed(title="Profile", description="", color=0x00ff00)
embed.add_field(name= f"User: {ctx.author.mention}", value=":white_check_mark:Verified 18+:white_check_mark:", inline=False)
embed.add_field(name='Name', value=str(ctx.author.name), inline=True)
embed.set_author(name=, icon=embed.Empty, icon_url=client.user.avatar_url)
await ctx.send("What Is Your Name?")
msg = await client.wait_for('message')
await ctx.send("What Is Your Name?")
msg = await client.wait_for('message')
await ctx.send(embed=embed)
print(f"The embed has been send")
```
You want to make a paginator?
Command raised an exception: AttributeError: 'ClientUser' object has no attribute 'avatar_url'
Like the pythons !help with the pages
Make sure that the column names are being set by the developer and not from any user @small igloo






