#Basic Pycord Help (Quick Questions Only)

1 messages ยท Page 37 of 1

tiny hearth
#

python bot.py
in a bat file.

#

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

proud mason
tiny hearth
proud mason
#

else you dont have python 3.11 installed or in PATH

tiny hearth
proud mason
tiny hearth
#

its in path

proud mason
#

huh

#

ok

tiny hearth
#

im so confused

proud mason
#

same

#

this might be a bug

tiny hearth
#

imma report it on github

#

see what they can do

proud mason
#

if it is, ill lose my bet on 24hr no patch release after minor release ๐Ÿ’€

tiny hearth
#

lmao

young bone
#

wait

#

which one do you use?

#

discord.Bot
commands.Bot
bridge.Bot

tiny hearth
#

bridge.AutoShardedBot

young bone
#

can you try .Bot?

tiny hearth
#

interesting

tiny hearth
#

i know

#

well reported it on github

proud mason
tiny hearth
#

๐Ÿ‘

proud mason
#

๐Ÿ’€

proud mason
#

cool

#

now we wait

merry briar
#

.

proud mason
# merry briar .

i use 2.4.0 and it seems to work for me ๐Ÿคทโ€โ™‚๏ธ

#

show your pip list

merry briar
# proud mason 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```
proud mason
#

hmm

#

idk try asking in jishaku help server

slow halo
#

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

young bone
#

show the pip list and use ctx.respond()

waxen whale
#

upgrade to the latest version first

slow halo
#

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"

proud mason
#

did you update pycord to v2.3.0 ?

slow halo
# young bone show the pip list and use ctx.respond()

-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

slow halo
# slow halo -illow 7.1.2 absl-py 0.11.0 aiohttp ...

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

proud mason
#

2.0.0rc1 pogbruh

#

pip install -U py-cord

rare ice
#

upgrade py-cord

slow halo
#

as i said

young bone
#

that is a really old version

slow halo
#

that was the first that worked^^

#

i feel like the API changed like the API Reference page

proud mason
#

oh thats the new docs

#

just released this version

slow halo
#

not happy with the new design of the Page. I cant find the things i need without the search tool

rare ice
#

Agreed

#

The old docs were better

slow halo
#

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

fervent cradle
#

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

vivid plaza
#

Any traceback ? @fervent cradle

fervent cradle
#

Nope no error

vivid plaza
#

does the bot have the permission to create threads ? @fervent cradle

fervent cradle
#

Im pretty sure its got admin, since its my test server

vivid plaza
#

pretty sure it's ctx ?

fervent cradle
#

Oh ill try that, (I didnt know since i was tryna make it using docs)

vivid plaza
#

Okay!

fervent cradle
#
 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
vivid plaza
#

remove the message.

#

just ctx.create_thread

fervent cradle
#

Its creating the thread from the latest message in the channel tho, and thats what message gets

vivid plaza
#

Oh yeah True

#

I really don't know where's the issue, sorry. Wait for someone more experimented to help you!

fervent cradle
#

Okay thanks

hallow blaze
#

I believe this is the method you are utilizing?

fervent cradle
hallow blaze
#

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.

hallow blaze
# fervent cradle Why isnt this code creating a thread on the latest message in the channel? ```py...

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.

fervent cradle
#

Oh alright, much appreictaed

#

appreciated*

fervent cradle
# hallow blaze For more reference here's the docs for it: https://docs.pycord.dev/en/stable/api...
   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 ?
silver moat
#

discord.TextChannel is a class, not an object

limber urchin
#

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

fervent cradle
#

Alright

limber urchin
#

What?

silver moat
#

is ApplicationsChannel a valid channel?

limber urchin
#

Then your command isn't even running..

fervent cradle
silver moat
#

yeah, but does your bot have intents/permissions to view it

fervent cradle
#

Yeah

limber urchin
fervent cradle
# limber urchin Then your command isn't even running..
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
silver moat
#

?

limber urchin
#

Then why are you passing ctx? And how are yo calling that function if it's not a command?

fervent cradle
#

shi forgot to call it, would i use a cog listener?

limber urchin
#

A listener for what? What are you even trying to do?

fervent cradle
limber urchin
#

Then use the on_message event

fervent cradle
#

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)

silver moat
#

Yes, of course you can.

limber urchin
#

Yeah, why wouldn't you? Just compare the author to a predefined user object

fervent cradle
#

im really not being smart today haha

fervent cradle
# silver moat or id
        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
silver moat
#

what is message.get_id ?

fervent cradle
#

ignore that, i added that to test smth

silver moat
#

is this in a cog?

fervent cradle
#

It is

silver moat
#
  • bot.event doesn't work in a cog
  • missing self
fervent cradle
#

Oh found some docs

silver moat
#

yay

fervent cradle
#
    @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?
peak chasm
#

any way to add this but with a function?

fervent cradle
#

Isnt creating a thread though

silver moat
silver moat
opaque glacier
#

my friend is receiving this error in the terminal, what can they do to fix this

silver moat
#

?tag install

obtuse juncoBOT
#
  1. 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

silver moat
#

if they already did, then restart terminal/IDE

fervent cradle
silver moat
fervent cradle
#

Those are my only 2 handlers

silver moat
#

could you show code for it?

fervent cradle
#
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)
#

?

opaque glacier
#

still getting this error, they uninstalled then reinstalled

fervent cradle
#

just use pip install

#

use the github version too

#

?guide install

#

f

#

squid ^

silver moat
fervent cradle
opaque glacier
fervent cradle
# opaque glacier

lmao, also happens to me i created a python venv, then pip worked in there

#

Its also really useful to seperate your pip installations

fervent cradle
opaque glacier
fervent cradle
#

Install git

silver moat
#

?tag git

obtuse juncoBOT
#

dynoError No tag git found.

silver moat
#

?tag install0git

obtuse juncoBOT
#

dynoError No tag install0git found.

silver moat
#

?tag install-git

obtuse juncoBOT
#

dynoError No tag install-git found.

silver moat
#

?tag install_git

silver moat
#

first try

fervent cradle
#

lmao

fervent cradle
silver moat
#

could you print(ApplicationsChannel)?

fervent cradle
#

Ill try now

#

well

#
  1. It must have worked before but the thread is pravite and has no one but bots in it
  2. 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

silver moat
#

I lost your thread code, could you send it again or link it?

fervent cradle
#

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
silver moat
#

oh the event listener isn't inline with the constructor

fervent cradle
#

Oh should i unindent it ?

silver moat
#

yea

fervent cradle
#

Done, what can i do to make it a public thread?

opaque glacier
fervent cradle
# opaque glacier

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

fervent cradle
silver moat
#

It should be attached to a message

fervent cradle
#

Its in the correct channel, but its also a pravite thread

#

It should be public

silver moat
fervent cradle
silver moat
#

use

await message.create_thread(...)
fervent cradle
silver moat
#

all messages know what channels they are in

fervent cradle
#

Yeah but i want it to be only created in one channel

silver moat
#

then check if the message is in the channel, and then create the thread.

fervent cradle
#

Okay

fervent cradle
silver moat
fervent cradle
atomic wolf
#

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?

fervent cradle
fervent cradle
limber urchin
#

?tag nojson

obtuse juncoBOT
#

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)
atomic wolf
limber urchin
#

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

peak chasm
#

the limit discord.ui.select(
options = []
)
is 25??

limber urchin
#

Yes

peak chasm
limber urchin
#

It's a Discord limitation, nothing to do about it

fervent cradle
limber urchin
atomic wolf
#

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)
                    )
                    """
            )
limber urchin
fervent cradle
limber urchin
fervent cradle
#

sry but been workin on it for hours

waxen whale
limber urchin
atomic wolf
#

how do i make an array ._.

limber urchin
#

actually SQLite doesn't seem to have support for Arrays

meager heron
#

Could do a multicolumn index, of course

proud mason
#

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

limber urchin
waxen whale
#

oh please use something better than sqlite

atomic wolf
limber urchin
silver moat
#

have you considered non-sql databases

atomic wolf
#

what would you recommend for beginners?

proud mason
limber urchin
#

Probably MongoDB or Postgres

silver moat
#

mongo

waxen whale
#

transactional database

#

sweet

fervent cradle
proud mason
silver moat
limber urchin
proud mason
fervent cradle
fervent cradle
limber urchin
silver moat
#

does zapier send the webhook into the thread?

fervent cradle
#

Its sending the webhook into the channel, it SHOULD make a thread but because it ISNT a normal message, it isnt creating a thread

proud mason
#

can you explain what you are trying to actually achieve and then how you are trying to achieve it?

fervent cradle
#
    @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 ^

proud mason
#

do webhook messages trigger the on message event?

silver moat
#

it's not a system message so I don't see a problem

fervent cradle
silver moat
#

let me get this straight. A webhook sends messages in a channel and you want to attach a thread to that message, right?

proud mason
proud mason
#

.rtfm discord.Message.webhook_id

winter condorBOT
#

Target not found, try again and make sure to check your spelling.

proud mason
#

.rtfm discord.message.webhook_id

winter condorBOT
#

Target not found, try again and make sure to check your spelling.

silver moat
#

attributes don't exist

proud mason
fervent cradle
proud mason
#

i still see only 1 id

fervent cradle
#
    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)```
proud mason
#

ah

fervent cradle
#

I updated it as it was wrong but didnt fix it

#

cuz ofc they were the same b4

proud mason
#

arent webhooks restricted to a single channel?

silver moat
#

are you compared the channel id to a webhook id?

proud mason
fervent cradle
#

Should i take that code outside of a variable?

proud mason
#

if you code use it then just remove it

fervent cradle
errant craneBOT
#

[AFK] just a squid is AFK: No reason specified.

fervent cradle
#

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

meager heron
#

What is ApplicationsChannel for

proud mason
#

remove ApplicationsChannel line

and then instead of message.channel.id put message.webhook_id

#

๐Ÿ˜ž

#

i hope 1045793294891896953 is the webhook id

fervent cradle
#

Would on message event not work for webhooks though?

proud mason
fervent cradle
#

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?
proud mason
fervent cradle
#

misread (lmao)

proud mason
#

happens

fervent cradle
#

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

proud mason
fervent cradle
#

Done, will see if it prints

proud mason
#

ok

#

also show your intents

fervent cradle
#

Its got all intents, also admin

fervent cradle
proud mason
#

hmm

#

are you loading the extension ?

fervent cradle
#

Yeah

proud mason
#

also i hope you are running the bot ๐Ÿ’€

fervent cradle
#

I had this working with normal messages, cant seem to have it working with webhooks

fervent cradle
proud mason
#

which bot class are you using?

#

commands.Bot ?

fervent cradle
#

discord.ext.commands.bot

#

I was using commands.bot, but changed as i added bridge

proud mason
#

hmm

fervent cradle
fervent cradle
#

other than what i already done

#

for the if statment

proud mason
#

i mean how else would you check the webhook id

fervent cradle
#

I put a print directly above the cog listener, and it works so its seeing the file

fervent cradle
proud mason
fervent cradle
proud mason
#

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

fervent cradle
# proud mason try adding a on message event listener in the main.py file, and printing there ...
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

obtuse juncoBOT
#

dynoError No tag fetch found.

fervent cradle
#

?tag fetch_channel

obtuse juncoBOT
#

dynoError No tag fetch_channel found.

fervent cradle
#

f gimme a sec

proud mason
#

i gtg now

fervent cradle
proud mason
#

yeah

fervent cradle
proud mason
#

dont put ()

fervent cradle
#

ApplicationsChannel = self.bot.get_channel(int(1045782142489210985))

could do smth like this mby

proud mason
fervent cradle
#

Tru lmao

fervent cradle
#

before the if

#

Im so confused, this should be working

#

Should i create a new thread

#

@proud mason

#

#1045802687465279550

fervent cradle
#

Got it working

#

Im so stupid

simple canopy
#

is there actual examples of using bot.start instead of bot.run?

#

:d

fierce hazel
#

Does anyone have an example of configuring overwrites with the overwrites= parameter when using create_voicechannel?

silver moat
errant craneBOT
#

discord/client.py line 695

await self.start(*args, **kwargs)```
simple canopy
#

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

long torrent
#

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'```
proud pagoda
#

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.

proud pagoda
# proud pagoda How do I check if a command is being run by someone? I'm using the max_concurren...

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
proud mason
proud mason
simple canopy
#

oh well, i guess that stackoverflow thread was 10 yrs old

proud mason
#

๐Ÿ˜‚

plain cave
#

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"

remote onyx
#

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

remote onyx
plain cave
#

Ah ok! I'll give this a shot tomorrow. Appreciate!

dapper pasture
#

How do i get voice attribute with interaction

#

ok i just found out lol, it's interaction.guild.voice_client

tender seal
#

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

limber urchin
#

overwork the bot?

#

how would an if statement overwork your bot?

tender seal
#

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

limber urchin
#

yes

young bone
limber urchin
#

find?

tender seal
#

I'm a newbie

tender seal
limber urchin
#

If you're new to Python you should not be developing a Discord bot

young bone
#

but you know basic python?

limber urchin
#

read rule 1 in #help-rules

tender seal
#

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

limber urchin
#

You can just use the in operator for that

tender seal
#

what do you think

#

oh

#

I prefer .find but alright

limber urchin
#

It wouldn't work, because find returns -1 if it doesn't find anything

#

which would be parsed to True in your statement

tender seal
#

oh

#

wait fr

young bone
tender seal
#

lol...

#

nevermind

limber urchin
tender seal
#

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

limber urchin
#

That's not a pycord error

#

That's a basic Python error

tender seal
#

bruh my mind is really working at 1% capacity

#

what does this garbage mean though

#

never got it before

young bone
#

do you know asyncio?

tender seal
#

never had to import it, why

limber urchin
#

You need to know how to work with coroutines and async-await before developing a bot

young bone
#

you dont have to import it

tender seal
#

OHHH I forgot await

#

rookie mistake

limber urchin
#

Yeah, reading the error message is usually helpful

tender seal
#

was never awaited

#

๐Ÿ˜…

#

bruh I'm really working at 1% capacity

fervent cradle
#

I need help removing "discord.py 2.0.0" its overriding my pycord.

limber urchin
#

?tag install

obtuse juncoBOT
#
  1. 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

fervent cradle
tender seal
#

how do I embed a slash command in a message

limber urchin
#

What?

tender seal
#

instead of showing up as plain text

limber urchin
#

Use an embed just like you would in a normal message

tender seal
#

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...

limber urchin
#

Look at the github examples

tender seal
tender seal
#

oh.

limber urchin
#

Because you copy-pasted and forgot the change your if statement

frank thistle
#

Can you only allow autofilled choices on a slash command? Like prevent them from typin their own or not?

young bone
frank thistle
#

Whats the difference between choices and autocomplete?

#

Oh nvm, choices is what I wanted, it does what I asked about :P thanks dude

tender seal
#

how do I disable both of these by pressing just one

#

prob editing the message?

proud mason
#

yeah

tender seal
#

and how exactly would I do that

proud mason
#

.rtfm view.disable_all_items

winter condorBOT
#

Target not found, try again and make sure to check your spelling.

tender seal
#

oo

proud mason
#

Hmm

#

.rtfm discord.ui.View

winter condorBOT
tender seal
#

hmm clear_items()

proud mason
tender seal
#

okk

#

do I call it in the async function

proud mason
tender seal
tender seal
#

I actually should remove it

proud mason
tender seal
#

just

#

where do I put the function

#

oh

#

well, I tried self.disable_all_items() before the callback and it did nothing

proud mason
#

In both functions below interaction.response.send_message

tender seal
#

ahh

#

below, thanks

atomic wolf
#

How do i add multiple roles to a user by role id

proud mason
atomic wolf
#

yes

tender seal
proud mason
#

.rtfm user.add_role

winter condorBOT
#

Target not found, try again and make sure to check your spelling.

tender seal
#

member

proud mason
#

Ugh wait

#

Oh yeah

tender seal
#

.rtfm member.add_role

winter condorBOT
#

Target not found, try again and make sure to check your spelling.

tender seal
#

oh

proud mason
#

.rtfm member

winter condorBOT
#

Target not found, try again and make sure to check your spelling.

young bone
proud mason
#

Bruh wtf

young bone
#

.rtfm member.add_roles

winter condorBOT
#

Target not found, try again and make sure to check your spelling.

tender seal
#

they're still there

proud mason
tender seal
#

and clickable

proud mason
#

Best way to do it

proud mason
frank thistle
tender seal
#

(it's class btw)

#

not lass

proud mason
#

After clearing

tender seal
#

was I supposed to

proud mason
#

Yeah

tender seal
#

oh so it doesn't happen instantly?

proud mason
#

nah

tender seal
#

@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.

proud mason
tender seal
#

yeah

#

ik
how would I define them

tender seal
#

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

limber urchin
#

Pass it as a parameter to your init function and set it as an attribute of self in the class

tender seal
#

I like your funny words magic man

#

jkjk

#

but honestly

#

how

limber urchin
#

Do you know how to pass a parameter to a class?

tender seal
#

haven't done much with classes

limber urchin
#

Then learn OOP in Python

tender seal
#

so let me guess

#

do I put it after discord.ui.View

#

probably not

limber urchin
#

Not at all

tender seal
#

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

tender seal
#

I'll try that.

#

at least I was going in the right direction

atomic wolf
#

Can you use the add_roles thing with a list?

limber urchin
#

Does it say you can in the docs?

peak chasm
#

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

limber urchin
#

setting inline=True means that the next field will be placed next to it, it does not affect the current one

tender seal
#

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

limber urchin
#

Why are you trying to await the init?

tender seal
#

I was trying everything

#

experimenting

wild sequoia
#

AttributeError: 'NoneType' object has no attribute 'created_at'

#

<t:{round(memberr.created_at.timestamp())}:R>

memberr: discord.Member

#

can anyone help me please?;/

verbal dawn
# tender seal

Very late but
Copy the slash command's id (attachment below) then use this as template </name:id> for ex. </help:1030780665303679077>

proud mason
proud mason
# tender seal

Good idea to create the view outside of the msg.respond call

#

And then pass it

swift pumice
#

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?

wild sequoia
#

AttributeError: 'NoneType' object has no attribute 'created_at'
<t:{round(memberr.created_at.timestamp())}:R>

memberr: discord.Member
can anyone help me please?;/

proud mason
tender seal
proud mason
swift pumice
proud mason
limber urchin
tender seal
#

ok

swift pumice
limber urchin
#

get_user only gets users that are cached and can return None, use fetch_user to get a user from the API

full basin
#

You're probably running multiple instances

young bone
#

bot Bot Commands?

#

The embed text

meager heron
young bone
jaunty raft
#

How can I use slashcommandgroups in cogs?

young bone
errant craneBOT
#

Here's the slash cog groups example.

jaunty raft
#

Sure thanks

#

With specifying the member or without?

#

But it will return right ans it wont go further

young bone
#

use Option for the slash command

jaunty raft
#

Then it wont respond with anything

young bone
#

user: Option(discord.Member, required=False)

jaunty raft
#

Or decorator

fervent cradle
#

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.

limber urchin
#

Are you responding to the commands?

fervent cradle
#

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')```
limber urchin
#

No, use ctx.respond

fervent cradle
#

gotcha

rare ice
#

.rtfm discord.InteractionResponse.send_message

winter condorBOT
rare ice
#

its basically that

#

||new rtfm command coming in clutch||

limber urchin
#

Add a check inside of the button callback

proud mason
rare ice
#

.rtfm discord.User.color

winter condorBOT
rare ice
#

.rtfm discord.User

rare ice
#

#883236900171816970

proud mason
somber cedar
#

why is it that even there is a reaction(s), the len(react_message.reactions) is always 0

somber cedar
#

I set the bot to have all intents

silver moat
#

oh I think you are accessing a stale instance of the message

proud mason
#

fetch the original_response again after adding reaction

rare ice
#

yeah you have to fetch the message again to get the updated reaction data.

somber cedar
#
@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

proud mason
#

oh wait

#

.rtdm interactionresponse.original_response

#

.rtfm interactionresponse.original_response

winter condorBOT
#

Target not found, try again and make sure to check your spelling.

proud mason
#

pff

#

Repeated calls to this will return a cached value.

somber cedar
#

OH, that makes sense

#

So I'd have to get the message Id of the message and update from there, right?

proud mason
#

try react_message.channel.fetch_message(react_message.id)

proud mason
silver moat
#

await it

proud mason
#

yea ofc

#

or is it for when you do interaction.original_response()

proud mason
#

i myself wasnt sure that would work ๐Ÿ˜‚

#

happy it did

echo egret
silver moat
echo egret
#

it would be convenient for me to have them in join order

silver moat
#

ok

#

you can calculate that yourself

mild osprey
#

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)```
rare ice
#

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://tenor.com/7Wko.gif

mild osprey
silver moat
#

View() is the class

#

view is the object

fringe socket
#

I could be wrong though.

rare ice
#

I see other bots do it

#

@worn hound does it

#

but itโ€™s offline

fringe socket
#

Well maybe until you find a solution send the GIF separately.

#

Have you opened a forum thread yet?

rare ice
#

#883236900171816970 message

winter condorBOT
rare ice
fringe socket
#

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.

rare ice
#

thanks

#

yeah Iโ€™ll send it without an embed

fringe socket
#

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.

rare ice
#

@fringe socket Itโ€™s just tenor links that arenโ€™t working

#

Giphy links work

fringe socket
#

Hm interesting

harsh canyon
#
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'
young bone
harsh canyon
harsh canyon
#

no

#

thx anyway

young bone
#

?

limber urchin
#

You're adding a field to an embed that has already been sent

young bone
#

use cogs pls

fervent cradle
#

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")

limber urchin
#

You can check the roles of the author of the message

fervent cradle
#

Ok can you send docs for that

limber urchin
#

Oh god, please do not connect to your database on every message being sent

#

that's going to overload your database in minutes

fervent cradle
limber urchin
fervent cradle
#

Like if user have certain role then its send a message

limber urchin
#

Yes?

#

Compare the IDs of the roles

#

I told you

mild osprey
# silver moat `view` is the object

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)
    ```
limber urchin
#

You need to edit the message with your new view if you're removing items

mild osprey
#

ok

#

ty

mild osprey
young bone
#

the same like a command

#

but not with ctx

mild osprey
#

so would it be interaction.guild.ban or interaction.response.guild.ban?

mild osprey
#

ok

#

ty

tender seal
#

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'

winter condorBOT
rare ice
#

Send code

tender seal
#

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

tender seal
rare ice
tender seal
rare ice
#

Whatever is causing it yes

#

Your cog

tender seal
#

this is what's in main.py at the end (if you're wondering)

bot.load_extension(f'admin')
bot.run(_TOKEN)
rare ice
#

Do you have that file in a directory such as cogs?

tender seal
#

is that a problem?

rare ice
#

No

tender seal
#

it's the only cog I'll have, so I don't think I need a folder for it

limber urchin
#

How do you initiate your bot instance?

rare ice
#

^

tender seal
#

why

#

that's what's in the main file

rare ice
#

Thatโ€™s why

limber urchin
rare ice
#

You need to use commands.Bot

tender seal
#

oh

limber urchin
rare ice
#

.rtfm commands.Bot

tender seal
#

ohhhh I see.

rare ice
#

First one

tender seal
#

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

proud pagoda
tender seal
#

edit: he doesn't do anything now

#

doesn't print when it's ready

#

or message when it gets pinged

young bone
#

add this to the message

await bot.process_commands(msg)
tender seal
#

more exactly

#

before the bot.listen stuff

#

or after

young bone
#

do you use commands in the main file?

tender seal
#

I have non-cog commands in the main

proud pagoda
tender seal
#

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

limber urchin
#

Use file.seek

#

If you need an offset

#

otherwise use readlines and cut the list at the index you want to stop

#

?

tender seal
#

oh wait I put await bot.process_commands(msg) in the wrong place

#

sorry

proud pagoda
#

Yea

tender seal
#

I'll try

tender seal
proud pagoda
#

Send all of ur code please

tender seal
#

should it be bot.listen for on_message

tender seal
#

my entire main file

#

?

proud pagoda
proud pagoda
proud pagoda
#

If your code doesn't work then yea

tender seal
#

doesn't work

proud pagoda
# tender seal

Try putting () after @bot.listen (so it should be like this @bot.listen())

tender seal
#

ok

tender seal
#

commands don't work

#

changed @bot.command to @commands.command

#

cog doesn't work too for some reason

limber urchin
#

What?

fervent cradle
#

you can use buttons with pycord correct?

tender seal
tender seal
fervent cradle
#

โค๏ธ

tender seal
#

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

fervent cradle
#

slash commands are better anyways

frank shale
#

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

young bone
fervent cradle
young bone
#

I have started to use only bridge commands so the people can choose which one they like to use

fervent cradle
tender seal
#

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

limber urchin
#

use asyncio's sleep

tender seal
#

now

#

can you mention users in the footer of an embed?

limber urchin
#

No

#

Footers can only be plain text

atomic wolf
#

Can anyone help me with MongoDB?

full basin
#

Don't ask to ask, just ask

atomic wolf
#

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 }..."

proud mason
#

Also put it in a code block

atomic wolf
tender seal
#

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?

limber urchin
#

Fetch the user and get their name?

#

.rtfm discord.Bot.fetch_user

winter condorBOT
#

Target not found, try again and make sure to check your spelling.

limber urchin
#

alright nvm then

civic jayBOT
tender seal
#

.rtfm respond()

winter condorBOT
#

Target not found, try again and make sure to check your spelling.

tender seal
#

.rtfm ctx.respond

winter condorBOT
#

Target not found, try again and make sure to check your spelling.

young bone
#

#app-commands

tender seal
#

oh

#

yeah I forgot I'm in #998272089343668364

tender seal
#

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

young bone
#

Im on my phone so you have to read

full basin
tender seal
#

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

limber urchin
#

?tag nojson

obtuse juncoBOT
#

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)
rare ice
#

from commands.HelpCommand, how can i get my Bot object? or can i even get it?

#

.rtfm commands.HelpCommand

winter condorBOT
limber urchin
#

Maybe context.bot?

rare ice
#

there isnt ctx tho

rare ice
#

oh

rare ice
#

#help-rules 4.2

You cannot ping or DM people for help

fervent cradle
#

Its not really a help need but ill follow the rules my man

orchid kernel
#

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?

fervent cradle
#

You could use a database

raw gust
limber urchin
amber shale
#

how to get the thread from where command is invoked?

tiny wagon
#

how can i create an eval command? i will restrict it just to me

grizzled sentinel
young bone
#

create it not inside of the class

#

move the list above the cog class

somber frost
young bone
grizzled sentinel
#

bot=commands.Bot(...)

somber frost
#

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

young bone
somber frost
#

okay, it says the "module" object is not callable

young bone
somber frost
#

but where do i call "module" in line 6

#

๐Ÿค”

#

omg..

full basin
#

It's Bot not bot

somber frost
#

...

#

I'm sorry, thank you ๐Ÿ˜‚

silver moat
#

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

haughty sluice
#

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?

young bone
haughty sluice
#

well it was supposed to be for py-cord but now I can't use it because I wanted a seperate env for it

grizzled sentinel
#

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.

tiny wagon
fervent cradle
#

File ".\sb.py", line 4035, in on_message
await client.process_commands(message)
AttributeError: 'Bot' object has no attribute 'process_commands'

limber urchin
fervent cradle
#

How do I use process_commands?
It says there is no process_commands....

limber urchin
fervent cradle
#

client = discord.Bot(command_prefix=default_prefix, intents=intents, guild_subscriptions=True)

fervent cradle
limber urchin
#

.rtfm commands.Bot

fervent cradle
#

ohh tysm

still helm
#

.rtfm commands.Bot

limber urchin
#

Where have you defined user in that code?

fallow hawk
#

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

limber urchin
#

Why would it not be possible? Just parse the input to a dict

fallow hawk
#

when i input it it gets turned into '"key":"value"'

#

and it doesnt stay a dict

limber urchin
#

Yeah, that's why you need to parse it yourself

fallow hawk
#

with the .dict() method?

limber urchin
#

No? Parse it yourself and then turn it into a dict

fallow hawk
#

im not sure i understand what you mean by parse

limber urchin
#

Split the string up into components and add them to a dict

fallow hawk
#

oh ok

plush meadow
#

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

limber urchin
#

That is entirely up to you, we can't help you unless you have a specific question on a feature

hollow brook
#

Exactly how big is this bot? Files, lines of code, etc

plush meadow
#

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):