#Basic Pycord Help (Quick Questions Only)
1 messages ยท Page 37 of 1
uninstalled any other python versions
and still getting the same error
this is where it fails idk why, it worked perfectly in pycord 2.2.2 so it shouldnt be a problem
try python3.11 bot.py
windows? do py3.11 bot.py
else you dont have python 3.11 installed or in PATH
do python --version to check the version
im so confused
if it is, ill lose my bet on 24hr no patch release after minor release ๐
lmao
bridge.AutoShardedBot
can you try .Bot?
interesting
add the full error traceback
๐
code idea to add the error as an image too cuz it is looking pretty fucked
๐
.
i use 2.4.0 and it seems to work for me ๐คทโโ๏ธ
show your pip list
aiohttp==3.8.3
aiosignal==1.2.0
astunparse==1.6.3
async-timeout==4.0.2
attrs==22.1.0
braceexpand==0.1.7
brotlipy==0.7.0
cchardet==2.1.7
cffi==1.15.1
charset-normalizer==2.1.1
click==8.1.3
colorama==0.4.6
dnspython==2.2.1
frozenlist==1.3.1
fuzzywuzzy==0.18.0
idna==3.4
import-expression==1.1.4
importlib-metadata==5.1.0
jishaku==2.5.1
line-profiler==4.0.1
multidict==6.0.2
orjson==3.8.0
py-cord==2.2.2
pycares==4.2.2
pycparser==2.21
pymongo==4.3.2
python-dotenv==0.21.0
pytz==2022.5
six==1.16.0
typing_extensions==4.4.0
yarl==1.8.1
zipp==3.10.0```
Does someone have a clue why my Bot isnt able to respond to Slash commands? #Py-cord 2.0.0
await ctx.channel.send(file=discord.File(Pfad + sep + Image[r])) --> works, but is not counted as Responds for the Slashcommand
await ctx.send_response(file=discord.File(Pfad + sep + Image[r])) --> 404 Not Found (error code: 10062): Unknown interaction
what?
show the pip list and use ctx.respond()
upgrade to the latest version first
await ctx.respond(file=discord.File(Pfad + sep + Image[r]))
raises
"discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: NotFound: 404 Not Found (error code: 10062): Unknown interaction"
did you update pycord to v2.3.0 ?
-illow 7.1.2
absl-py 0.11.0
aiohttp 3.6.3
asgiref 3.3.0
astunparse 1.6.3
async-timeout 3.0.1
attrs 20.2.0
beautifulsoup4 4.10.0
cachetools 4.1.1
certifi 2020.6.20
chardet 3.0.4
charset-normalizer 2.0.12
clipboard 0.0.4
configparser 5.2.0
cycler 0.10.0
dataclasses 0.6
dblpy 0.4.0
dbots 3.0.0
Django 3.1.2
flatbuffers 1.12
future 0.18.2
gast 0.3.3
google-auth 1.23.0
google-auth-oauthlib 0.4.2
google-pasta 0.2.0
grpcio 1.32.0
h5py 2.10.0
html5lib 1.1
idna 2.10
image 1.5.33
Keras 2.4.3
Keras-Preprocessing 1.1.2
kiwisolver 1.2.0
Markdown 3.3.3
matplotlib 3.3.2
mechanize 0.4.7
MouseInfo 0.1.3
multidict 4.7.6
numpy 1.20.2
oauthlib 3.1.0
opencv-python 4.5.2.52
opt-einsum 3.3.0
Pillow 8.1.2
pip 21.0.1
protobuf 3.13.0
psutil 5.8.0
py-cord 2.0.0rc1
pyasn1 0.4.8
pyasn1-modules 0.2.8
PyAutoGUI 0.9.53
PyGetWindow 0.0.9
PyMsgBox 1.0.9
pyparsing 3.0.0a1
pyperclip 1.8.2
PyRect 0.2.0
PyScreeze 0.1.28
python-dateutil 2.8.1
pytube 11.0.1
pytweening 1.0.4
pytz 2020.1
PyYAML 5.3.1
ratelimiter 1.2.0.post0
requests 2.27.1
requests-oauthlib 1.3.0
rsa 4.6
scipy 1.5.4
setuptools 50.3.2
six 1.15.0
soupsieve 2.3.1
sqlparse 0.4.1
tensorboard 2.4.0
tensorboard-plugin-wit 1.7.0
tensorflow 2.4.0
tensorflow-estimator 2.4.0rc0
termcolor 1.1.0
torch 1.7.1
torchaudio 0.7.0
torchvision 0.8.1+cpu
twitchio 1.1.0
typing-extensions 3.7.4.3
urllib3 1.26.8
watchdog 2.1.6
webencodings 0.5.1
websockets 9.0.1
Werkzeug 1.0.1
wheel 0.36.0
wrapt 1.12.1
yarl 1.5.1
zope.interface 5.1.2
upgrade py-cord
as i said
that is a really old version
that was the first that worked^^
i feel like the API changed like the API Reference page
not happy with the new design of the Page. I cant find the things i need without the search tool
there is search tho-
i know there is a search. and thats the ONLY way i can find stuff....and thats why i hate it....i dont want to type it into the Search....Anyway...i think that the API was able to respond to the Command even with 2.0.0rc
Why isnt this code creating a thread on the latest message in the channel?
async def thread(self,ctx):
ApplicationsChannel = self.bot.get_channel(int(1028037205849014342))
message = await ApplicationsChannel.fetch_message(
ApplicationsChannel.last_message_id)
await message.create_thread(name="Discuss Application Here", auto_archive_duration=10080, reason=None,message="Lets start discussing this application", type=discord.ChannelType.public_thread)```
Im doing it based off the docs, as its my first time doing threads in pycord
Any traceback ? @fervent cradle
Nope no error
does the bot have the permission to create threads ? @fervent cradle
Im pretty sure its got admin, since its my test server
await message.create_thread ?
pretty sure it's ctx ?
Oh ill try that, (I didnt know since i was tryna make it using docs)
Okay!
await ctx.message.create_thread(name="Discuss Application Here", auto_archive_duration=10080, reason=None,message="Lets start discussing this application", type=discord.ChannelType.public_thread)
``` Hasnt fixed it
Its creating the thread from the latest message in the channel tho, and thats what message gets
Oh yeah True
I really don't know where's the issue, sorry. Wait for someone more experimented to help you!
Okay thanks
You are passing invalid arguments I believe.
https://docs.pycord.dev/en/stable/api/models.html#discord.Message.create_thread
I believe this is the method you are utilizing?
https://guide.pycord.dev/popular-topics/threads im using this
Threads with Pycord
Oh, well discord.Message.create_thread applies only two parameters.
You should be utilizing the discord.TextChannel.create_thread, so use the channel obtained to create the thread with the message passed in.
And I believe the TextChannel one is the one you want.
For more reference here's the docs for it:
https://docs.pycord.dev/en/stable/api/models.html#discord.TextChannel.create_thread
You most likely mixed up the channel one with the message one.
ApplicationsChannel = self.bot.get_channel(int(1028037205849014342))
message = await ApplicationsChannel.fetch_message(
ApplicationsChannel.last_message_id)
await discord.TextChannel.create_public_threads(name="Discuss Application Here", auto_archive_duration=10080, reason=None,message="Lets start discussing this application", type=discord.ChannelType.public_thread)``` Hasnt fixed it and i've looked at docs you sent, whats wrong ?
discord.TextChannel is a class, not an object
Do you have a global error handler? If you do, disable it for now. And print message to see what it gives you. Also that is not how you use discord.TextChannel
you need an instance of the class, not the class itself
Alright
Dosent print anything
What?
is ApplicationsChannel a valid channel?
Then your command isn't even running..
Its getting the channel by the ID
yeah, but does your bot have intents/permissions to view it
Yeah
.
import discord
from discord.ext import commands
import aiohttp
class thread(commands.Cog):
def __init__(self, bot):
self.bot = bot
async def thread(self,ctx):
ApplicationsChannel = self.bot.get_channel(int(1028037205849014342))
message = await ApplicationsChannel.fetch_message(
ApplicationsChannel.last_message_id)
await discord.TextChannel.create_public_threads(name="Discuss Application Here", auto_archive_duration=10080, reason=None,message="Lets start discussing this application", type=discord.ChannelType.public_thread)
print(message)
def setup(bot):
bot.add_cog(thread(bot))``` Its not a command its just checking for it
?
Then why are you passing ctx? And how are yo calling that function if it's not a command?
shi forgot to call it, would i use a cog listener?
A listener for what? What are you even trying to do?
Once a message is sent in a channel, create a thread on it
Then use the on_message event
Am i able to specficy if the message is from a specfic person using on message? (I thought of that at first but i didnt think id be able to check)
Yes, of course you can.
Yeah, why wouldn't you? Just compare the author to a predefined user object
or id
im really not being smart today haha
async def on_message(message):
ApplicationsChannel = self.bot.get_channel(int(1028037205849014342))
await ApplicationsChannel.create_thread(name="Yes", auto_archive_duration=10080)```, I know this is wrong but im unsure of what? I tried ApplicationsChannel.message.create_thread
what is message.get_id ?
ignore that, i added that to test smth
is this in a cog?
It is
bot.eventdoesn't work in a cog- missing
self
Would i need to use a cog listener? I couldnt find docs on it (and tried /example)
Oh found some docs
yay
@commands.Cog.listener()
async def on_message(self,message):
ApplicationsChannel = self.bot.get_channel(int(1028037205849014342))
await ApplicationsChannel.create_thread(name="Yes", auto_archive_duration=10080)``` Gotten this far, do i need to add message somewhere?
any way to add this but with a function?
should be good enough
Isnt creating a thread though
you can subclass discord.ui.Select and create your options dynamically in the constructor.
are there any errors and disable any error handlers.
?tag install
- Uninstall discord.py or any other forks of discord.py you might have with the namespace
discord.
python -m pip uninstall discord.py discord -y
2a. Install py-cord
python -m pip install py-cord
2b. Update py-cord
python pip install -U py-cord
Installing other builds:
Note: You need to have git installed. Use ?tag git to find out how to install git.
Updating the module to master branch (unstable):
pip install -U git+https://github.com/Pycord-Development/pycord
^
bro beat me to it
if they already did, then restart terminal/IDE
Only handlers is checking for missing param or command cooldown
what does the handler do if it isn't one of them?
huh
Those are my only 2 handlers
could you show code for it?
import os
import pymongo
from dotenv import load_dotenv
load_dotenv()
from discord.ext import commands
bot = discord.ext.commands.Bot(intents = discord.Intents.all(),command_prefix='f!', activity = discord.Activity(type=discord.ActivityType.playing, name="BennixMC"))
@bot.event
async def on_ready():
print('I am online')
@bot.event
async def on_application_command_error(ctx, error):
if isinstance(error, commands.CommandOnCooldown):
await ctx.respond(f'This command is on cooldown, Try again in {round(error.retry_after)} seconds')
WrongParam = discord.Embed(title="Missing Argument", description="Missing Argument in this command, you can use /help to find the information on this command.",color=discord.Color.blue())
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, discord.ext.commands.MissingRequiredArgument):
await ctx.send(embed = WrongParam, )
directories = ["Fun commands", "Utility Commands", "Other"]
for directory in directories:
for filename in os.listdir(directory):
if filename.endswith(".py"):
bot.load_extension(f"{directory}.{filename[:-3]}")
bot.run(os.getenv("TOKEN"))``` (might be slightly outdated code but for the 2nd handler)
?
python was not found
You can try using py instead of python, same happens to me
lmao, also happens to me i created a python venv, then pip worked in there
Its also really useful to seperate your pip installations
@silver moat ?
or to skip venv, just use py -m pip install -U git+https://github.com/Pycord-Development/pycord
Install git
?tag git
No tag git found.
?tag install0git
No tag install0git found.
?tag install-git
No tag install-git found.
?tag install_git
first try
lmao
Do you know what was happening with my bot?
could you print(ApplicationsChannel)?
Ill try now
well
- It must have worked before but the thread is pravite and has no one but bots in it
- didnt print anything
i assume the reason it also didnt send anything like thread created (yk the msg it normaly sends) is cuz its prv
I lost your thread code, could you send it again or link it?
Ill send it
import discord
from discord.ext import commands
import aiohttp
class thread(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_message(self,message):
ApplicationsChannel = self.bot.get_channel(int(1028037205849014342))
await ApplicationsChannel.create_thread(name="Discuss Application", auto_archive_duration=10080)
print(ApplicationsChannel)
def setup(bot):
bot.add_cog(thread(bot))``` full file
oh the event listener isn't inline with the constructor
Oh should i unindent it ?
yea
Done, what can i do to make it a public thread?
Its in the error, I had this, just install microsoft 11 build tools
The link is further up in your error
nah at top of ur ss
Install it (may take a bit)
bros getting every error i had a bit ago
@silver moat (ty btw)
It should be attached to a message
It isnt, Thats why im confused
Its in the correct channel, but its also a pravite thread
It should be public
async def on_message(self,message):
ApplicationsChannel = self.bot.get_channel(int(1028037205849014342))
await ApplicationsChannel.create_public_thread(name="Discuss Application", auto_archive_duration=10080)
print(ApplicationsChannel)```
AttributeError: 'TextChannel' object has no attribute 'create_public_thread'
use
await message.create_thread(...)
Then it wont know the correct channel?
all messages know what channels they are in
Yeah but i want it to be only created in one channel
then check if the message is in the channel, and then create the thread.
Okay
async def on_message(self,message):
ApplicationsChannel = self.bot.get_channel(int(1045366009009283174))
if message in 1045366009009283174:
await message.create_thread(name="Discuss Application", auto_archive_duration=10080)
Would this be correct if statment?
uhhh no. It should be message.channel.id
Im having another issue, but i see whats happening but cant fix it, Im using zapier to send google forum response to discord, its sending it as a webhook (I think) so it isnt creating the thread
I want to make a command that saves all the users current roles or role_ids in a file for later use, does anyone know how to do this?
Basic python, Just get the role names then write to file
Is it even possible if its sending it through webhook?
Don't use files for storing data. Use a database
?tag nojson
Why not to use json files for data storage
JSON files are commonly used to store data that is read by a program, however, they are unsuitable for storing dynamic data due to a number of reasons.
It is recommended to use a DBMS (Database Management System) as they come with optimized technologies for storing and retrieving information.
Advantages of using a database:
- Database tables can be related, making it easy to separate your information into multiple tables and only fetch what you need
- Databases allow you to use a query/data processing language to make complex data operations easier with less code
- One misplaced character will corrupt an entire file. A database very rarely experiences corruptions due to their automatic handling of data integrity
- Transactions in SQL databases allow you to revert unwanted changes and prevent data corruption in the case of an error
- Databases have support for indexes, allowing retrieval of some data to be extremely fast
- It is very easy to update existing data in a database, as opposed to re-writing a file
- Databases are reliable
Popular database management systems:
- SQLite3 (File based, no need for a server setup, SQLite is the most used database engine in the world)
- MongoDB (Stores data in documents a similar manner to JSON format, easy for beginners)
- PostgreSQL (Very popular and robust SQL based database management system)
- MySQL (Another popular SQL based system, good start for learning SQL)
i tried using it with databases, but i dont know how to store multiple role_ids into one database thingy
That's very easily done in almost any database. Just have a table with the user ID as a primary key and an array of role IDs as another column
the limit discord.ui.select(
options = []
)
is 25??
Yes

It's a Discord limitation, nothing to do about it
Its small amounts of data dosent matter
That is not an excuse for doing bad practices, do it right from the beginning
so like this (sqlite):
async with aiosqlite.connect("databases/user_roles.db") as db:
await db.execute(
"""
CREATE TABLE IF NOT EXISTS users (
user_id INTEGER,
role_id INTEGER,
PRIMARY KEY (user_id, role_id)
)
"""
)
Thats true
No, your role_id column needs to be an array of integers
Have you got any idea here? Just need to allow it to work w webhook
and you can not make two columns a primary key
spaxter
sry but been workin on it for hours
wouldn't string be safer?
I guess arguably it would, but that would also require parsing it whenever you retrieve it
how do i make an array ._.
actually SQLite doesn't seem to have support for Arrays
Could do a multicolumn index, of course
idk how big you are going on this database thing, but what i would have is-
1 user table with all the stuff i want to store for it
1 role table with all the stuff ill store for it
and another table that as 1 foreign key in users and another foreign key in roles
this should be the most sql way to do it
This would be the most proper way, yeah 
oh please use something better than sqlite
so should i use mysql or something
Use whatever you think suits you best
have you considered non-sql databases
what would you recommend for beginners?
postgres..
Probably MongoDB or Postgres
mongo
Anyone?
MongoDB>>>
mhm. cuz one of the key rule of sql is never to store more collections of data (like a list) in a single entry
Clarify?
Depends on your use case, Mongo is easier but Postgres will scale better for large amounts of data
if someone knew they would have helped yk
whats zapier
huh? Im just trying to make it work with webhook (I put the id in)
Google it, its rly useful (and trusted)
I don't think anyone understands what your issue is
does zapier send the webhook into the thread?
Its sending the webhook into the channel, it SHOULD make a thread but because it ISNT a normal message, it isnt creating a thread
can you explain what you are trying to actually achieve and then how you are trying to achieve it?
@commands.Cog.listener()
async def on_message(self,message):
ApplicationsChannel = self.bot.get_channel(int(1045782142489210985))
if message.channel.id == 1045782142489210985:
await message.create_thread(name="Discuss Application", auto_archive_duration=10080)
The ID is the webhook id ^
do webhook messages trigger the on message event?
it's not a system message so I don't see a problem
Nope, It isnt triggering the event (or isnt triggering the create thread line),
hm
let me get this straight. A webhook sends messages in a channel and you want to attach a thread to that message, right?
isnt that a channel id?
seems so
.rtfm discord.Message.webhook_id
Target not found, try again and make sure to check your spelling.
.rtfm discord.message.webhook_id
Target not found, try again and make sure to check your spelling.
attributes don't exist
nvm its this thing https://docs.pycord.dev/en/stable/api/models.html#discord.Message.webhook_id
It has 2 IDS (and just updated both)
Looking now
i still see only 1 id
in this
first ID = channel id
second ID = webhook id
async def on_message(self,message):
ApplicationsChannel = self.bot.get_channel(int(11045366009009283174))
if message.channel.id == 1045793294891896953:
await message.create_thread(name="Discuss Application", auto_archive_duration=10080)```
ah
arent webhooks restricted to a single channel?
are you compared the channel id to a webhook id?
also you never seem to use ApplicationsChannel
Should i take that code outside of a variable?
if you code use it then just remove it
The code needs changed a bit, as i just relieased its webhook its sent not message
[AFK] just a squid is AFK: No reason specified.
o rip
@commands.Cog.listener()
async def on_message(self,message):
ApplicationsChannel = self.bot.get_channel(int(11045366009009283174))
if message.channel.id == 1045793294891896953:
await message.create_thread(name="Discuss Application", auto_archive_duration=10080)
so what needs changed? im confused now lmao
What is ApplicationsChannel for
remove ApplicationsChannel line
and then instead of message.channel.id put message.webhook_id
๐
i hope 1045793294891896953 is the webhook id
Would on message event not work for webhooks though?
it should work
okay
async def on_message(self,message):
self.bot.get_channel(int(11045366009009283174))
if message.webhook_id == 1045793294891896953:
await message.create_thread(name="Discuss Application", auto_archive_duration=10080)``` this correct?
i said remove the entire line
misread (lmao)
happens
Still isnt creating a thread, No errors either
import discord
from discord.ext import commands
import aiohttp
class thread(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_message(self,message):
if message.webhook_id == 1045793294891896953:
await message.create_thread(name="Discuss Application", auto_archive_duration=10080)
def setup(bot):
bot.add_cog(thread(bot))```
full file
@proud mason
add a print statement before checking the webhook id
Done, will see if it prints
Its got all intents, also admin
It didnt print anything
Yeah
also i hope you are running the bot ๐
I had this working with normal messages, cant seem to have it working with webhooks
๐คฃ yes dw
hmm
but if i need to use commands.bot, thats fine
Is this needed?
other than what i already done
for the if statment
i mean how else would you check the webhook id
I put a print directly above the cog listener, and it works so its seeing the file
yea tru
where did you add the print statement? did you try sending a normal message?
Normal, or webhook dosent aciivate the print
hmm smth wrong with the cog ig
try adding a on message event listener in the main.py file, and printing there
i had also once long ago read an issue where if you had no commands in the cog then it would act up weird
import discord
import os
import pymongo
from dotenv import load_dotenv
load_dotenv()
from discord.ext import commands
bot = discord.ext.commands.Bot(intents = discord.Intents.all(),command_prefix='f!', activity = discord.Activity(type=discord.ActivityType.playing, name="BennixMC"))
@bot.event
async def on_ready():
print('I am online')
@bot.event
async def on_application_command_error(ctx, error):
if isinstance(error, commands.CommandOnCooldown):
await ctx.respond(f'This command is on cooldown, Try again in {round(error.retry_after)} seconds')
WrongParam = discord.Embed(title="Missing Argument", description="Missing Argument in this command, you can use /help to find the information on this command.",color=discord.Color.blue())
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, discord.ext.commands.MissingRequiredArgument):
await ctx.send(embed = WrongParam, )
@commands.Cog.listener()
async def on_message(self,message):
print("test")
if message.webhook_id == 1045793294891896953:
await message.create_thread(name="Discuss Application", auto_archive_duration=10080)
directories = ["Fun commands", "Utility Commands", "Other"]
for directory in directories:
for filename in os.listdir(directory):
if filename.endswith(".py"):
bot.load_extension(f"{directory}.{filename[:-3]}")
bot.run(os.getenv("TOKEN"))``` Its in it, and no work
P sure you need to fetch the channel?
?tag fetch
No tag fetch found.
?tag fetch_channel
No tag fetch_channel found.
f gimme a sec
@proud mason
not like that ๐
put it like how you put the other events
i gtg now
Oh, as a bot event?
yeah
Traceback (most recent call last):
File "C:\Users\Wacky\Documents\FoolishBot\main.py", line 23, in <module>
@bot.event()
^^^^^^^^^^^
TypeError: Client.event() missing 1 required positional argument: 'coro'
dont put ()
ApplicationsChannel = self.bot.get_channel(int(1045782142489210985))
could do smth like this mby
a number is already an integer tho
Tru lmao
It dosent print it
before the if
Im so confused, this should be working
Should i create a new thread
@proud mason
#1045802687465279550
Does anyone have an example of configuring overwrites with the overwrites= parameter when using create_voicechannel?
inside bot.run... lol
https://github.com/Pycord-Development/pycord/blob/master/discord/client.py#L695
Pycord, a maintained fork of discord.py, is a python wrapper for the Discord API - pycord/client.py at master ยท Pycord-Development/pycord
discord/client.py line 695
await self.start(*args, **kwargs)```
yeah, fair, that's what i did but i had weird thing
fixed tho
bot wasn't really starting when i tried to use new_event_loop instead of get_event_loop (it threw warnings at me)
but i just used get_event_loop_policy().get_event_loop() instead and it worked w/o any warnings and/or errors

Hey does anyone know why my paginator send sometimes says unknown interaction, I've asked about this issue before and I was told to not worry about since in my testing it was only happening when I started my bot and it probably wasn't ready yet. After having the bot live for a bit I've seen it happen multiple times seemingly randomly, I would like to know if anyone here has any idea whats going on. Traceback is below
Task exception was never retrieved
future: <Task finished name='discord-ui-view-dispatch-48f2cb87f3c73677fa6d1936ef63266d' coro=<View._scheduled_task() done, defined at /pufferpanel/.local/lib/python3.11/site-packages/discord/ui/view.py:405> exception=AttributeError("'Select' object has no attribute 'select_type'")>
Traceback (most recent call last):
File "/pufferpanel/cogs/AppMenu.py", line 75, in select_category
await paginator.respond(interaction, ephemeral=True, target=interaction.user, target_message="Please check your DMs!")
File "/pufferpanel/.local/lib/python3.11/site-packages/discord/ext/pages/pagination.py", line 1160, in respond
await interaction.response.send_message(
File "/pufferpanel/.local/lib/python3.11/site-packages/discord/interactions.py", line 825, in send_message
await self._locked_response(
File "/pufferpanel/.local/lib/python3.11/site-packages/discord/interactions.py", line 1090, in _locked_response
await coro
File "/pufferpanel/.local/lib/python3.11/site-packages/discord/webhook/async_.py", line 215, in request
raise NotFound(response, data)
discord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interaction
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/pufferpanel/cogs/AppMenu.py", line 78, in select_category
await interaction.response.edit_message(content="An unknown error occurred, error has been sent to developer.", delete_after=10)
File "/pufferpanel/.local/lib/python3.11/site-packages/discord/interactions.py", line 961, in edit_message
await self._locked_response(
File "/pufferpanel/.local/lib/python3.11/site-packages/discord/interactions.py", line 1090, in _locked_response
await coro
File "/pufferpanel/.local/lib/python3.11/site-packages/discord/webhook/async_.py", line 215, in request
raise NotFound(response, data)
discord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interaction
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/pufferpanel/.local/lib/python3.11/site-packages/discord/ui/view.py", line 414, in _scheduled_task
await item.callback(interaction)
File "/pufferpanel/cogs/AppMenu.py", line 86, in select_category
await interaction.response.edit_message(content="Failed to get apps", delete_after=10)
File "/pufferpanel/.local/lib/python3.11/site-packages/discord/interactions.py", line 961, in edit_message
await self._locked_response(
File "/pufferpanel/.local/lib/python3.11/site-packages/discord/interactions.py", line 1090, in _locked_response
await coro
File "/pufferpanel/.local/lib/python3.11/site-packages/discord/webhook/async_.py", line 215, in request
raise NotFound(response, data)
discord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interaction
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/pufferpanel/.local/lib/python3.11/site-packages/discord/ui/view.py", line 416, in _scheduled_task
return await self.on_error(e, item, interaction)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/pufferpanel/.local/lib/python3.11/site-packages/discord/ui/view.py", line 400, in on_error
print(f"Ignoring exception in view {self} for item {item}:", file=sys.stderr)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/pufferpanel/.local/lib/python3.11/site-packages/discord/ui/item.py", line 93, in __repr__
attrs = " ".join(
^^^^^^^^^
File "/pufferpanel/.local/lib/python3.11/site-packages/discord/ui/item.py", line 94, in <genexpr>
f"{key}={getattr(self, key)!r}" for key in self.__item_repr_attributes__
^^^^^^^^^^^^^^^^^^
AttributeError: 'Select' object has no attribute 'select_type'```
How do I check if a command is being run by someone? I'm using the max_concurrency decorator on a slash command to prevent it from being run by more than one user at a time, and I'm getting the issue that while catching the MaxConcurrencyReached error, I'm unable to process the second person's command after the first one is done. I cannot use the wait kwarg on the max_concurrency decorator since I get an application didn't respond error since the response wasn't deferred.
Nvm figured out how to do it, I had to look at the internals of the lib for a bit. I basically had to do this in the error handler for the MaxConcurrencyReached error that is thrown when two people run a command:
await ctx.defer() # Defer the response to prevent an "Application did not respond" error
while True:
try:
await ctx.command._max_concurrency.acquire(ctx)
except commands.MaxConcurrencyReached:
await asyncio.sleep(0.1)
else:
break
await ctx.invoke(ctx.command, *[option['value'] for option in ctx.selected_options]) # Rerun the command
Lmao how
Yeah because you aren't supposed to create a new loop. In Py3.10 and later, it's recommended to use asyncio.run, which creates the loop for you. You get the loop with get_event_loop like you did
oh well, i guess that stackoverflow thread was 10 yrs old
๐
Quick question. I moved to pycord from discordpy. I am trying to rewrite a piece of code that parses the message that was sent. How do I get the command text from the ctx data?
Like /slash "I need this text to parse"
hey anyone know why my on_guild_join event randomly stopped working? the bot has intents and i believe they are enabled in the code
It would be something like this:
async def slash(ctx, text: str)
Ah ok! I'll give this a shot tomorrow. Appreciate!
How do i get voice attribute with interaction
ok i just found out lol, it's interaction.guild.voice_client
how do I listen for a ping
there has to be an event for that, right
I don't want to listen to every message though
and use an if statement
that would overwork the bot
idk
no
It won't
lol.
do I just do
@bot.event
async def on_message(ctx):
if ctx.content.find("<@(bot user id)>"):
ctx.respond("I'm here")
oh wait
obviously I forgot an if statement
yes
use message and message.channel.send
find?
as in swapping ctx for message
I'm a newbie
yeah
If you're new to Python you should not be developing a Discord bot
but you know basic python?
read rule 1 in #help-rules
I'm not
new to python
I just kinda got that off my mind
you can look for something in a string
so if someone sends "blah blah blah (@mention)"
it'll still respond
maybe I shouldn't add that
You can just use the in operator for that
It wouldn't work, because find returns -1 if it doesn't find anything
which would be parsed to True in your statement
https://guide.pycord.dev/introduction @tender seal
Pycord Guide is a complete guide for Pycord. Learn how to create Discord Bots today!
RuntimeWarning: coroutine 'Messageable.send' was never awaited
msg.channel.send("I'm here!")
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
I'm a pycord newbie
bruh my mind is really working at 1% capacity
what does this garbage mean though
never got it before
do you know asyncio?
never had to import it, why
You need to know how to work with coroutines and async-await before developing a bot
you dont have to import it
Yeah, reading the error message is usually helpful
I need help removing "discord.py 2.0.0" its overriding my pycord.
?tag install
- Uninstall discord.py or any other forks of discord.py you might have with the namespace
discord.
python -m pip uninstall discord.py discord -y
2a. Install py-cord
python -m pip install py-cord
2b. Update py-cord
python pip install -U py-cord
Installing other builds:
Note: You need to have git installed. Use ?tag git to find out how to install git.
Updating the module to master branch (unstable):
pip install -U git+https://github.com/Pycord-Development/pycord
Thank you โค๏ธ
What?
instead of showing up as plain text
Use an embed just like you would in a normal message
you can click it, and it'll insert the command into your message field
I mean something like
Did you mean to use /admin rmbnt
but you can click the slash command
do you get what I mean?
I saw this somewhere...
Look at the github examples
what
oh.
Because you copy-pasted and forgot the change your if statement
Can you only allow autofilled choices on a slash command? Like prevent them from typin their own or not?
no but you can use choices=[] or autocomplete
Whats the difference between choices and autocomplete?
Oh nvm, choices is what I wanted, it does what I asked about :P thanks dude
yeah
and how exactly would I do that
.rtfm view.disable_all_items
Target not found, try again and make sure to check your spelling.
oo
hmm clear_items()
That will remove it
You call in the button callback
And then do interaction.message.edit(view=self)
just
where do I put the function
oh
well, I tried self.disable_all_items() before the callback and it did nothing
In both functions below interaction.response.send_message
How do i add multiple roles to a user by role id
You have the ids in a list?
yes
for loop
.rtfm user.add_role
Target not found, try again and make sure to check your spelling.
member
.rtfm member.add_role
Target not found, try again and make sure to check your spelling.
oh
.rtfm member
Target not found, try again and make sure to check your spelling.
With choices you have a limit of 25
Bruh wtf
.rtfm member.add_roles
Target not found, try again and make sure to check your spelling.
they're still there
Ok so
Create discord.Object(id) by iterating through your list using list comprehension. Then pass this list to this function
https://docs.pycord.dev/en/stable/api/models.html#discord.Member.add_roles
and clickable
Best way to do it
Show updated code
Yeah thats fine
was I supposed to
Yeah
oh so it doesn't happen instantly?
nah
@proud mason So I've got this code
it's working
I want to put in some stuff in the string
that's outside of the scope
so I wanna say f"Successfully cleared all {bnt} BNT {bnt_emoji} from {user.name}"
but I can't really do that
cuz it'll throw an error
i'll try figuring something out but still
waiting for help
okay how do I do it.
Where is bnt and emoji definited
so, in my slash command
{bnt} is the amount of tokens you wanna remove
the slash command works but
I wanna make the reply
show the amount of bnt
but because bnt is not defined in the class, how do I do that
Pass it as a parameter to your init function and set it as an attribute of self in the class
Do you know how to pass a parameter to a class?
haven't done much with classes
Then learn OOP in Python
Not at all
yeah
wait
so this is the code for displaying the buttons
I have a "learn while playing the game" approach with things
I look up tutorials and ask people questions
and sometimes deal with problems myself
okay I looked that up on StackOverflow ๐
I'll try that.
at least I was going in the right direction
Can you use the add_roles thing with a list?
Does it say you can in the docs?
I know that to make it next to each other I have to use "True" but I can't make the 3rd field below it using "false"
i accept sugerences
setting inline=True means that the next field will be placed next to it, it does not affect the current one
ok so I did
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: TypeError: ConfirmationView.__init__() missing 1 required positional argument: 'user'
now
I tried putting in the user
awaiting the init
I've tried a lot of stuff and I don't know what to do
once again, I ask for your help
I also tried async def __init__
just gave another error
Why are you trying to await the init?
AttributeError: 'NoneType' object has no attribute 'created_at'
<t:{round(memberr.created_at.timestamp())}:R>
memberr: discord.Member
can anyone help me please?;/
Very late but
Copy the slash command's id (attachment below) then use this as template </name:id> for ex. </help:1030780665303679077>
Don't forgot super().__init__() at the end of your init
Good idea to create the view outside of the msg.respond call
And then pass it
Okay, so maybe I am dumb, but does anyone have an example of a working webhook integrations with pycord?
Also, what info am I supposed to put in the brackets of discord.Webhook() for the data and session? Is there any way to easily allow my bot to make a webhook link and connect itself to the webhook?
AttributeError: 'NoneType' object has no attribute 'created_at'
<t:{round(memberr.created_at.timestamp())}:R>
memberr: discord.Member
can anyone help me please?;/
Sorry but what's webhook integration
Also you don't create the webhook object yourself. You use methods to do it
what does that do
Read the error? memberr is None
The error explains it all
I think I used integration inappropriately, but the command/event I am making is an on message which will send a webhook as a response (just for the use of a username and profile picture swap)
Well you are subclassing. If you override the init then you should first init the super class (the class you subclassed from)
You need to initialize your superclass, read up on how subclassing works. And once again, learn how OOP in Python works
ok
use memberr = bot.get_user(id)
And follow it up with the rest of your code
get_user only gets users that are cached and can return None, use fetch_user to get a user from the API
You're probably running multiple instances
You mean use both at the same time?
No, you can only use one of them but choices have a limit of 25 what autocomplete not have
How can I use slashcommandgroups in cogs?
the same like if you are not in a cog?
Here's the slash cog groups example.
Sure thanks
With specifying the member or without?
But it will return right ans it wont go further
use Option for the slash command
Then it wont respond with anything
user: Option(discord.Member, required=False)
Or decorator
so, i'm trying to migrate my legacy commands discord.py bot to a slash commands py-cord bot, it's going well. all commands work thus far, but they spit out the error "the application did not respond in" in an ephemeral message.
Are you responding to the commands?
is this considered a response?
@commands.slash_command(name="ping", guild_ids=[guild_id], description="Pong!")
async def ping(self, ctx):
await ctx.send(f'Pong! That took {(round(self.bot.latency*1000, 1))}ms')```
No, use ctx.respond
gotcha
.rtfm discord.InteractionResponse.send_message
Add a check inside of the button callback
you got attributes on it?
i have to add them manually but yes
.rtfm discord.User.color
.rtfm discord.User
discord.UserCommand
discord.User
discord.User.accent_color
discord.User.accent_colour
discord.User.avatar
discord.User.banner
discord.User.bot
discord.User.color
discord.User.colour
discord.User.created_at
discord.User.default_avatar
discord.User.discriminator
discord.User.display_avatar
discord.User.display_name
discord.User.dm_channel
discord.User.id
discord.User.jump_url
discord.User.mention
discord.User.mutual_guilds
discord.User.name
#883236900171816970
oh
why is it that even there is a reaction(s), the len(react_message.reactions) is always 0
reaction intents, perhaps?
I set the bot to have all intents
oh I think you are accessing a stale instance of the message
you have the old object
yea this
fetch the original_response again after adding reaction
yeah you have to fetch the message again to get the updated reaction data.
@bot.slash_command(name = "test", description = "test")
async def test(ctx):
react_interaction = await ctx.respond(f"a")
react_message = await react_interaction.original_response()
await react_message.add_reaction(reaction)
await asyncio.sleep(5)
react_message2 = await react_interaction.original_response()
print(len(react_message2.reactions))
print(react_message.content)
Could I ask what is wrong here, still says 0
oh wait
.rtdm interactionresponse.original_response
.rtfm interactionresponse.original_response
Target not found, try again and make sure to check your spelling.
OH, that makes sense
So I'd have to get the message Id of the message and update from there, right?
try react_message.channel.fetch_message(react_message.id)
for the after adding the reaction
await it
yea ofc
how can a bot ever need this? https://docs.pycord.dev/en/stable/api/data_classes.html#discord.MessageFlags.ephemeral
bots dont get ephemeral msgs ๐
or is it for when you do interaction.original_response()
it's own ephemeral messages
Thanks!
does someone know how the members are arranged when getting the member list of a voice channel? it is not mentioned in the docs https://docs.pycord.dev/en/stable/api/models.html#discord.VoiceChannel.members
however discord dispatches them
it would be convenient for me to have them in join order
anyone know whats wrong with this? (the no buttons doesnt work) ```async def ban(ctx, member:discord.Member, *, reason=None):
view = View()
yesbutton = Button(label="yes",emoji="โ
",style=discord.ButtonStyle.green)
nobutton = Button(label="no",emoji="โ",style=discord.ButtonStyle.red)
async def yesbancallback(ctx):
await ctx.guild.ban(member,reason=reason)
yesbutton.callback = yesbancallback
async def nobancallback():
View().remove_item(yesbutton,nobutton)
nobutton.callback = nobancallback
view.add_item(yesbutton)
view.add_item(nobutton)
await ctx.send("test", view=view)```
The callback is empty?
for some reason i cant set gifs as discord.Embed.set_image
embed = discord.Embed(color=discord.Colour.embed_background(), title="vNziie-- hugged user")
embed.set_image(url="https://tenor.com/7Wko.gif")
https://cdn.nziie.is-a.dev/u/olwSkevT4yl6 keeps spinning then goes to the 404 image
https://tenor.com/7Wko.gif
no?
The url also works
I think that might be a Discord limitation.
I could be wrong though.
Well maybe until you find a solution send the GIF separately.
Have you opened a forum thread yet?
#883236900171816970 message
[No content to show, message most likely has an attachment](#883236900171816970 message)
No
Maybe do that.
Someone is bound to know how to.
I'll look into it when I have the time.
This is conveniently something I am trying to do for my bot as well.
Until you can do it in an embed ofc
The way I made my hug command was by scraping an API and replacing the bits that aren't the URL with nothing.
Hm interesting
from discord.ext import bridge
intents = discord.Intents.default()
intents.message_content = True
bot = bridge.Bot(command_prefix="!", intents=intents)
@bot.bridge_command()
async def hello(ctx):
await ctx.respond("Hello!")
@bot.bridge_command()
async def bye(ctx):
await ctx.respond("Bye!")
@bot.bridge_command()
async def sum(ctx, first: int, second: int):
s = first + second
await ctx.respond(f"{s}")
bot.run("token")```
this example from the docs gives this error:
Traceback (most recent call last):
File "/home/deez/turdbot/test/test2.py", line 10, in <module>
async def hello(ctx):
File "/home/deez/.local/lib/python3.8/site-packages/discord/ext/bridge/bot.py", line 91, in decorator
self.add_bridge_command(result)
File "/home/deez/.local/lib/python3.8/site-packages/discord/ext/bridge/bot.py", line 76, in add_bridge_command
self._bridge_commands.append(command)
AttributeError: 'Bot' object has no attribute '_bridge_commands'
Do you have something else installed?
if you mean library pip list says py-cord 2.3.0 is installed
I mean stuff like discord.py
no
https://github.com/Pycord-Development/pycord/issues/1800 nvm its a known issue
thx anyway
?
You're adding a field to an embed that has already been sent
use cogs pls
Is eny wey check roles using on_message event
Like
Bot.event
Async def on_message(message):
If massage.somthing == role id:
Await message.send("my message")
You can check the roles of the author of the message
Ok can you send docs for that
Oh god, please do not connect to your database on every message being sent
that's going to overload your database in minutes
Is eny wey to check for for a certain role?
Compare the IDs?
Yes
Like if user have certain role then its send a message
i changed it up a bit, now its not throwing any errors but still not working ```async def ban(ctx, member:discord.Member, *, reason=None):
view = View()
yesbutton = Button(label="yes",emoji="โ
",style=discord.ButtonStyle.green)
nobutton = Button(label="no",emoji="โ",style=discord.ButtonStyle.red)
async def yesbancallback(ctx):
await ctx.guild.ban(member,reason=reason)
yesbutton.callback = yesbancallback
view.add_item(yesbutton)
view.add_item(nobutton)
async def nobancallback(interaction):
view.remove_item(yesbutton)
view.remove_item(nobutton)
nobutton.callback = nobancallback
await ctx.send("test", view=view)
```
You need to edit the message with your new view if you're removing items
use interaction for buttons
how would i ban someone with interaction?
so would it be interaction.guild.ban or interaction.response.guild.ban?
thanks
try it
hi so I'm making a cog
for my bot
and I get
discord.errors.ExtensionFailed: Extension 'admin' raised an error: AttributeError: 'Bot' object has no attribute 'add_command'
.tag idw
Saying it doesn't work or asking what's wrong with this code is not helpful for yourself or others.
Describe what you expect and/or tried (with your code), and what isn't going right.
Please provide any errors you get for optimal assistance.
Send code
Here are my init and setup functions:
def __init__(self, bot):
self.bot = bot
def setup(bot):
bot.add_cog(AdminCmds(bot))
and some code
I use @commands.command to define a command
example
don't mind the ConfirmationView class, it's wip
and I don't think it's causing the problem
what do you think
Send your code in a file not screenshots
the entire thing?
this is what's in main.py at the end (if you're wondering)
bot.load_extension(f'admin')
bot.run(_TOKEN)
Do you have that file in a directory such as cogs?
no, same directory
is that a problem?
No
it's the only cog I'll have, so I don't think I need a folder for it
How do you initiate your bot instance?
^
bot = discord.Bot()
why
that's what's in the main file
Thatโs why
discord.Bot doesn't have add_command
You need to use commands.Bot
oh

.rtfm commands.Bot
discord.ext.commands.Bot
discord.ext.commands.bot_has_role
discord.ext.commands.bot_has_permissions
discord.ext.commands.bot_has_guild_permissions
discord.ext.commands.bot_has_any_role
discord.ext.commands.BotMissingPermissions
discord.ext.commands.BotMissingRole
discord.ext.commands.BotMissingAnyRole
ohhhh I see.
First one
alright thanks
so can I change bot = discord.Bot(intents=intents) to
bot = commands.Bot(intents=intents)
```without messing up my code?
I guess it's time to find out
okay bot's online
thanks
but-
yeah it broke my code lol
@bot.event
async def on_ready():
print("THE BOT IS ONLINE")
@bot.event
async def on_message(msg):
if not msg.author.id == botid:
if "f<@{botid}}>" in msg.content:
await msg.channel.send("My prefix is `/`")
if "us lol" in msg.content:
await msg.channel.send(f"us lol", reference=msg)
```, for example
do I change bot.event to commands.event or what
Try @bot.listen()
alright
edit: he doesn't do anything now
doesn't print when it's ready
or message when it gets pinged
add this to the message
await bot.process_commands(msg)
?
more exactly
before the bot.listen stuff
or after
do you use commands in the main file?
yes
I have non-cog commands in the main
No, so use @bot.event and then at the bottom of the function it decorates just put await bot.process_commands(msg)
ok
what about the on_ready
yeah
so you open the file
yeah, wait
you use open() to open a file
in your case, that'll be open(r'filename.txt')
then, I guess
text = ""
i = 1
for line in (open(r'filename.txt').readlines()):
if i == 300:
break
text += f"{line}\n"
oops
I guess that works (and that there's a better way)
try that though
Use file.seek
If you need an offset
otherwise use readlines and cut the list at the index you want to stop
?
sorry for the late reply but
on_ready(): works,
on_message(msg): doesn't
oh wait I put await bot.process_commands(msg) in the wrong place
sorry
Yea
I'll try
commands don't show up, and bot doesn't react to on_message
Send all of ur code please
should it be bot.listen for on_message
Just put it in pastebin or smthn
Yeah cuz @bot.event overrides the on_message event however if you put await bot.process_commands(msg) in the on_message event then ur commands will still work
do you still need the code
If your code doesn't work then yea
Try putting () after @bot.listen (so it should be like this @bot.listen())
ok
okay so he responds to messages but
commands don't work
changed @bot.command to @commands.command
cog doesn't work too for some reason
What?
you can use buttons with pycord correct?
yeah
Learn all about implementing buttons in your Discord Bot using Pycord.
can anyone help me
though
wait let me try replacing command with slash_command
and see
turned out I just had to change .command to .slash_command
slash commands are better anyways
Not a question about errors but more about finding a nice approach that isn't a big hassle to work with ๐
The bot is sending DMs to users and I am interested in blocking the user that has blocked the bot. The message is send with the fire and forget method asyncio.create_task(user_ctx.send(embed=embed)). The problem is that you can't catch the error if you fire the task away.
Any ideas on what the best way is to catch the discord.errors.Forbidden exception if you want to fire multiple messages at the same time? I havent found any equivalient to the e.g. aiohttp.ClientSession where you can do a async with statement to fire the tasks away rapidly
you can also use bridge commands ^^
very true
I have started to use only bridge commands so the people can choose which one they like to use
I want to use bridge commands but im relearning pycord and all of the discord syntex so def need to learn these
How do I add a timeout without interrupting my script?
I'm making an economy / leveltype bot
that gives you points for sending messages
do I make it a thread
use asyncio's sleep
thanks
now
can you mention users in the footer of an embed?
Can anyone help me with MongoDB?
Don't ask to ask, just ask
k
So, I'm trying to save roles in my db, but when I execute the command from another server it takes the roles that were saved from the first server. So I tried to fix it by just adding the guild id but either I messed up or it didn't work
The code:
guild_id = self.ctx.guild.id
check = cursor.find_one({"guild_id": guild_id, "_id": self.ctx.author.id})
user_name = self.ctx.author
if check is None:
cursor.insert_one({"guild_id": guild_id, "_id": self.ctx.author.id, "name": str(user_name), "roles": [str(r.id) for r in self.ctx.author.roles[1:]]})
else:
cursor.update_one({"guild_id": guild_id, "_id": self.ctx.author.id}, {"$set": {"roles": [str(r.id) for r in self.ctx.author.roles[1:]]}})
Error: "pymongo.errors.DuplicateKeyError: E11000 duplicate key error collection: dripbot.user_roles index: id dup key: { _id: 688040488024014882 }..."
Full traceback please
Also put it in a code block
is it possible to get someone's username just by their account ID?
prob have to use discord's api
but it'd be cool if that was built into pycord.
is it, by any chance?
Target not found, try again and make sure to check your spelling.
.rtfm respond()
Target not found, try again and make sure to check your spelling.
.rtfm ctx.respond
Target not found, try again and make sure to check your spelling.
#app-commands
well since I'm here and don't know how to use @winter condor
how do I respond privately to a slash command
it's probably in the docs but I don't wanna check
unless you just leave me on read
ephemeral=True
yeah I just saw it
in the docs
I'm making a command which adds an entry to a json file
and I want the user to choose between 4 options
but for some reason they don't show up
it's type: btw
I have a choices table / dict i forgor
and these don't show up
?tag nojson
Why not to use json files for data storage
JSON files are commonly used to store data that is read by a program, however, they are unsuitable for storing dynamic data due to a number of reasons.
It is recommended to use a DBMS (Database Management System) as they come with optimized technologies for storing and retrieving information.
Advantages of using a database:
- Database tables can be related, making it easy to separate your information into multiple tables and only fetch what you need
- Databases allow you to use a query/data processing language to make complex data operations easier with less code
- One misplaced character will corrupt an entire file. A database very rarely experiences corruptions due to their automatic handling of data integrity
- Transactions in SQL databases allow you to revert unwanted changes and prevent data corruption in the case of an error
- Databases have support for indexes, allowing retrieval of some data to be extremely fast
- It is very easy to update existing data in a database, as opposed to re-writing a file
- Databases are reliable
Popular database management systems:
- SQLite3 (File based, no need for a server setup, SQLite is the most used database engine in the world)
- MongoDB (Stores data in documents a similar manner to JSON format, easy for beginners)
- PostgreSQL (Very popular and robust SQL based database management system)
- MySQL (Another popular SQL based system, good start for learning SQL)
from commands.HelpCommand, how can i get my Bot object? or can i even get it?
.rtfm commands.HelpCommand
Maybe context.bot?
there isnt ctx tho
oh
#help-rules 4.2
You cannot ping or DM people for help
shit my b
Its not really a help need but ill follow the rules my man
Hello,
I have this slash command (function) that needs to authenticate to an API first in order to use the API each time I use the command.
And because the authentification takes too much time (a few seconds each time), I want to auth only once when I first use the command, and then I'd like to store the information that I already made the auth during this session.
Currently the auth is made each time I use the command which doesn't make sense since the bot stays online.
Is there a way to cache into the bot that I made the auth the first time, without using a specific command dedicated to making the auth first?
You could use a database
You can also make a custom bot class in which you store the auth
If it's a large amount of data, use a database. Otherwise you can just cache it in a globally available variable, or use a in-memory database like Redis.
how to get the thread from where command is invoked?
how can i create an eval command? i will restrict it just to me
is_owner()
It looks like ctx.channel returns the thread and not the parent channel.
commands.Bot
bot=commands.Bot(...)
you are right, i already forgot it. its a long time ago when i used pycord haha
thank you very much, both of you
what is this
take a look at your code and the error
okay, it says the "module" object is not callable
.
It's Bot not bot
No spoonfeed
we are here to help you learn or in other words, we aren't the United States education system
you can use self.bot.ses in your cogโs constructor
yeah
np
Hi since I was trying to build a new venv for py-cord, i created a blank one from conda through conda create
After activating the env I opened Jupyter notebook
To my surprise I was still able to access discord.py when the venv had no modules installed
Is this intended in Jupyter?
We would help you if you use py-cord
well it was supposed to be for py-cord but now I can't use it because I wanted a seperate env for it
Pycord still uses import discord
It was decided that "discord" was not attributed to discord.py
Ohhh, you don't even have pycord installed
I have not used jupiter. But it looks like you might have installed a package globally instead of locally.
I want to know how can i make eval command
File ".\sb.py", line 4035, in on_message
await client.process_commands(message)
AttributeError: 'Bot' object has no attribute 'process_commands'
This is not the place to ask "how to make x command". Get started on your own and come back if you run into any specific issues.
How do I use process_commands?
It says there is no process_commands....
How are you initiating your bot instance?
client = discord.Bot(command_prefix=default_prefix, intents=intents, guild_subscriptions=True)
^
discord.Bot doesn't have process_commands, use commands.Bot
.rtfm commands.Bot
commands.Bot
commands.Bot.activity
commands.Bot.add_application_command
commands.Bot.add_check
commands.Bot.add_cog
commands.Bot.add_command
commands.Bot.add_listener
commands.Bot.add_view
commands.Bot.after_invoke
commands.Bot.all_commands
commands.Bot.allowed_mentions
commands.Bot.application_command
commands.Bot.application_commands
commands.Bot.application_flags
commands.Bot.application_id
commands.Bot.application_info
commands.Bot.before_identify_hook
commands.Bot.before_invoke
commands.Bot.cached_messages
commands.Bot.can_run
ohh tysm
.rtfm commands.Bot
commands.Bot.walk_commands
commands.bot_has_role
commands.bot_has_permissions
commands.bot_has_guild_permissions
commands.bot_has_any_role
commands.BotMissingPermissions
commands.BotMissingPermissions.args
commands.BotMissingPermissions.with_traceback
commands.BotMissingRole
commands.BotMissingRole.args
commands.BotMissingRole.with_traceback
commands.BotMissingAnyRole
commands.BotMissingAnyRole.args
commands.BotMissingAnyRole.with_traceback
Where have you defined user in that code?
Is it possible to take a string as input such as "key":"value" and somehow turn that into a dict so i could just put it into a request like requests.post(url, headers, data=body) where body is the new dict
Why would it not be possible? Just parse the input to a dict
Yeah, that's why you need to parse it yourself
with the .dict() method?
No? Parse it yourself and then turn it into a dict
im not sure i understand what you mean by parse
Split the string up into components and add them to a dict
oh ok
ok. i am about waist deep in my own crap
i've written a very very large Discord bot. The logic within the commands and whatnot works great. It's all pretty neat and organized. However, the actual basis it's built on is horrendous. Imagine a skyscraper standing on a pile of twigs
I've essentially written this bot using the old school method, and never really incorporated the really nice new features that the API now supports. how bad of a task would it be to convert my bad bot into a good bot
rewriting, which is technically the correct answer, is sort of last on my list at the moment because this thing is monstrous
That is entirely up to you, we can't help you unless you have a specific question on a feature
Exactly how big is this bot? Files, lines of code, etc
it's about 20,000 lines long
across maybe 100 files
to my standard, that is big. i don't know how big that actually is in relation to a good bot
my goal is to essentially slap decorators on all my commands and tweak them to support the slash notation
let me give some context
this is my diabolical attempt at making a "cog" system
async def import_commands():
for file in sorted(os.listdir('commands')):
if file.endswith('.py') and not file.startswith('_'):
command_name = file[:-3]
mod = importlib.import_module(f'commands.{command_name}')
modules[command_name] = mod.metadata
print(
f'Loaded module: [b magenta]{mod.metadata["name"]}[/b magenta]')
and then within each module there is a main function which takes in three arguments like so:
async def main(client, message, args):


