#discord-bots
1 messages ยท Page 537 of 1
idk
Just put everything in one
i just coped first and pasted and changed add to removes
indents?
your repl lagging I guess
You use guilt instead of guild, you use add_rremoves instead of remove_roles and you didn't defined member before your check
ok
i fixed rremove and i did member = None
It's time to use a proper IDE 
yep, definitely a repl issue
i domt get it
k
I doubt you coded any of what you have by yourself
member not found
Do you have members intent enabled
whats that
!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.
Enable the members intent
And please READ the entire message, don't just look at the piece of code and copy paste it like everything you've did so far
get rid of all these lines by using
obj = {"item": "fish", "amount": amount}
users[str(user.id)].setdefault("inventory", [])
users[str(user.id)]["inventory"].append(obj)
I get what you're trying to make but there's something you need to be aware of, each "fish" you append will be in its own dict so you have to increase the amount instead of appending the same item
k i did
What did you do
seen messsage and enabled that for my bot
Okay now try again
k
when i said enabled for bot i didnt mean paste the code
lemme do that now
member not found
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.
Hey @harsh mirage! I noticed you posted a seemingly valid Discord API token in your message and have removed your message. This means that your token has been compromised. Please change your token immediately at: https://discordapp.com/developers/applications/me
Feel free to re-post it with the token removed. If you believe this was a mistake, please let us know!
oh god
import discord
from discord import Intents
from discord.ext import commands
intents = Intents.default()
intents.members = True
client = discord.Client()
member = None
@client.event
async def on_ready():
print("Logged in.")
@client.event
async def on_raw_reaction_add(payload):
message_id = payload.message_id
if message_id == 898312112944865302:
guild_id = payload.guild_id
guild = discord.utails.find(lambda g : g.id == guild_id, client.guilds)
if payload.emoji.name == 'yen':
role = discord.utils.get(guilt.roles, name = 'Yellow Team')
elif payload.emoji.name == "euro":
role = discord.utils.get(guild.roles, name = 'Blue Team')
else:
role = discord.utils.get(guild.roles, name = payload.emoji.name)
member = None
if role is not None:
member = discord.utils.find(lambda m : m.id == payload.user_id, guild.members)
if member is not None:
await member.add_roles(role)
else:
print("Member not found.")
else:
print("Role not found")
@client.event
async def on_raw_reaction_add(payload):
message_id = payload.message_id
if message_id == 898312112944865302:
guild_id = payload.guild_id
guild = discord.utils.find(lambda g : g.id == guild_id, client.guilds)
if payload.emoji.name == 'yen':
role = discord.utils.get(guilt.roles, name = 'Yellow Team')
elif payload.emoji.name == "euro":
role = discord.utils.get(guild.roles, name = 'Blue Team')
else:
role = discord.utils.get(guild.roles, name = payload.emoji.name)
member = None
if role is not None:
member = discord.utils.find(lambda m : m.id == payload.user_id, guild.members)
if member is not None:
await member.add_removes(role)
else:
print("Member not found.")
else:
print("Role not found")
@client.event
async def on_raw_reaction_remove(payload):
pass
client.run')```
bruh srry
remove your token and PLEASE put here
You're missing the intents
In the message you were supposed to read ^
Wrong indentation, align it same as the if
bruh whats wrong there
and i AGAIN changed guilt
Then compare these two pictures
Just look at the parameters
Something with "intents"
And lastly, align this to the if
And don't forget to learn Pytho n before doing a bot, it's always better than copy pasting code without knowing what you do
im beghiner in bots, thats hoe i start ehen i lwarn something new. i copy n paste and at the end i rewatch the vid to see what he said for definitions
!resources
The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.
== not =
try both with '==' and '=' still error
did
and I said to align not replace
ty
Not like I already sent before but sure
import discord
from discord import Intents
``` why are you Importing from discord, if ur using import discord?
Import discord is like using
from discord import *
- means all
ehhh
You normally never really do that
You only import what you need
So no don't use *
unless what you need is everything
Which is never the case

aligned, still 'None' error
!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.
i did
oh wait...
No you didn't.......
Not my fault if you don't have the Python basics with you
# code
extensions = [
"cogs.event",
"cogs.fun",
"cogs.information",
"cogs.leveling",
"cogs.manageserver",
"cogs.mod",
"cogs.modmail",
"cogs.music",
"cogs.other",
"cogs.owner",
"cogs.search",
"cogs.set_prefix",
]
if __name__ == "__main__":
for ext in extensions:
bot.load_extension(ext)
#error
$ d:/ditttt2044/env/Scripts/python.exe d:/ditttt2044/adit.py
Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "help" is not found
Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "help" is not found```
why this error?
you probably removed the help command with bot.remove_command or by setting help_command=None in commands.Bot
WDYM
lol yur kinda passive aggressive
import discord
from discord.ext import commands
bot, token = (
commands.Bot(
command_prefix="d1t ", help_command=None, intents=discord.Intents().all()
),
"...",
)
extensions = [
"cogs.event",
"cogs.fun",
"cogs.information",
"cogs.leveling",
"cogs.manageserver",
"cogs.mod",
"cogs.modmail",
"cogs.music",
"cogs.other",
"cogs.owner",
"cogs.search",
"cogs.set_prefix",
]
if __name__ == "__main__":
for ext in extensions:
bot.load_extension(ext)
bot.run(token)
done @slate swan
i feel yur pain...
aint it obvious that if you help_command = None there will be no help command?
you need to write it again , it often happens when you copy paste code from other files
i have command help
what cog is it in?
Bruh
show the cog
I was coding and my restarted automatically
Perfect
i have a question
so im trying to get it so my bot will delete it's message when i react to it with a specific emoji, how does that work?
!d discord.on_reaction_add
discord.on_reaction_add(reaction, user)```
Called when a message has a reaction added to it. Similar to [`on_message_edit()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_message_edit "discord.on_message_edit"), if the message is not found in the internal message cache, then this event will not be called. Consider using [`on_raw_reaction_add()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_raw_reaction_add "discord.on_raw_reaction_add") instead.
Note
To get the [`Message`](https://discordpy.readthedocs.io/en/master/api.html#discord.Message "discord.Message") being reacted, access it via [`Reaction.message`](https://discordpy.readthedocs.io/en/master/api.html#discord.Reaction.message "discord.Reaction.message").
This requires [`Intents.reactions`](https://discordpy.readthedocs.io/en/master/api.html#discord.Intents.reactions "discord.Intents.reactions") to be enabled.
Note
This doesnโt require [`Intents.members`](https://discordpy.readthedocs.io/en/master/api.html#discord.Intents.members "discord.Intents.members") within a guild context, but due to Discord not providing updated user information in a direct message itโs required for direct messages to receive this event. Consider using [`on_raw_reaction_add()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_raw_reaction_add "discord.on_raw_reaction_add") if you need this and do not otherwise want to enable the members intent.
!d discord.on_raw_reaction_add
Check if the reaction.emoji is equal to the emoji you want, and that if the user.bot is Fale.
How can I create a pre formatted text setting that would set color that I can use as s.print
I am using the color-print module found at https://pypi.org/project/print-color/#description
I am using the colored text in the console for debugging my bot
import discord
from discord import Intents
from discord.ext import commands
intents = Intents.default()
intents.members = True
client = discord.Client()
member = None
@client.event
async def on_ready():
print("Logged in.")
@client.event
async def on_raw_reaction_add(payload):
message_id = payload.message_id
if message_id == 898312112944865302:
guild_id = payload.guild_id
guild = discord.utails.find(lambda g : g.id == guild_id, client.guilds)
if payload.emoji.name == 'yen':
role = discord.utils.get(guild.roles, name = 'Yellow Team')
elif payload.emoji.name == "euro":
role = discord.utils.get(guild.roles, name = 'Blue Team')
else:
role = discord.utils.get(guild.roles, name = payload.emoji.name)
if member:
if condition:
pass
if role is not None:
member = discord.utils.find(lambda m : m.id == payload.user_id, guild.members)
if member is not None:
await member.add_roles(role)
else:
print("Member not found.")
else:
print("Role not found")
@client.event
async def on_raw_reaction_add(payload):
message_id = payload.message_id
if message_id == 898312112944865302:
guild_id = payload.guild_id
guild = discord.utils.find(lambda g : g.id == guild_id, client.guilds)
if payload.emoji.name == 'yen':
role = discord.utils.get(guild.roles, name = 'Yellow Team')
elif payload.emoji.name == "euro":
role = discord.utils.get(guild.roles, name = 'Blue Team')
else:
role = discord.utils.get(guild.roles, name = payload.emoji.name)
if member:
if condition:
pass
if role is not None:
member = discord.utils.find(lambda m : m.id == payload.user_id, guild.members)
if member is not None:
await member.add_removes(role)
else:
print("Member not found.")
else:
print("Role not found")
@client.event
async def on_raw_reaction_remove(payload):
pass
client.run('TOKEN ')```
guess
I don't help you anymore, you don't do what I say. You copy paste code you don't even understand. You don't know Python basics.
I'm sorry but at this point you should learn Python before doing a bot.
You have to set a default value for member.
I already explained him that over 6 times
Man got so frustrated, I believe you were extra stupid or something.
Good luck on making him understand Python's basics when he probably never really heard about programming before copying the code
nvm... ill figure it by myself. yall will see when i became the best programmer in the future
It's okay, Krypton.
At least you have humor, that's good 
Anyways, you both have a great day ^^
...
Okay, anyways, you have to set a default value for member before the if statement.
Example:
name = None
age = None
if age is not None:
name = "Seif Wessam"
print(name)
i didnt
You never did, I already explained you so many times
role was None; therefore, member was never defined.
just laugh.... remeber my name
And you also haven't added the intents as I've told you also around 3-4 times
why wont this work?
1 @Bot.command()
2 async def test(ctx):
3 user = ctx.author
4 if user.id == (853991571702939668):
5 message = await ctx.send('testing')
6 @Bot.event
7 async def on_reaction_add(reaction, user):
8 if reaction.emoji == (':EBup:'):
9 await message.delete
10 else:
11 await ctx.send("you can't use that command")
You defined intents but you never used them.
T H I S my guy
Please read when I try to help you
Indentation.
If you don't do what we tell you to do we can't help you out
where?
Somewhere, on earth, inside your computer, right into your code.
not just identation
Naming conventions momentum
@Bot.event is inside your command's function.
in the 4th line he/she uses user that's not defined
That's the only thing that got my attention, I haven't checked the rest of the code.
yea, identation it's not just the problem
follow python naming convenstions (unrelated to the error)
ive got an idea
im doing that code from yesterday. imma give up
i will just use carl bot's reaction role
cool
@Bot.command()
async def test(ctx):
user = ctx.author
if user.id == (853991571702939668):
message = await ctx.send('testing')
@Bot.event
async def on_reaction_add(reaction):
if reaction.emoji == (':EBup:'):
await message.delete
else:
await ctx.send("you can't use that command")
``` this may work
@Bot.command()
async def test(ctx):
if ctx.author.id == 853991571702939668:
message = await ctx.send('testing')
reaction, user = await Bot.wait_for("reaction_add", check=lambda r: r.user == ctx.author and r.emoji == '<:EBup:THE_EMOJI_ID_HERE>')
await message.delete()
else:
return
@fallow mauve spoonfed. I'm having a good day.
I made it in the way he wanted it to work.
But yours is partially correct.
It's correct from the code part, but not what he wants to do.
you didnt have to do that
i made it here on discord and i may did some errors
tbh i don't know what he wants to do
yep just read
He wants to send a message and wait for a reaction to be added by the author and then delete the message after the reaction is added.
I've practiced a lot to understand what a one wants to do from just a broken code by working with many newbies. 
oh okay
yeaa ๐คฃ

well, the code doesnt work
Errors?
Or actually, show me your code.
I'm pretty sure I know where the issue is.
yeah there are no errors given
probably indentation
Do you get any errors?
So what exactly "doesn't work"?
has the bot even started
it sends the message, i react to it and nothing happens
badwords = ["kayle"]
@commands.Cog.listener()
async def on_message(msg):
for word in badwords:
if word in msg.content:
await msg.channel.send('hm')
await bot.process_commands(msg)
``` any ideas why this doesnt work? the console doesnt give any errors
self
and you probably want to put badwords in your class init, not just floating
any ideas?
ive been trying to get this kinda thing to work with a friend of mine and it just wont
print(reaction.emoji)
help me.
Code?
cant i just put it outside the class?
yeah sure
hm
me?
idk a list with lots of values in the __init__ function seems messy
yeah you do you then, it really doesnt matter
okay
i gtg do school, b back later
No, and also print(reaction.emoji).
anyone wanna hop in a VC and help a total noob out ๐
How do people hyper link text in titles without it turning blue
it is author link
^
!d discord.Embed.set_author
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.
ohh
Wait I didn't know you could set url's in the .set_author part of an embed instead of icon_url
Dont know whats going on here and why its saying this module is no callable
It's commands.Bot
capital B
๐ฆ
Okay, next query, as Im following a tutorial just to get a grasp of how to make a button in my server and im receiving this
im presuming im likely missing a line somewhere to define the @button is actually a command?
!pypi disnake is a pretty great fork.
https://scoopydev.xyz/github?repo=python-discord-bot I've made a tutorial of making a Discord bot using that library.
Isn't it faster to write the normal github repo 
Don't focus too much. Lmao.
xD
how do i use functions in my cog if the function was like this? i tried it earlier but it says "Command raised an exception: AttributeError: 'Events' object has no attribute 'h1_append'"
class Events(commands.cog):
def __init__(self, bot):
self.bot=bot
self.test = []
def h1_append(self, value):
self.test.append(value)
@commands.command()
async def append(self, ctx, value):
await self.h1_append(value)
Hello, I'm trying to create level event, but when I send 1 message at 0 exp, I instantly level up. How should I make it more like Mee6- I would need to send amount of messages, so I can level up to level 1. The code :python @client.event async def on_message(message): if message.author.bot == False: with open('users.json', 'r') as f: users = json.load(f) await update_data(users, message.author) await add_experience(users, message.author, 1) await level_up(users, message.author, message) with open('users.json', 'w') as f: json.dump(users, f) await client.process_commands(message) async def update_data(users, user): if not f'{user.id}' in users: users[f'{user.id}'] = {} users[f'{user.id}']['experience'] = 0 users[f'{user.id}']['level'] = 1 async def add_experience(users, user, exp): users[f'{user.id}']['experience'] += exp async def level_up(users, user, message): with open('levels.json', 'r') as g: levels = json.load(g) experience = users[f'{user.id}']['experience'] lvl_start = users[f'{user.id}']['level'] lvl_end = int(experience ** (1 / 5)) if lvl_start < lvl_end: await message.channel.send(f'{user.mention} has leveled up to level {lvl_end}') users[f'{user.id}']['level'] = lvl_end

try this ```py
Events().h1_append(the value)
but im making a command inside the cog/class
so Events isnt defined yet
i think thats how that works
so you want to use the function in the command in the cog
yes
then do this in the command ```py
self.h1_append(value)
hm
if its a async function then you await it
If Im making a discord bot taht requires a database use..do I ask help here or on #databases 
def hl_append(self, value):
self.badwords.append(self.value)
``` is this right?
hm
Maybe you forgot to save the file or re-run the bot
hm
I don't think you need self as a param there
its in a cog
noticed that
still
probably havent touched dpy in a hot min
it's still just a class function
at the .append()?
oh
you mean the function
in the def
hm
and h1_append is not a coroutine
hm
whats your issue
scroll up
this
Too far
no
it isnt too far
ok and how do you call it
?
by using it?
Show me your code, im not asking how to call a class func

async def append(self, ctx, value):
await ctx.send('e')
self.hl_append(value)
wait why hl
hl_append is the name of the function
you defined h1 and calling hl
it's both h1 in the code you've sent above
wait I think its because of a typo..
I see the l at value
Thats what im saying lol
it works now
๐
thanks ๐ฟ

where i can find tutorial to unban command with ID users not nickname
why do you need a tutorial when theres docs
can you send me that?
!d discord.Member.ban
await ban(*, delete_message_days=1, reason=None)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Bans this member. Equivalent to [`Guild.ban()`](https://discordpy.readthedocs.io/en/master/api.html#discord.Guild.ban "discord.Guild.ban").
await unban(*, reason=None)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Unbans this member. Equivalent to [`Guild.unban()`](https://discordpy.readthedocs.io/en/master/api.html#discord.Guild.unban "discord.Guild.unban").
import discord
#client
client = discord.client()
#do somtching idiot
clint.run```
whats wrong here ?
XDDDDD
4th line
run is a method that takes a token
is a joke?
client.run("yourbottoken")
?
"clint"
pepega
why not use bot tho
cuz pepega 
we dunno
okie
discord.Client, not client - also you put clint in your .run.
Also if you want to do commands use commands.Bot not discord.Client and read the docs on ext.commands
sayonara
but atleast we know what's wrong with the code
wat
?
Client capital c, not client lowercase c
oh nice
.
wow
๐ฟ.
full stop
.
Hi guys , I have a bot hosted with replit and it logs when a message is deleted or edited ... ., but when I restart it ,
it cannot log changes for messages that were sent before the restart
please elaborate more. What do you mean while loops?
wdym
.run() has a reconnect kwarg that you can set.
i wanna spam ping people
!rule 5
5. Do not provide or request help on projects that may break laws, breach terms of services, or are malicious or inappropriate.
Did you read it
and can probably get you API banned.
^
as if you can do it
haha
if i get reported or will it just pop me
what?
no. your token gets invalidated and when you try to reconnect it will prompt you to contact discord's Trust and Safety to reinstate your bot iirc
but bans can also be temporary and per-ip

How do to a person by their id?
bot.get_user(id) or guild.get_member(id)
Oh sorry, accidently mishprashed my question. How can I DM a person by thier id
Would this be right for my code? Iโm trying to make the brackets say n/a instead https://hastebin.com/kijozetewa.csharp
if "User Badges" == None:
userbadges = "N/A"
a string wont be None
Thanks
if userbadges == None:
userbadges = "N/A"
Guys I want to make a discord bot all rounder using python and with web control who has interest dm me
What do I do if I canโt use the command when itโs for everyone? The owner can do it but when I try, it doesnโt work and thereโs no errors
Show the code @slate swan
File "C:\Users\minua\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "C:\Users\minua\Downloads\ex.py", line 59, in translation
language = language[0]
TypeError: 'NoneType' object is not subscriptable
order completed!
spanish
<class 'str'>
Final text: Translated(src=en, dest=es, text=spanish, pronunciation=spanish, extra_data="{'translat...")
order completed!
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\minua\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "C:\Users\minua\Downloads\ex.py", line 59, in translation
language = language[0]
TypeError: 'NoneType' object is not subscriptable```
what am I doing wrong?
it was working before
language = cur.fetchone()
language: list
language = language[0]
print(language)
print(type(language))```
Guys, i need help, when you make a bot in one file and you create an on_message event, it stops command processing and you have to initialize it yourself, i don't know how to recreate the same behavior using an event inside a discord.Cog
And it doesnโt work when someone @ someone else, but itโs supposed to
its definitely not in the code you provided, there must be a decorator at the top specifying the permissions
language is None.
!e
array = None
print(array[0])
@dapper cobalt :x: Your eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "<string>", line 2, in <module>
003 | TypeError: 'NoneType' object is not subscriptable
yes of course
Yo, anyone here knows how dpy sends events? I ain't able to understand lol
Aren't you a solid contributor at disnake?
Oh, wait. It was just your print().
Can we stop this now?
Lmao, alright.
But I ain't kidding. Do u know how it handles events?
Nope.
@dapper cobalt as you can see, 'spanish' is in the variable language
Easy
So basically, internally they connect to a websocket
Okay?
This websocket sends back messages
Can you show your code?
Mhm
You read those messages, if it's the dispatch type it has an event name and event data
Mhm
cur.execute('SELECT id FROM flashcards_test ORDER BY id DESC')
print('order completed!')
cur.execute('SELECT Language FROM flashcards_test WHERE User = (?)', (user,))
language = cur.fetchone()
language: list
language = language[0]
print(language)
print(type(language))```
Then you decide what to do from there that's the basics
You could dispatch it etc again
Ah okay
Hey, is there any like github page for discord.py?
Templates or for discord.py itself?
channel_entry = 862766760741699615
channel = bot.get_channel(channel_entry)
x = input()
await channel.send(x)```
how can i make this work so it doesnt only send the input once and i can reuse it without restarting the bot each time?
BTW @pliant gulch your wrapper has got supports for events or it is still a WIP?
A while loop and make it sleep at the end of each time.
It's very much nearing stable release, all events pretty much work. We have a lot of models and I've basically finished commands extension already
Ah okay cool
Ty
^^
Here's a flowchart for release if your interested
someone help me please
I just did..
Thanks ๐
oh ty lol didnt see that
The file https://hastebin.com/ifazezuzis.py
can you help me too?
@dapper cobalt any tips?
your missing the arguement ctx
so ctx.channel.send?
Remove ctx from the function's paramters.
ohokay
What is language: list?
I think you mean list(language).
e
Task exception was never retrieved
exception=AttributeError("'NoneType' object has no attribute 'send'")>
Traceback (most recent call last):
await channel.send(x)
AttributeError: 'NoneType' object has no attribute 'send'
And also, print language right after you define it, and see what it returns.
its the same thing essentially
Either the channel does not exist or is not in the bot's cache.
channel exists
Do you have intents enabled?
yes
it worked before, but now that im trying to loop it so it can be used multiple times instead of once it doesnt want to work for some reason
Are you starting the loop before the bot starts?
before the bot.run?
Is it inside an on_ready event or even under a await bot.wait_until_ready()?
order completed!
language ('spanish',)
spanish
<class 'str'>
Final text: Translated(src=en, dest=es, text=!change, pronunciation=!change, extra_data="{'translat...")
order completed!
language None```
I see now
lmao
Yep, the loop starts before the bot does. Which means, the bot's cache has not loaded yet.
Start the loop inside the on_ready event.
alright
Or under await bot.wait_until_ready().
@bot.event
async def on_ready():
await bot.change_presence(status=discord.Status.idle, activity=discord.Game(f"with {len(bot.guilds)} servers | ^help"), afk=True)
print("Bot running with:")
async def input_echo():
print("Username: ", bot.user.name)
print("User ID: ", bot.user.id)
channel_entry = 862766760741699615
channel = bot.get_channel(channel_entry)
x = input()
await channel.send(x)
pass
bot.loop.create_task(input_echo())
``` i doubt this is proper lmao
What have i done wrong here, from everything i can see it should be fine but obviously im missing something
Hello, i have an error :
AttributeError: 'NoneType' object has no attribute 'get_channel'
My code :
initFunction.py :
async def editChannel(discordGuildID, discordChannelID, dataNotif):
guild = bot.get_guild(discordGuildID)
getChannel = guild.get_channel(discordChannelID)
await getChannel.edit(name=f"{dataNotif}")
main.py :
await editChannel(discordGuildID,discordChannelID,dataNotif)
The function: above the on_ready.
The bot.loop.create_task(input_echo()): inside the on_ready.
ohh
okay
async def input_echo():
print("Username: ", bot.user.name)
print("User ID: ", bot.user.id)
channel_entry = 862766760741699615
channel = bot.get_channel(channel_entry)
x = input()
await channel.send(x)
pass
@bot.event
async def on_ready():
await bot.change_presence(status=discord.Status.idle, activity=discord.Game(f"with {len(bot.guilds)} servers | ^help"), afk=True)
print("Bot running with:")
bot.loop.create_task(input_echo())
like this?
coming from js
? anyways... Read this:
_ _
Bot is not ready yet
And my mistake, it worked very well until a few weeks ago.
async def edit_channel(channelID:int, dataNotif):
channel = bot.get_channel(channelID)
await channel.edit(name=dataNotif)
await edit_channel(1234 ,"Some Text")
Add a sleep is a solution ?
does anyone know how i can limit the amount of times a command can raise CommandOnCooldown
That, and also make sure the function is executed after the bot has started. So that the cache is loaded.
You should only call functions that require the bot to be ready in functions the bot calls on events and stuff
!d discord.ext.commands.cooldown
@discord.ext.commands.cooldown(rate, per, type=discord.ext.commands.BucketType.default)```
A decorator that adds a cooldown to a [`Command`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Command "discord.ext.commands.Command")
A cooldown allows a command to only be used a specific amount of times in a specific time frame. These cooldowns can be based either on a per-guild, per-channel, per-user, per-role or global basis. Denoted by the third argument of `type` which must be of enum type [`BucketType`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.BucketType "discord.ext.commands.BucketType").
If a cooldown is triggered, then [`CommandOnCooldown`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.CommandOnCooldown "discord.ext.commands.CommandOnCooldown") is triggered in [`on_command_error()`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.discord.ext.commands.on_command_error "discord.discord.ext.commands.on_command_error") and the local error handler.
A command can only have a single cooldown.
@dapper cobalt i did this, still didnt work
Is it the same issue?
ye
Can I see the error again?
e
Task exception was never retrieved
future: <Task finished name='Task-1' coro=<input_echo() done, defined at D:\This PC (Pre 07-31-2021)\desktop\vaclav\Vaclav\bot.py:89> exception=AttributeError("'NoneType' object has no attribute 'send'")>
Traceback (most recent call last):
File "D:\This PC (Pre 07-31-2021)\desktop\vaclav\Vaclav\bot.py", line 94, in input_echo
await channel.send(x)
AttributeError: 'NoneType' object has no attribute 'send'
Bot running with:
Username: Atheon
User ID: 890318171817537577```
i know how to put a cooldown what im asking is how would i limit the amount of times a command will respond i.e. command is on cooldown retry after 69 seconds because the user could just spam this and it will send a cooldown message for every time the user sends the command
!d discord.ext.commands.CommandOnCooldown
exception discord.ext.commands.CommandOnCooldown(cooldown, retry_after, type)```
Exception raised when the command being invoked is on cooldown.
This inherits from [`CommandError`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.CommandError "discord.ext.commands.CommandError")
asyncio.sleep(cooldown_time)
youll have to define cooldown_time tho
await canal.set_permissions(ctx.guild.default_role, send_messages=True)```how i can use this to change cooldown?
canal?
how to get the current time for UTC + 2
testembed.set_footer(
text=f"๐ฌ โข {ctx.author} - {time}"
never heard that one before
ah
someone knows?????
i want to set in fooster \๐ฌ โข Kr3mu#9515 - 21.37
embed.timestamp = datetime.datetime.now()
!d discord.Embed.timestamp
The timestamp of the embed content. This is an aware datetime. If a naive datetime is passed, it is converted to an aware datetime with the local timezone.
Same error
Try datetime.datetime instead.
^
or its another code
Can I see your code?
!d discord.TextChannel.slowmode_delay
The number of seconds a member must wait between sending messages in this channel. A value of 0 denotes that it is disabled. Bots and users with manage_channels or manage_messages bypass slowmode.
No.
why
testembed.timestamp = datetime.datetime.now()
^
did muting/deafening someone with cmds is possible?
That's for the date, and the footer is just the emoji and ctx.author.
tnx
ok i try
thanks
I do not think so.
um but isee on stackoverflow we can mute
but idk if it work
I think you can toggle the member's VoiceState.mute to True.
!d discord.VoiceState.mute
Indicates if the user is currently muted by the guild.
oops
Something like
ctx.VoiceStatue.mute = True
I'm completely unsure and I doubt that this is correct.
idk im just trying to change ban to mute, and when i run it seems like working
@dapper cobalt anything about this?
Hi guys , I have a bot hosted with replit and it logs when a message is deleted or edited ... ., but when I restart it ,
it cannot log changes for messages that were sent before the restart
@commands.command()
@commands.has_role('- Hi Owners')
async def givelevel(self, ctx: commands.Context, member: discord.Member=None, *, lvl:int):
if member == None:
return
if ctx.guild == None:
return
result = await self.find_or_insert_user(member)
user_id, guild_id, xp, level = result
print(xp, level)
level = lvl
cursor = await self.db.cursor()
await cursor.execute('Update users set xp=?, level=? where user_id=? and guild_id=?', (xp, level, user_id, guild_id))
await self.db.commit()
await ctx.send(f"{member.mention} level changed to {lvl}")
``` i have givelevel it works fine on users but when i try to give my self level it says its changed but its not
youd have to use a db
any link, docs plz
Try printing member.
All I know is that channel returns None.
!d sqlite3
Source code: Lib/sqlite3/
SQLite is a C library that provides a lightweight disk-based database that doesnโt require a separate server process and allows accessing the database using a nonstandard variant of the SQL query language. Some applications can use SQLite for internal data storage. Itโs also possible to prototype an application using SQLite and then port the code to a larger database such as PostgreSQL or Oracle.
The sqlite3 module was written by Gerhard Hรคring. It provides a SQL interface compliant with the DB-API 2.0 specification described by PEP 249, and requires SQLite 3.7.15 or newer.
!d pymongo though.
Whats the difference between mongodb and pymongo
is it possible to have an event that runs whenever someone adds an emoji to a message, and get me the message ID AND the user ID AND the emoji added? is there something similar for when someone removes and emoji? My goal is giving a user a role whenevr they react with a specific emoji'
!d discord.on_reaction_add
discord.on_reaction_add(reaction, user)```
Called when a message has a reaction added to it. Similar to [`on_message_edit()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_message_edit "discord.on_message_edit"), if the message is not found in the internal message cache, then this event will not be called. Consider using [`on_raw_reaction_add()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_raw_reaction_add "discord.on_raw_reaction_add") instead.
Note
To get the [`Message`](https://discordpy.readthedocs.io/en/master/api.html#discord.Message "discord.Message") being reacted, access it via [`Reaction.message`](https://discordpy.readthedocs.io/en/master/api.html#discord.Reaction.message "discord.Reaction.message").
This requires [`Intents.reactions`](https://discordpy.readthedocs.io/en/master/api.html#discord.Intents.reactions "discord.Intents.reactions") to be enabled.
Note
This doesnโt require [`Intents.members`](https://discordpy.readthedocs.io/en/master/api.html#discord.Intents.members "discord.Intents.members") within a guild context, but due to Discord not providing updated user information in a direct message itโs required for direct messages to receive this event. Consider using [`on_raw_reaction_add()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_raw_reaction_add "discord.on_raw_reaction_add") if you need this and do not otherwise want to enable the members intent.
ooo i see
MongoDB is the database itself, pymongo is a driver for it.
oh ๐ค
Ty
!d discord.on_reaction_remove
discord.on_reaction_remove(reaction, user)```
Called when a message has a reaction removed from it. Similar to on\_message\_edit, if the message is not found in the internal message cache, then this event will not be called.
Note
To get the message being reacted, access it via [`Reaction.message`](https://discordpy.readthedocs.io/en/master/api.html#discord.Reaction.message "discord.Reaction.message").
This requires both [`Intents.reactions`](https://discordpy.readthedocs.io/en/master/api.html#discord.Intents.reactions "discord.Intents.reactions") and [`Intents.members`](https://discordpy.readthedocs.io/en/master/api.html#discord.Intents.members "discord.Intents.members") to be enabled.
Note
Consider using [`on_raw_reaction_remove()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_raw_reaction_remove "discord.on_raw_reaction_remove") if you need this and do not want to enable the members intent.
@dapper cobalt help lmao
Try printing channel.
wdym
does the channel exist?
yes the channel exists
it says nonetype
ill try and copy the channel id again ig
I need help
One category help?
try printing channel like he said
do print(channel)?
yes
before or after the input statement
before i guess
Did you print channel though
!d discord.Member.edit
await edit(*, nick=..., mute=..., deafen=..., suppress=..., roles=..., voice_channel=..., reason=None)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Edits the memberโs data.
Depending on the parameter passed, this requires different permissions listed below...
mute/deafen kwargs @brave flint
note that they must be connected to a voice channel or you will get discord.errors.HTTPException: 400 Bad Request (error code: 40032): Target user is not connected to voice.
a
the print(channel) is above the x definitive
hm
but the even on_message_delete or _edit do no trigger on old messages after restarting the bot, so do u have any idea please
thx i will try it
np
ok tq
Currently running into something strange. have the following code and I can get the bot to generate the button (practicing with buttons)
but then my interaction fails, any clues?
delete system 32
Personally, I would suggest against using third-party libraries for buttons and drop-downs :)
discord.py has them already in v2.0, which you install from github
of course its all up to you though. ๐ - hope you get someone here that knows discord-components, all i know is the official way with Views
Yeah I tried importing the discord.py v2.0 just seemed to break everything hahaha
async def input_echo():
channel_entry = 862766760741699615
channel = bot.get_channel(channel_entry)
x = input()
await channel.send(x)
``` how can i make it so that every input i make into the console gets sent to this channel? currently it only works once per startup
it'll mostly be stuff like avatar_url -> avatar.url, not that many changes and imo its worth the effort xD
is there a reddit page for discord.py or pycord
they have (both) a discord server - see channel topic
Im still getting used python so changing my libraries might be tossing myself right back into the tumble dryer
How would you send success/error messages.
- Create exceptions
CommandSuccessandCommandFailureand catch them inon_command_errorevent. - Create utility functions
success_embedanderror_embedand writereturn await ctx.send(embed=success_embed(โmessage text")
Custom context class isnโt a good solution for me.
i feel this..
ah, makes sense. well good luck with discord-components 
@bot.command(name='poopie')
async def poopie():
#work
return
@poopie.error()
async def poopie.error(ctx,error):
if isinstance(error,<error here>):
#work```
If i can get this part to work might see how to convert what ive done into V2
is there anyway to kinda put a cooldown on a on cooldown error???? to prevent this from happening
asyncio.sleep(time)
especially if a lot of the commands are already in the library ๐
!d asyncio.sleep
coroutine asyncio.sleep(delay, result=None)```
Block for *delay* seconds.
If *result* is provided, it is returned to the caller when the coroutine completes.
`sleep()` always suspends the current task, allowing other tasks to run.
Setting the delay to 0 provides an optimized path to allow other tasks to run. This can be used by long-running functions to avoid blocking the event loop for the full duration of the function call.
Deprecated since version 3.8, removed in version 3.10: The `loop` parameter. This function has been implicitly getting the current running loop since 3.7. See [Whatโs New in 3.10โs Removed section](https://docs.python.org/3/whatsnew/3.10.html#whatsnew310-removed) for more information.
Example of coroutine displaying the current date every second for 5 seconds:
so many imports
i knoww
what do you mean by this??? i still want it to react with cooldown like twice but after that it stops responding
maybe thats why V2 is better hahahaha
it puts the command in sleep mode for a specific amount of time
i dont think its local tho,i think it affects all users from using that command while its in CD
could be wrong but
ยฏ_(ใ)_/ยฏ
anyone have any projects i can collaborate on, i'm bored as hell
so where would i put this?
send code
just for the bit that sends the cooldown message is all i need
@client.listen()
async def on_command_error(ctx: Context, error):
if isinstance(error, commands.CommandOnCooldown):
await ctx.send("this command is on cooldown, retry after {} seconds.".format(round(error.retry_after, ndigits=2)))
could you put all those imports in a dictionary to then collapse it to make the code a bit neater?
async def on_command_error(ctx: Context, error):
if isinstance(error, commands.CommandOnCooldown):
await ctx.send("this command is on cooldown, retry after {} seconds.".format(round(error.retry_after, ndigits=2)))
asyncio.sleep({}.format(round(error.retry_after))```
try that, lmk if it works
ok
does nothing i can still get the cooldown message multiple times
thats very weird
wondering if you put them in a dictionary if it would interfere with the commands accessing them
lemme look at mine and see if i can compare
very interesting spotify name :)
oh
what did you expect its just sleeping
i see what i did wrong lmao
@client.listen()
async def on_command_error(ctx: Context, error):
if isinstance(error, commands.CommandOnCooldown):
await ctx.send("this command is on cooldown, retry after {} seconds.".format(round(error.retry_after, ndigits=2)))
await asyncio.sleep({}.format(round(error.retry_after))```
try that
there is no differece
yes there is
there isnt
ive added 'await' to the final line
and i fixed it you were missing '' with the {} and a ending )
hm
ok
lmk if it works or not
it just sleeps for the rest of time
it does nothing
then im clueless, thats all i can think of
u slept for the amount of time the cd was
i need it to limit the amount of times commandoncooldown is called so i cant just spam it over and over and get rate limited
why no work?
I have a problem, when I put some functions outside my main.py file and put in initFunction.py, it doesn't work anymore, it doesn't find information like guild name, etc...
I use async def.
from discord.ext import commands,tasks
import discord
import requests
from xml.dom import minidom
import time
from os.path import exists
from asyncio import sleep
intents = discord.Intents()
intents.members = True
bot = commands.Bot(command_prefix='!', intents =intents)
async def editchannel(discordGuildID):
print(type(discordGuildID))
discordGuildID = int(discordGuildID)
print(type(discordGuildID))
print(discordGuildID)
guild = bot.get_guild(817398581005647872)
print(guild)
main.py :
[...]
await editchannel('9595959')
Any solution ?
This worked very well until a fortnight ago.
@slate swan do u have any idea how to handle this
i truly suck at db lol
im not the right person to ask
help??```py
@commands.Cog.listener()
async def on_message(self,message):
msg=message.jump_url.split('/')
chann=self.bot.get_channel(msg[-2])
mess=await chann.fetch_message(msg[-1])
await message.channel.send(mess.content)
await message.channel.send(mess.author)
No problem but why use db with the issue I mentionned
a split is a list of str, you need to cast to an int
that's unexpected, probably because of message cache ig
not sure
you have to log the data somewhere, without db its just stored as memory
thatโs expected, thatโs how itโs meant to work with dpy
you use raw events when an object isnโt cached or youโre not sure
so message caching is the reason behind it 
how tf do i fix this shit
so many imports that you probably dont use
so i moved my commands to separate files within the repl so i could categorize them, and now they wont work
why?
class discord.ext.commands.Cog(*args, **kwargs)```
The base class that all cogs must inherit from.
A cog is a collection of commands, listeners, and optional state to help group commands together. More information on them can be found on the [Cogs](https://discordpy.readthedocs.io/en/master/ext/commands/cogs.html#ext-commands-cogs) page.
When inheriting from this class, the options shown in [`CogMeta`](https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.CogMeta "discord.ext.commands.CogMeta") are equally valid here.
check this out if you haven't yet
can anyone help me pls
I am using on_reaction_add put when i try to print reaction, Reaction.message, user nothing happens
any clues?
@client.event
async def on_reaction_add(user, reaction):
print(user)
print(Reaction.message)
print(reaction)```
First of all, it should be a lowercase r. Secondly, are you sure that's the right order of parameters? Thirdly, this works only for new messages being reacted, I think.
!d discord.on_reaction_add
discord.on_reaction_add(reaction, user)```
Called when a message has a reaction added to it. Similar to [`on_message_edit()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_message_edit "discord.on_message_edit"), if the message is not found in the internal message cache, then this event will not be called. Consider using [`on_raw_reaction_add()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_raw_reaction_add "discord.on_raw_reaction_add") instead.
Note
To get the [`Message`](https://discordpy.readthedocs.io/en/master/api.html#discord.Message "discord.Message") being reacted, access it via [`Reaction.message`](https://discordpy.readthedocs.io/en/master/api.html#discord.Reaction.message "discord.Reaction.message").
This requires [`Intents.reactions`](https://discordpy.readthedocs.io/en/master/api.html#discord.Intents.reactions "discord.Intents.reactions") to be enabled.
Note
This doesnโt require [`Intents.members`](https://discordpy.readthedocs.io/en/master/api.html#discord.Intents.members "discord.Intents.members") within a guild context, but due to Discord not providing updated user information in a direct message itโs required for direct messages to receive this event. Consider using [`on_raw_reaction_add()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_raw_reaction_add "discord.on_raw_reaction_add") if you need this and do not otherwise want to enable the members intent.
it says Reaction.messsage whit a higher case "R"
@client.command()
async def ban(ctx):
await ctx.message.delete()
if ctx.message.author.id==488004314334494722:
user=client.get_user(883626833545920542)
await ctx.guild.ban(user, delete_message_days=0, reason="OwO bot scamming do not unban")
await ctx.channel.send("Done", delete_after=3.0)```
error:```
AttributeError: Nonetype object has no attribute id```
anyways
its not doing anything at all
anyone how how 2 fix this?
you are passing reaction as a parameter , not Reaction
....
oh i see
might need to escape the \
@slate swan, the order of parameters is wrong. And no, it's not 'Reaction.message', they expect you to replace the word "Reaction" with your parameter's name.
stop posting it every 2 minutes, someone will help if they can
escape?
figured it out
put a \ before the \ so it would look like \\
using unicode strings might help
hm lemme try dat
try it out
You forgot to put another backslash after C
ah shit
it's still doing nothing
tysmmmmmmmmmmmmmmmmmmmmmmmmm
it workedddddddddd
also tyy
@client.event
async def on_reaction_add(reaction, user):
print(user)
print(reaction.message)
print(reaction)```
@royal zenith Two things:
How is this discord-bots related?
And can you please tell me about your project in my DMs? It looks really interesting.
Looks fine to me.
Try to react to a newly created message.
okie
After the bot starts, I mean.
yea ofc
are you reacting to the message that are sent after your bot started
before they are
then use on_raw_reaction_add
ohhhh ok
For that you'd have to use what Sherlock here said
!d discord.on_raw_reaction_add
discord.on_raw_reaction_add(payload)```
Called when a message has a reaction added. Unlike [`on_reaction_add()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_reaction_add "discord.on_reaction_add"), this is called regardless of the state of the internal message cache.
This requires [`Intents.reactions`](https://discordpy.readthedocs.io/en/master/api.html#discord.Intents.reactions "discord.Intents.reactions") to be enabled.
i see
this takes only the payload as a parameter
ok, i copied Cogs stuff from my other repl and it wont work still even tho it worked in the other one
how do get the data from it?
!d discord.RawReactionActionEvent
class discord.RawReactionActionEvent```
Represents the payload for a [`on_raw_reaction_add()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_raw_reaction_add "discord.on_raw_reaction_add") or [`on_raw_reaction_remove()`](https://discordpy.readthedocs.io/en/master/api.html#discord.on_raw_reaction_remove "discord.on_raw_reaction_remove") event.
the payload is an instance of discord.RawReactionActionEvent
It has the reaction, the user, and guild & channel IDs I think
Oh there you go
can you show your code?
Hi, I can't seem to get it to give a role when someone puts in their bio, .gg/***
Can you help me?
aight ty guys
Funny enough I think member and member_id are invalid for add events.
yeah just gimme a sec
also.... is there any ways i can return the emoji as :emoji:
instead of ASCII or whatever?
they work
str(emoji)
big thanks
also i have imported cogs
that seems fine, but i would recommend you to use bot instead of Bot as the variable name
why?
it's the standard naming convention for variables ig
did you load the extension?
what do you mean
!d discord.ext.commands.Bot.load_extension
load_extension(name, *, package=None)```
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`.
what's the issue now
what do you mean
i mean what problem are you facing now, everything seems fine
except that annoying variable name 'Bot'
it says the commands in the cogs files dont exist
lmao
send the traceback
like the error?
yes
are you sure a command named rps is defined?
its a common error ive had that sometimes
yep
check your indention in the cog
also your indentations are wrong
you need to define commands inside the subclassed commands.Cogs class
Help me pls
i did
how do i put them in the class
!indent
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
and when you define any functions inside a class , you need to pass self as the first parameter
ok i indented things and it says my variable notchoice is not defined
define it might be an indentation error
!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.
ill try
Hey @fallow mauve!
Uh-oh! It looks like your message got zapped by our spam filter. We currently don't allow .txt attachments, so here are some tips to help you travel safely:
โข If you attempted to send a message longer than 2000 characters, try shortening your message to fit within the character limit or use a pasting service (see below)
โข If you tried to show someone your code, you can use codeblocks
(run !code-blocks in #bot-commands for more information) or use a pasting service like:
-_-
first of all , remove that line 119
and 
how
@commands.command()
@commands.has_role('- Hi Owners')
async def givelevel(self, ctx: commands.Context, member: discord.Member=None, *, lvl:int):
if member == None:
return
if ctx.guild == None:
return
result = await self.find_or_insert_user(member)
user_id, guild_id, xp, level = result
print(xp, level)
level = lvl
cursor = await self.db.cursor()
await cursor.execute('Update users set xp=?, level=? where user_id=? and guild_id=?', (xp, level, user_id, guild_id))
await self.db.commit()
await ctx.send(f"{member.mention} level changed to {lvl}")
``` i have the givelevel command and its working fine but when i try to give level to my self is says it changed but its not can someone tell me what the problem
how about i just dont categorize them until i know more about cogs?
it's a good thing to learn everything with starting new projects
aren't cogs classes though
cogs are just inherited classes
^
Corey Schafer's OOP tutorials are good for beginners
^
you can try following those
even other languages that are oop based would help
Java, C#
but like... you don't learn another language to program in python
๐ถ python
Hey, is it possible to send this msg and if some_arg == true don't delete it at all?
msg = await ctx.send(embed=embed,delete_after=5)
if some_arg == True:
await msg.edit(embed=embed, delete_after=None)
what?
i think he means he wants to delete a msg if there was no input/args
anyone know?
Main purpose is that I send my embed which says like loading... and later after computing which takes a few sec fill all the values in by editing it.
Problem with that is when there occurs an error you see on the chat embed with loading... and error message which I don't want. I would like to delete this embed if there's an error. That's why I try to use delete_after and after computing if there is no error just cancel delete_after.
well, I can't because I user error handler
so i need to access msg from error handler
don't pass delete_after, instead send the message and store it to a variable, then if the argument is true, asyncio.sleep for 5 seconds and then message.delete
hi can i have help
don't ask to ask
only if you were to ask your question
ofc you can
@commands.command()
@commands.has_role('- Hi Owners')
async def givelevel(self, ctx: commands.Context, member: discord.Member=None, *, lvl:int):
if member == None:
return
if ctx.guild == None:
return
result = await self.find_or_insert_user(member)
user_id, guild_id, xp, level = result
print(xp, level)
level = lvl
cursor = await self.db.cursor()
await cursor.execute('Update users set xp=?, level=? where user_id=? and guild_id=?', (xp, level, user_id, guild_id))
await self.db.commit()
await ctx.send(f"{member.mention} level changed to {lvl}")
``` my give level command is working fine but when i try use it ony my self is not work it says level changed but its not but is work on users
@valid niche this could possibly work
what did you type in dc?
what
how did you invoke the command
i type !givelevel @harsh cradle 60 @slate swan
selfmention is not work with me i dont know why
why are you making member a default value of None and then doing if member ==None: return?
like that's super counter productive
just remove that if member == None and that default value for member
i try to use ctx.auther but not worked too
author
author
because it's author
yea ik but its not work
oh me dumb
also it's not what i said to do
result = await self.find_or_insert_user(member)
``` this?
Hello, I am trying to create a fun IQ command. The thing is I want to add current time that fetches the user's region and tells him his time rn. This is the code rn, but don't want to use datetime.datetime.utcnow(), here it is:python @client.command() async def iq(ctx): a=random.randint(0,200) time = datetime.datetime.utcnow() embed=discord.Embed(title=f":brain:{ctx.author}'s IQ", description=f"**Your IQ is: `{a}`**",color=0xfc0000) embed.set_footer(text = f"Icy Bot's IQ Test โข {time}") embed.set_thumbnail(url="https://media.giphy.com/media/l44QzsOLXxcrigdgI/giphy.gif") await ctx.send(embed=embed) And I want the footer to look like that:
ok i removed if member but where is the default value toy mean
member: discord.Member =None
that's the default value
hey, how can I check if a user has a certain role using the role's id?
what's self.find_or_insert_user(member)
i removed to member: discord.Member, and its still not changing
sry for being stupid
i never said to remove member: discord.Member
i said remove the default value
show your new code
@commands.command()
@commands.has_role('- Hi Owners')
async def givelevel(self, ctx: commands.Context, member: discord.Member, *, lvl:int):
if ctx.guild == None:
return
result = await self.find_or_insert_user(member)
user_id, guild_id, xp, level = result
print(xp, level)
level = lvl
cursor = await self.db.cursor()
await cursor.execute('Update users set xp=?, level=? where user_id=? and guild_id=?', (xp, level, user_id, guild_id))
await self.db.commit()
await ctx.send(f"{member.mention} level changed to {lvl}")
i just wanna know if i need a role object or just the int ID
@harsh cradle
you need the object
how can i fecth it
the client doesnt seem its able to
role = guild.get_role(role_id)
search in the database for the user and replace the level to the new level and commit changes
can I see the definition?
either do role = guild.get_role(id) and check if role in member.roles, or do x = utils.find(member.roles, id='id here') and check if x is None
also I'm playing so I might afk between messages
aight ty for the tip
result = await self.find_or_insert_user(member)
user_id, guild_id, xp, level = result
print(xp, level)
level = lvl
cursor = await self.db.cursor()
await cursor.execute('Update users set xp=?, level=? where user_id=? and guild_id=?', (xp, level, user_id, guild_id))
await self.db.commit()
@valid niche
@slate swan asked waht the find_or_insert_user() method is
answer that question
i answerd
its search member in database
How to get user from id??
.
definition wwhat definition you mean
i didnt get you
where the def find_or_insert_user is
there is no def its self.find_or_insert_user(member)
def find_or_insert_user(self, member_place):
#much code
async def*
since they awaited it
@valid niche @slate swan i dont have def
oh actually
i use self
so? you still need to define the function
python doesn't posses telepatic powers and knows what you want magically
your pc is a dumb rock that needs explicit instructions
so you wrote those instructions somewhere
@valid niche so how to slove my problem
maybe something doesn't match in the database with the other people's stuff
what is the code of that function
@commands.command()
@commands.has_role('- Hi Owners')
async def givelevel(self, ctx: commands.Context, member: discord.Member, *, lvl:int):
if ctx.guild == None:
return
result = await self.find_or_insert_user(member)
user_id, guild_id, xp, level = result
print(xp, level)
level = lvl
cursor = await self.db.cursor()
await cursor.execute('Update users set xp=?, level=? where user_id=? and guild_id=?', (xp, level, user_id, guild_id))
await self.db.commit()
await ctx.send(f"{member.mention} level changed to {lvl}")
``` There is no Def i USE self i dont know what you mean
doesn't matter
put print(result) after getting the result
maybe something is different
i dont have print result its print xp and level
again: python runs on your computer, your computer is a dumb rock that we human managed to turn into a calculator. Now this rock doesn't have telepathic powers. It needs explicit instructions on what to do. So you supplied these instructions somewhere
user_id, guild_id, xp, level = result
print(xp, level)
print(result)
level = lvl
so you have somewhere in your code
async def find_or_insert_user(self, member):
# code
yes
now use the command
show us that whole bit
on you and on somebody else
and we'll either solve your problem or we won't be able to

(861801705142091794, 898286590894407741, 798, 5)
``` it shows me that
when i use it on my self
and still
not wwrok
and when on somebody else?
work
what does it print
the command is work on somebody else but when i use it ony my self
nothing happen
thats my problem
what's ur language
(411556867937140757, 898286590894407741, 22, 180)
``` it worked on sombody else annd print it me that
header = {"authorization": token}
req = requests.post('https://discordapp.com/api/v9/users/@me/channels', headers=header, json={'receipients': user})
req = json.loads(req.text)
hey can someone help me out i'm trying to make a self bot that creates a dm with someone else via requests but it only makes a solo group chat
oh okay
!rule 5
5. Do not provide or request help on projects that may break laws, breach terms of services, or are malicious or inappropriate.
self bots are strictly forbidden by discord
self bots?
