#Basic Pycord Help (Quick Questions Only)

1 messages · Page 53 of 1

hushed cargo
#

Damn

#

Oki how do I make it just work with one server?

young bone
#

set the guild id to the command

hushed cargo
#

Ohhh oki Tyty

meager heron
#

How can I check if my bot has manage_webhooks permission in a given channel?

When I run ctx.channel.permissions_for(ctx.bot.user), I get an error stating ClientUser object has no attribute '_roles'

harsh canyon
#

.

fervent cradle
#

how do i wait for a message?

silver moat
#

.rtfm bot,wait_for

winter condorBOT
#

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

silver moat
#

.rtfm bot.wait_for

indigo badger
#

Hi so I was makeing a gif command and for some reason every time it sends the gif will not load in the embed. ```py
@client.command()
async def gifs(ctx):
subreddit = reddit.subreddit("gifs")
top = subreddit.top(limit = 50)
all_subs = []

for submission in top:
all_subs.append(submission)

random_sub = random.choice(all_subs)

name = random_sub.title
url = random_sub.url

em = discord.Embed(title= name)

em.set_image(url = url)

await ctx.send(embed=em)

#

I am useing Praw to get the posts.

#

Anyone know a fix to this?

young bone
#

what is Praw?

silver moat
fervent cradle
silver moat
#

.rtfm discord.File

indigo badger
young bone
#

how should we know how to fix it?

silver moat
#

is url a valid url?

indigo badger
#

Yes.

young bone
#

any errors?

indigo badger
#

Nope.

#

It sends the embed but does not show the gif.

silver moat
#

is the gif spot loading or non-exist?

indigo badger
#

Shows that .

#

And says failed to load image when I click on it.

silver moat
#

url shows the url of the post I believe

#

so the url is not valid

indigo badger
#

Well I clicked the url and it sent me to the website.

silver moat
#

yeah the url should send to an image

#

or gif

#

not a website

indigo badger
#

Ya it is the gif that is on the website.

silver moat
#

let me make this clearer: the url should SEND you DIRECTLY to an IMAGE-LIKE file

fervent cradle
#

image = base64 jpeg ...

silver moat
#

are you sending a local file?

fervent cradle
#

no ?

silver moat
#

you should use the fp parameter. What type is image?

fervent cradle
#

data:image/jpeg;base64

silver moat
#

python datatype

young bone
#

can you show more code pls?

fervent cradle
silver moat
fervent cradle
#

base64

#

string

young bone
silver moat
#

yeah then File(fp=image)

fervent cradle
#

sends nothing and no error

#

image = base64 ...

full basin
#

Can you actually show how you're defining it

fervent cradle
#

request and json

silver moat
#

?tag request

obtuse juncoBOT
#

dynoError No tag request found.

silver moat
#

?tag blocking

obtuse juncoBOT
#

dynoError No tag blocking found.

full basin
#

.requests

winter condorBOT
#

Why you should not use the requests library for your bot
requests is a popular HTTP library for Python. It is however not a good option for Discord bots, since it is not async and blocking.

This essentially means that your bot will not be able to execute any code at all while a request is happening. Since requests usually take a few seconds to complete, this can have a detrimental effect on your bot's performance. E.g if a user executes a command that performs a request taking 5 seconds to complete, no one else will be able to use your bot for those 5 seconds.

Please look at using a HTTP library that has async support, such as aiohttp or httpx

full basin
#

Print image

#

And print type(image)

#

And show the console

silver moat
#

because we still don't know what it is

fervent cradle
#

oh shit

#

str

#

hymmm

#

idk

silver moat
#

filename="image.jpeg"?

indigo badger
#

Could it be because I am trying to load a image when a gif is not really a image?

#

Or no?

hushed cargo
#

im doing a view thing like this
`
SelectCommand = Select(blah blah blah)
async def SelectCommandCallback(select, interaction):
blah blah blah
SelectCommand.callback = SelectCommandCallback

view = View()
view.add_item(SelectCommand)
`
but when its run it says select is missing- how do i get?

hushed cargo
#

wut?

silver moat
#

send the error

#

with the on line x things

hushed cargo
#

the problem is it doesnt know wut select is-

silver moat
#

async def SelectCommandCallback(select, interaction): should be async def SelectCommandCallback(interaction):

hushed cargo
#

how do i get the selection?

silver moat
#

with SelectCommand

hushed cargo
#

rdfsuhijyarfijlsu im dum- howw

#

i need the callback to do different stuffs based on wut was selected

silver moat
#

SelectCommand.values ?

hushed cargo
#

nuu this better naming

#

thank you-

#

its working nowww

silver moat
#

yw

hushed cargo
#

also reason this one has weird names is bc its wut im using to reset my commands

#

like reloading them

#

sorry bad choice of words-

proud mason
limber urchin
#

discord.Member.kick?

#

You need to learn how OOP works in Python before making a bot

fervent cradle
#

maybe

limber urchin
#

Read #help-rules

harsh garden
#

how can I make the slash command only visible and available to admins?

proud mason
errant craneBOT
#

Here's the slash perms example.

empty kraken
#

Hey guys, i want to make a bot which includes image generation. but as you know PILLOW is really slow and it is not supporting async either. How can i solve this?
Should i make a webserver where images will be generated and bot can just read bytes and send it, or should i do some queued image generator in another thread with callbacks?

proud mason
#

Well you can use asyncio.to_thread which makes stuff a lot easier

#

And are you using PIL or Pillow

empty kraken
proud mason
#

im wrong

#

its the opposite

#

💀

#

pillow is the maintained onee

loud holly
#

has anything happened with member_count which apparently doesn't exist in Guild

loud holly
#

suddenly broke

proud mason
loud holly
#

I have all intents enabled

#

enabled it on the apps as well

fervent cradle
proud mason
#

check if it works with stable release

#

(2.3.2)

proud mason
#

a string of bytes?

loud holly
#

if it works, I'll see reinstalling everything on the container itself

fervent cradle
loud holly
#

if not you should learn it

fervent cradle
#

no*

proud mason
#

Learning asyncio basics is really really important for using pycord

#

.lp

winter condorBOT
#
proud mason
signal stratus
#

How do I import all Intents without the presence intent?

proud mason
signal stratus
fervent cradle
#

why its dont work ?

full basin
#

Use actual loop tasks and not while loops

fervent cradle
#

is it possible to loop with variables?

#

async def time_task(xyz, xyz2):

#

and start

#

?

full basin
#

.tias

winter condorBOT
fervent cradle
#

😦

signal stratus
#

Why is this not working? presence is not found. I want to get out of the way of all intent that presence needs

full basin
#

.rtfm Intents.presence

winter condorBOT
full basin
#

Missing a S chief

#

Reading the docs is useful.

signal stratus
#

ok

frank thistle
#

Is discord dying? None of my bots have any slash commands registered anymore kek

frank thistle
#

Ty

full basin
signal stratus
#

oh lol

#

idk

alpine kernel
#

is using an asyncio mutex lock common practice for something that might set the state of a bot?

fervent cradle
#

Is it somehow possible to catch 2 errors in a try-catch block? If so, how?

proud mason
proud mason
# fervent cradle

loop.create_task is not a coroutine tbh. asyncio.create_task is preferable

just use tasks extension. it is much better

proud mason
proud mason
proud mason
waxen skiff
#
import discord
from discord.ext import commands
import os, sys
from views.SeedsPlantsButton import SeedsPlantsButton
sys.path.append(os.path.abspath('..'))
import db.utils as utils```

i dont understand why my cogs arent loading or erroring but my imports are correct
#

it worked before i split stuff up into seperate files

alpine kernel
fervent cradle
proud mason
fervent cradle
#

I don't think you can, importing messes up when you try to import a folder or file with spaces in it

proud mason
proud mason
#

what doesnt work?

fervent cradle
#

only recive

green hinge
#

Is that possible?

@discord.ui.select(placeholder="Wähle einen Spot aus", options=get_water)```
proud mason
#

dont use requests

#

use aiohttp

#

?tag blocking

obtuse juncoBOT
#

dynoError No tag blocking found.

proud mason
#

.blocking

#

ugh

proud mason
#

?tag aiohttp

obtuse juncoBOT
#

Use aiohttp.
requests and urllib are blocking. Do not use these libraries within your asynchronous code as they're not asynchronous.
(http://discordpy.readthedocs.io/en/latest/faq.html#what-does-blocking-mean)

discord.py uses aiohttp, so it should already be installed. An example of code using aiohttp and discord.py:

async with aiohttp.ClientSession() as cs:
    async with cs.get('https://httpbin.org/json%27') as r:
        res = await r.json()  # returns dict
        await ctx.send(res['slideshow']['author']) 

For more help, see aiohttp's documentation: <http://aiohttp.readthedocs.io/en/stable/>

proud mason
#

?tag xy

obtuse juncoBOT
#

An XY problem is when you're trying to ask about your attempted solution, rather than your actual problem.

You are trying to solve problem X, using solution Y. Instead of asking for help with X, you ask about Y. This only results in frustration as whoever is trying to help you needs to ask several questions before even beginning to help you with your actual issue, wasting both their own, and your time. Always include as much information as you can about your problem, including attempted solutions. If there are solutions you've ruled out, include them along with an explanation as to why you've ruled them out.

green hinge
proud mason
green hinge
fervent cradle
#

dont work

#

still

#

idk sorry

proud mason
#

slash cmds broken for me for some reason. let me pull up an example

#

smth like that

green hinge
proud mason
#

dont use requests and websocket. they are blocking. use aiohttp

proud mason
green hinge
# proud mason <https://github.com/Pycord-Development/pycord/blob/master/examples/views/dropdow...

Is this as correct as I thought it was?

async def get_water(ctx: discord.AutocompleteContext):
      waters = await dab.get_waters()
      return [water[1] for water in waters if water[1].startswith(ctx.options["gewässer"])]

class Dropdown(discord.ui.Select):
    def __init__(self, bot: discord.Bot):
        self.bot = bot
        options = get_water()
        super().__init__(
            placeholder="Wähle das Gewässer aus",
            min_values=1,
            max_values=1,
            options=options,
        )
        
    async def callback(self, interaction: discord.Interaction):
      await interaction.response.send_message(f"Deine Auswahl ist: {self.values[0]}")


class SpotSettings(discord.ui.View):
    def __init__(self, bot: discord.Bot):
        self.bot = bot
        super().__init__(timeout=None)

        self.add_item(Dropdown(self.bot))```
frank shale
#

Like, it was working fine today, but now all commands are gone

fervent cradle
frank shale
#

Ok happy than it is not my problem ^

fervent cradle
#

show the code

young bone
#

?tag intents

obtuse juncoBOT
#

https://docs.pycord.dev/en/master/intents.html
https://discord.com/developers/docs/topics/gateway#gateway-intents

import discord
from discord.ext import commands

# Get specific intents for fine control
intents = discord.Intents()
intents.emojis = True
intents.guilds = True
intents.messages = True  # Required for prefix commands!
...
# Get all non-priveliged intents; this excludes presences, members and message_content 
intents = discord.Intents.default()

# Set priveliged intents: these must be enabled on dev portal
intents.members = True
intents.presences = True
intents.message_content = True  # Required for prefix commands >= 2.0.0b5

# Get all intents; all intents must be enabled on dev portal.
intents = discord.Intents.all()

# Apply intents when creating your bot
bot = commands.bot(prefix="?", intents=intents)
Discord Developer Portal

Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.

young bone
#

?tag requests

obtuse juncoBOT
#

Why you should not use the requests library for your bot
requests is a popular HTTP library for Python. It is however not a good option for Discord bots, since it is not async and blocking.

This essentially means that your bot will not be able to execute any code at all while a request is happening. Since requests usually take a few seconds to complete, this can have a detrimental effect on your bot's performance. E.g if a user executes a command that performs a request taking 5 seconds to complete, no one else will be able to use your bot for those 5 seconds.

Please look at using a HTTP library that has async support, such as aiohttp or httpx

loud holly
#

what the typing intent used for?

#

what is its purpose exactly

young bone
waxen skiff
#

i like how instead of it erroring it just doesnt load the cog

#

makes it very easy to debug

loud holly
#

I'm trying to basically remove intents that I'm not using

#

so I'm going through all the intents

young bone
#

you can just do intents=discord.Intents.all()

loud holly
#

I can't upgrade the server bc I don't have funds

waxen skiff
#

how can i make slash commands have options

young bone
young bone
waxen skiff
#

for an arg

#

alright

#

and set a description for an arg?

young bone
#

description=""?

loud holly
#

description=""

young bone
loud holly
#

ty however it doesn't have much explanation for typing intents which was why I was confused for why does it exist

young bone
#

oh, mhm

full basin
#

The python server will be more helpful

ornate swan
spice oyster
#

Hello! I had py-cord==2.3.0 in my requirements.txt file for a while and made no changes to the code or to other files. Why am I suddenly getting this error?

Traceback (most recent call last):
File "/.local/lib/python3.9/site-packages/discord/ui/view.py", line 414, in _scheduled_task
await item.callback(interaction)
File "/cogs/draft.py", line 118, in first_pick
await self.on_interaction(button, interaction)
File "/cogs/draft.py", line 199, in on_interaction
interaction = await interaction.response.send_message(content)
File "/.local/lib/python3.9/site-packages/discord/interactions.py", line 825, in send_message
await self._locked_response(
File "/.local/lib/python3.9/site-packages/discord/interactions.py", line 1090, in _locked_response
await coro
File "/.local/lib/python3.9/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```
full basin
#

Might be taking more than 3 seconds to respond

fervent cradle
#

that file isn't to do with that error

spice oyster
spice oyster
waxen skiff
#
    async def interaction_check(self, interaction: discord.Interaction):
        return interaction.user.id == self.author.id```
#

why doesnt this work

#

only make the button work for the author of the original message

#

and i pass the self.author into the button

full basin
#

.tag idw

winter condorBOT
#

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.

waxen skiff
#

i just did 💀

limber urchin
#

You did not explain what you expect to work or provide any errors

#

We have no idea what you're trying to do

spice oyster
waxen skiff
#

i got it

waxen skiff
#

What are you trying to do?

only make the button work for the author of the original message

#

and no errors

waxen skiff
#

how do i make my slash commands updated options show up? this is my code and i just added the member option and min and max to amount and both of those dont show up

@discord.option("member", discord.Member, description="The member to get the profile of, leave blank for yourself", required=False, default = None)
# command

@discord.option("amount", min_value=1, max_value=100, description="The amount of seeds you want to buy", required=False, default=1)
# command```
#

no errors

young bone
#

Im not sure how stable the discord API is at the moment

young bone
waxen skiff
#
async def profile(self, ctx, member: discord.Member = None):

async def buy(self, ctx, seed, amount:int=1):
loud holly
waxen skiff
#

yes

loud holly
waxen skiff
#

\then it should work..

#

hmm

loud holly
waxen skiff
#

huh

young bone
loud holly
#

wait no, you're using @discord.option

young bone
#

discord.option()

waxen skiff
#

yeah..

#

so...

young bone
#

you can use both

waxen skiff
#

then why isnt it working

young bone
#

give it some time

#

discord is weird with slash commands

#

ok discord.option and discord.Option is not the same. I get an error if I use discord.Option

loud holly
#

If there's a server where I can't get any information from, but from bot.guilds it is showing that there's a server that the bot is in, but I can't get any info from, does it mean that it is inactive?

young bone
loud holly
#

and printed out memer_count along with guild.name

#

and when I use len(bot.guilds), I'm getting 14 however 13 guilds are being printed

rare ice
loud holly
#

Ty

waxen skiff
#
@discord.option("member", discord.Member, description="The member to get the profile of, leave blank for yourself", required=False, default = None)
    async def profile(self, ctx, member: discord.Member = None):```
#

why isnt the option working

#

it doesnt show up

waxen skiff
silver moat
waxen skiff
#

will do

#

cool! it worked!!

silver moat
hushed cargo
#

is this supposed to work?
msg = await interaction.original_response() await msg.delete()

proud mason
hushed cargo
proud mason
#

That should work too

hushed cargo
#

;-; damn- i didnt know it was so simple dfjknjnevajlve

#

it not workk

proud mason
#

That's why you should always read the docs

proud mason
#

.idw

winter condorBOT
#

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.

hushed cargo
#

says 404 not found lemme get a ss

proud mason
hushed cargo
proud mason
#

I'm usually not a guy to judge but windows vm in a Mac?? Mac is already pretty good, if not better for development

hushed cargo
#

hfdshjvajsjhf

#

NOT A VM

proud mason
proud mason
hushed cargo
#

ohhhhh sorry im dum i thought you meant error code-

#

ill explain command, i have sum so i dont have seperate commands for /slap, /hug etc so i have this select menu thingy it sends as an ephemeral and when you select thingy it sends it in the current channel and i wants it to delete the select message, andddd im using chrome remote desktop to control my windows server pc-

proud mason
# hushed cargo

Ah so you want to select menu itself rather than the message it sends?

proud mason
hushed cargo
#

the select menu is just to decide wut you wanna do (this has all the /slap, /punch, /hug etc) and ofc i want the menu to be only viewable by the sender, but it isnt rly needed after it sends the message

proud mason
#

Add self.stop() to the end of the view callback

add await view.wait() to the Slash cmd
And then do await ctx.interaction.delete_original_response()

hushed cargo
#

ohhhh ajnvejniaevjinjeajniv TYYY that makes so much senseeee

proud mason
#

Also just so you know, you can access the bot instance through interaction.client in the callback
No need to pass the bot instance to the view

hushed cargo
#

omgg to XD

#

tyyyyyy*

proud mason
#

Np prayadge

hushed cargo
#

Now is doing
await self.stop()
TypeError: object NoneTypw can’t be used in “await” expression

proud mason
#

Full error?

hushed cargo
proud mason
#

You don't await it

hushed cargo
#

Taking screenshot on Mac is pain-

#

OH

proud mason
#

I find it easy lul

hushed cargo
#

XD I didn’t know abt that one 😭

#

I was using cmd+shift+3 then cropping 😭

proud mason
#

"Dommy Mommy is online"
Reminds me of @waxen whale kek

proud mason
hushed cargo
#

XD

#

That’s the bots name-

proud mason
proud mason
hushed cargo
#

Fr dommy mommies >>>

#

Also wut do I use instead of “await view.wait()

#

proud mason
hushed cargo
#

Wellll

#

First off “view” doesn’t exist-

proud mason
#

You would need to create the view instance before the ctx.respond
Not inside it

hushed cargo
#

Then if I replace with View

#

The view is a different class doe-

proud mason
#

Wait I'll show an example

hushed cargo
#

Oki Tyty

proud mason
#

You are doing this

async def cmd(...):
    ...
    await ctx.respond(..., view=MyView())
    # await view.wait() can't 😭

Do

async def cmd(...):
    ...
    view = MyView (...)
    await ctx.respond(..., view=view)
    await view.wait()
hushed cargo
#

Couldn’t do “await MyView(…).wait()?

silver moat
#

no, you are creating another MyView instance

#

different from the original one you sent

proud mason
proud mason
#

Yeah

silver moat
#

k I'll go to bed then

hushed cargo
#

XD

#

Night night

proud mason
#

Alr gn prayadge

hushed cargo
#

OMG IT WORKS

#

TYYY

proud mason
#

Yay 👍

hushed cargo
#

I has other question that isn’t exactly pycord but i imagine you’d know wayyyy more than me

#

So I use MySQL database, and if I just connect to it when main is run at first it doesn’t work after like a day

proud mason
#

👀

#

Hmm i don't use MySQL tbh

hushed cargo
#

My fix is to connect every time a command is run this feels rly inefficient

proud mason
#

What connector do you use?

hushed cargo
#

Yea-

proud mason
#

Do you use connection pools?

waxen whale
#

who've summoned me

hushed cargo
#

Idek wut that is 😭

hushed cargo
#

Thats my bots nameeee

proud mason
proud mason
proud mason
hushed cargo
#

I just use MySQL,connector-

#

Imma be honest I had no idea how databases worked like a week ago-

#

Also imma prolly goto bed soon-

#

Bc gotta be able to get up early ish, bc has appointment!!! And hopefully E dose goes upppp:D

tribal bough
#

how to add reaction to a respond message?

#

not workingpy msg = await ctx.respond(embed=embed) await msg.message.add_reaction("👍") await msg.message.add_reaction("👎")
error: txt Application Command raised an exception: AttributeError: 'NoneType' object has no attribute 'add_reaction'

proud mason
green hinge
# proud mason Looks correct. Except for the part that get_water is an async function 💀

Okay made it as a normal function.
But now I get the error message:

    options = get_water()
  File "c:\Users\User\Documents\Coding\OnlyFrames\cogs\spot.py", line 27, in get_water
    return [water[1] for water in waters]
TypeError: 'coroutine' object is not iterable
C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ui\view.py:416: RuntimeWarning: coroutine 'get_waters' was never awaited
  return await self.on_error(e, item, interaction)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback```
green hinge
proud mason
#

You can use botvars to access the list

#

.botvar

winter condorBOT
#

Need to keep track of a variable between functions? No problem!

⚠️ Careful what you name it though, else you might overwrite something ⚠️

Just add it to your commands.Bot or discord.Client instance like so:

bot = commands.Bot(...)
bot.my_variable = 0

async def foo():
    bot.my_variable += 1

# In a cog
@commands.command()
async def counter(self,ctx):
    await ctx.send("Current Counter is at {}".format(ctx.bot.my_variable))

This also allows you to access this from other cogs/extensions/functions. Anywhere you have access to the bot instance

green hinge
# proud mason You can use botvars to access the list

Did I understand that correctly?

bot.waters = []

@bot.event
async def on_ready():
    bot.waters = await dab.get_waters()
    print(f"{bot.user} ist online")```
```py
class Dropdown(discord.ui.Select):
    def __init__(self, bot: discord.Bot):
        self.bot = bot
        options = bot.waters
        super().__init__(
            placeholder="Wähle das Gewässer aus",
            min_values=1,
            max_values=1,
            options=options,
        )
        
    async def callback(self, interaction: discord.Interaction):
      await interaction.response.send_message(f"Deine Auswahl ist: {self.values[0]}")```
hushed cargo
#

how do i get get the server id here?

green hinge
#

How can I display my dropdown menu or update the view?

class SpotSettings(discord.ui.View):
    def __init__(self, bot: discord.Bot):
        self.bot = bot
        super().__init__(timeout=None)

    @discord.ui.button(label='🎣 Start', custom_id="StartButton", style=discord.ButtonStyle.primary)
    async def start_button(self, button: discord.ui.Button, interaction: discord.Interaction):
        await interaction.response.send_message(f"Bitte wähle das Gewässer aus")
        self.add_item(Dropdown(self.bot))```
fervent cradle
#

Hey guys I know the basic autocomplete stuff, but how do I suggest a diff list of items once some text has already been put into the bot, eg in the box i put in a and it shows a whole diff list with stuff starting from a for example

grizzled sentinel
#

I think there is an example of this somewhere in the autocomplete example. I would give more info but my internet is being slow and not loading anything.

fervent cradle
#

wait i got what i was tryna do,

current_val = ctx.interaction.data['options'][0]['value']

assuming [0] is the option number

#

and i can give stuff based on that

proud mason
hushed cargo
#

Where the commented stuff is out

proud mason
#

dont use global variables ngl

hushed cargo
#

I’m not-

#

So I’m asking how-

#

Bc it’s not in a function so can’t pass it in and use self

proud mason
#

how do you plan on running it if it is not a function

#

its not even inside the __init__ if thats what you were planning

hushed cargo
#

This it’s not-

#

The options are set there so they can be accessed by @discord.ui.select

#

Butt imma have some nsfw options that I only want to be added if nsfw stuff is enabled in the server

#

So it needs the server id to check if it is

#

And if it’s in a function @discord.ui.select won’t be able to get it

proud mason
#

subclass the select menu

hushed cargo
#

Idk how to do dat-

proud mason
#

thats the best way to go if you dont want static options

proud mason
#

wait ill do it

hushed cargo
#

Oki tyty

west venture
#

Is there any way i can use gifs in embeds set_images?

young bone
#

why should it not work?

west venture
#

its not working

young bone
#

can you show the code?

west venture
#

.||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||https://ask-your-mom.big-pp.club/🚽🚏🐍🤫

I wasted more than 13.98 KB for you to see this

25/01/2023 at 18:26

young bone
#

wait, do you use the Better Discord Plugin to send embeds?

west venture
#

.||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||||​||https://ask-your-mom.big-pp.club/🥇🤩💾🌽

I wasted more than 11.04 KB for you to see this

25/01/2023 at 18:27

young bone
#

?tag requests

obtuse juncoBOT
#

Why you should not use the requests library for your bot
requests is a popular HTTP library for Python. It is however not a good option for Discord bots, since it is not async and blocking.

This essentially means that your bot will not be able to execute any code at all while a request is happening. Since requests usually take a few seconds to complete, this can have a detrimental effect on your bot's performance. E.g if a user executes a command that performs a request taking 5 seconds to complete, no one else will be able to use your bot for those 5 seconds.

Please look at using a HTTP library that has async support, such as aiohttp or httpx

proud mason
#

.aiohttp

young bone
obtuse juncoBOT
#

Use aiohttp.
requests and urllib are blocking. Do not use these libraries within your asynchronous code as they're not asynchronous.
(http://discordpy.readthedocs.io/en/latest/faq.html#what-does-blocking-mean)

discord.py uses aiohttp, so it should already be installed. An example of code using aiohttp and discord.py:

async with aiohttp.ClientSession() as cs:
    async with cs.get('https://httpbin.org/json%27') as r:
        res = await r.json()  # returns dict
        await ctx.send(res['slideshow']['author']) 

For more help, see aiohttp's documentation: <http://aiohttp.readthedocs.io/en/stable/>

young bone
#

;3

proud mason
#

yeah that

#

❤️

west venture
young bone
#

thats why it is not working...

west venture
#

what link i have to use?

young bone
#

you have the website and not the gif

west venture
green hinge
#

How can I display my dropdown menu or update the view?

class SpotSettings(discord.ui.View):
    def __init__(self, bot: discord.Bot):
        self.bot = bot
        super().__init__(timeout=None)

    @discord.ui.button(label='🎣 Start', custom_id="StartButton", style=discord.ButtonStyle.primary)
    async def start_button(self, button: discord.ui.Button, interaction: discord.Interaction):
        await interaction.response.send_message(f"Bitte wähle das Gewässer aus")
        self.add_item(Dropdown(self.bot))```
proud mason
proud mason
green hinge
# young bone edit_message(view=self)
class SpotSettings(discord.ui.View):
    def __init__(self, bot: discord.Bot):
        self.bot = bot
        super().__init__(timeout=None)

    @discord.ui.button(label='🎣 Start', custom_id="StartButton", style=discord.ButtonStyle.primary)
    async def start_button(self, button: discord.ui.Button, interaction: discord.Interaction):
        await interaction.response.send_message(f"Bitte wähle das Gewässer aus")
        self.add_item(Dropdown(self.bot))
        await interaction.response.edit_message(view=self)```
Then I get this error message:

discord.errors.InteractionResponded: This interaction has already been responded to before```

hushed cargo
#

am getting error

full basin
proud mason
green hinge
hushed cargo
full basin
#

You're overriding the init

#

You must add super().__init__()

hushed cargo
#

yea i have this here sorry fogot to show it as its kinda in the middle of everything, its in the select

full basin
hushed cargo
#

yea i just added thatt testing it rn tyyy<3 /p

#

oki so looks like it works but doesnt seem like the callback is working-

#

like it runs fine but when i select something it doesnt respond but no error

full basin
#

Name your callback "callback"

#

Not select_callback

hushed cargo
#

yee i changed that and same thing

#

waitt i tink the problem is that it doesnt use select, how do i get the selected value?

full basin
#

self?... self is the select

hushed cargo
#

omg- im dum-

#

im sorry- im running on very little sleep-

#

i needs a monster and ill be oki-

hushed cargo
#

Im unable to get screenshots- but I’m this how would I use view.wait() with the self.stop()

#

Bc a select doesn’t have a self.stop()

proud mason
young bone
proud mason
hushed cargo
#

Perfect tysm!!!!

hushed cargo
wary rover
#

Hello, I've been coding for a while with py-cord and I've never had this problem. Would you have an idea?
My code works perfectly.

17:28:08 [ERROR] Loading cogs error --> Extension 'addons.configuration.cogConfiguration' raised an error: ClientException: Too many arguments passed to the options kwarg.
proud mason
#

huh

#

thats new

#

are you using some 3rd party extension?

wary rover
young bone
wary rover
wary rover
#

It was a problem with groupConfiguration = bot.create_group("configuration") obviously doing that in a class doesn't give a proper result, although it works.

proud mason
#

hmm

queen kayak
#

Hi, is there a way to get more than the most recent 100 entries in the audit log? I'm trying to get logs from weeks ago and nothing is being returned

        async for entry in ctx.guild.audit_logs(oldest_first=True, action=discord.AuditLogAction.member_update,
                                                before=datetime(2023, 1, 8)):
proud mason
#

pycord version?

#

@round rivet hey does view.message rely on bot cache? shouldnt the message exist as long as the view itself has a reference count and is not garbage collected?

#

hmmm

glossy sand
#
Error handling request
Traceback (most recent call last):
  File "/root/HC_venv/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 314, in data_received
    messages, upgraded, tail = self._request_parser.feed_data(data)
  File "/root/HC_venv/lib/python3.10/site-packages/aiohttp/http_parser.py", line 300, in feed_data
    msg = self.parse_message(self._lines)
  File "/root/HC_venv/lib/python3.10/site-packages/aiohttp/http_parser.py", line 494, in parse_message
    raise BadStatusLine(line) from None
aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'SM'"

I've been regularly getting these types of 'Bad status line' errors, does anyone have any idea what this is?

proven widget
#

hi just a quick question how to make code to kick/ban players with the slash commands

young bone
proven widget
young bone
#

?tag idw

obtuse juncoBOT
#

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.

proven widget
#

1 min

#

@young bone how to put my code in box here?

young bone
#

?tag codeblock

obtuse juncoBOT
#

Please put your code in a code block:
```py
Here is your Code
```

That makes reading code in Discord a lot easier:

print("This is an example.")
proven widget
#
@commands.has_permissions(kick_members = True, administrator = True)
async def kick(ctx, member: Option(discord.Member, description = "Who do you want to kick?"), reason: Option(str, description = "Why?", required = False)):
    if member.id == ctx.author.id: #checks to see if they're the same
        await ctx.respond("BRUH! You can't kick yourself!")
    elif member.guild_permissions.administrator:
        await ctx.respond("Stop trying to kick an admin! :rolling_eyes:")
    else:
        if reason == None:
            reason = f"None provided by {ctx.author}"
        await member.kick(reason = reason)
        await ctx.respond(f"<@{ctx.author.id}>, <@{member.id}> has been kicked from this server!\n\nReason: {reason}")

@kick.error
async def kickerror(ctx, error):
    if isinstance(error, MissingPermissions):
        await ctx.respond("You need Kick Members and Administrator permissions to do this!")
    else:
        await ctx.respond("Something went wrong...") #most likely due to missing permissions 
        raise error
#

that is my code i know im noob but ya

young bone
#

how do you define the bot?

proven widget
young bone
#

do you know the basic´s of python?

spare juniper
#

@ancient summit

#

self.message is None

#

make sure that self.message exists first

#

what is self? are you sure self has a message attribute?

#

do you have any code for what self is?

#

please copy and paste code as a code block

do this:

```python
PASTE CODE HERE
```

#

add ,ctx after self

#

i believe

#

.rtfm view.on_timeout

winter condorBOT
young bone
obtuse vale
#

is it normal that tasks.loop is stopping while a slash command is being used?

spare juniper
#

interesting

#

.rtfm discord.ui.View

spare juniper
#

yeah it looks like view does have a .message

obtuse vale
#

is it normal that tasks.loop is stopping while a slash command is being used?

spare juniper
#

@ancient summit only thing i see right now is perhaps the view wasnt sent with a message?

waxen skiff
#
    @commands.slash_command(guild_ids=[1067194420543377459])
    @discord.option("crop", description="Crop that you want to plant", choices=[crop['name'].title() for crop in crops.crops])
    @discord.option("amount", description="Amount to plant", min_value=1, max_value=max_value(user['farm_level']), required=False, default=None)
    async def plant(self, ctx, crop, amount:int=None):
        user = await utils.get_user(self.bot, ctx.author.id)
``` how could i make the max_value for the amount option based on something in `user`?
#

even could work if i could pass in ctx.author.id into my max_value() function

spare juniper
#

what?

#

what does "even could work" mean?

#

sorry i havent had much sleep i might need to re-read this several times

waxen skiff
#

sorry, its prolly confusing

#

even could work meaning like

spare juniper
#

no wait i understand teh first line

obtuse vale
#

is it normal that tasks.loop is stopping while a slash command is being used?

waxen skiff
#

maybe this?

    @commands.slash_command(guild_ids=[1067194420543377459])
    @discord.option("crop", description="Crop that you want to plant", choices=[crop['name'].title() for crop in crops.crops])
    async def plant(self, ctx: commands.Context, crop, amount:discord.Option(int, "amount", min_value=1, max_value=lambda: await utils.max_plant(commands.Context.author.id), default=None, required=False)):
        user = await utils.get_user(self.bot, ctx.author.id)```
spare juniper
#

i dont think you can do that

#

heres my idea

spare juniper
# waxen skiff maybe this? ```py @commands.slash_command(guild_ids=[1067194420543377459]) ...

when you start the bot, the bot tells discord all the slash command information including the max value for the slash command option

it doesnt run the code, so it doesn't know what user is, and discord prob wont run the code because its not running that command that command for each user

basically the options are constants declared at "build time" you could say and so cannot be changed

waxen skiff
#

i figured

#

so how can i do this

obtuse vale
#

u can change them with autocomplete

spare juniper
#

have no max ig and just check if its over the max and alert the user

waxen skiff
#

run time/compile time btw

spare juniper
#

oh yeah compile time

#

not sure about run time

#

idk

waxen skiff
#

its called run time lol

#

coming from a rust dev

spare juniper
gleaming falcon
#

Slash commands can prompt for attachments in the command fields. Can any Component allow for this, e.g. a button that prompts or some other message interaction? Or the slash command itself is the only way to provide one in any workflow?

full basin
#

Only options

gleaming falcon
#

Thanks! Hopefully this will be enabled elsewhere at some point. I'm trying to revamp some application commands from the jumble of inputs into a View with controls for a slightly more visual experience.

merry briar
#

How is this done? can I link to the right place in the documentation?

errant craneBOT
#

Here's the context menus example.

full basin
full basin
#

¯_(ツ)_/¯

knotty surge
#

Anyway to make a buttons attached to a message?

young bone
knotty surge
#

Thanks mate, anymore contact then that?

spare juniper
knotty surge
#

Thank you

alpine kernel
#

how can i get the id for an emoji like ⚱️ for use in a discord.ui.button there's no id to it, nor can i copy paste it into an editor, doing emoji=';urn;' (semis as regular) gives me invalid emoji, tried without colons too

silver moat
#

and \:urn:

alpine kernel
#

thank you!

silver moat
#

so basically \⚱️

#

you would get the raw unicode emoji by sending it in Discord preceding it with a backslash (escape character)

gleaming falcon
#

Structural question - if I add a View inside my cog (I generally make them separate), this would properly reload them when using reload_extension()? I feel like my external classes aren't properly being updated when I reload my cogs.

alpine kernel
#

last small question, can other users interact with a button that i've invoked the command on?

silver moat
alpine kernel
#

cool i'll add a check then 🙂

silver moat
#

gl

gleaming falcon
#

Also, I forget... am I able to add component classes inside my View, or best if it's not? I sorta remember having some access issues, but maybe I was doing something wrong --

class MyView(discord.ui.View):
  class MyModal(discord.ui.Modal)
    ...

  @discord.ui.button(label='Modal')
  async def invoke(self, button, interaction):
    await interaction.response.send_modal(MyModal())
silver moat
#

yes, but unorganized

gleaming falcon
#

Hm. I thought that would be more organized than having classes sitting out in space. Of course, I'm mostly concerned with being able to reset the cog and have all changes refreshed.

#

Which goes back to my previous question about having Views and other UI classes within my Cog (even if they're not nested within each other)

alpine kernel
#

sorry to ask a question over you again >.<
is there any way to do a callback from the view originator? my command creates a response with a view, but on button press I'd like a callback to the command in a cog for additional actions to be done

#

nm think i found it 🙂

prisma flicker
#

can you have two commands on the same cooldown?

tribal bough
#

code:

    async def callback(self, interaction: discord.Interaction):
        self.button.disabled=True
        msg = self.message
        embed = msg.embeds[0].to_dict()
        embed["fields"][0]["value"] = "{}".format(self.children[0].value)
        newEmbed = discord.Embed.from_dict(embed)
        await msg.edit(embed=newEmbed,view=self)
        await interaction.response("You answered this questions",empheral=True)

error:

Ignoring exception in modal <cogs.views.QuestionModel object at 0x000001A6BAC91730>:
Traceback (most recent call last):
  File "C:\Users\Fammy\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ui\modal.py", line 341, in dispatch
    await value.callback(interaction)
  File "C:\Users\Fammy\Desktop\discord\Keni\cogs\views.py", line 99, in callback
    await msg.edit(embed=newEmbed,view=self)
  File "C:\Users\Fammy\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\message.py", line 1465, in edit
    data = await self._state.http.edit_message(
  File "C:\Users\Fammy\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\http.py", line 366, in request
    raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In components.0.components.0: Value of field "type" must be one of (2, 3, 5, 6, 7, 8).```
severe brook
#

code

async def self(interaction: discord.Interaction):
    message = await interaction.response.send_message(f"Ping!")
    

question: how would i edit the message the bot just sent, I have tried a couple ways but I get a no attribute error

alpine kernel
gleaming falcon
tribal bough
proud mason
#

Yeah that's a good way to do it

alpine kernel
#

anyone mind if i ask a quick database selection question? or will i get bashed over the head

proud mason
#

Sure go ahead

alpine kernel
#

Right now I'm storing data in json files so my instinct is to go with mongodb, but seeing mongodb taking up 1.6gigs on disk (windows) is kinda crazy for my small needs (maybe i installed extra crazy stuff?), and was wondering if you guys have any suggestions.
I wouldnt mind sql lite but I hear it doesnt support multiple simultaneous transactions well, and i dont expect that but i'd like it to handle that situation gracefully

proud mason
proud mason
severe brook
alpine kernel
#

ok, so would you just advise going with sql lite for it's minimalness?

proud mason
alpine kernel
#

okey ty

proud mason
#

If you have a larger database, i suggest going with PostgreSQL

#

It's powerful

alpine kernel
#

yeah I dont expect my project to go further then one discord server or two

proud mason
#

Ah so sqlite should be good

alpine kernel
#

but if a project i ever do explodes I'll worry about that when the time comes heh

proud mason
#

Use asqlite or aiosqlite to connect to it. The built in sqlite3 library is blocking

alpine kernel
#

ty

proud mason
#

Np

gleaming falcon
#

Can a View access cog class it was invoked from? Or perhaps interaction callbacks? I thought there was a link somewhere... or do I have to pass it in?

prisma flicker
sick lake
#

How can I send a message on the on_ready function of the bot?

prisma flicker
green hinge
#

Can I create an input field on Discord other than via modals?
So what I have in mind is a field like autocomplete so that a user can enter something there? 🙂

uneven beacon
#

im new to pycord so i have no idea what my problem is...
can someone help?

full basin
fervent cradle
#

pls help

full basin
#

Because create_task expects an asynchronous function

#

And stop using the requests library for everyone's sake

uneven beacon
#

what am i doing wrong?

full basin
#

The context itself doesn't have that method

#

.rtfm create_text_channel

winter condorBOT
full basin
#

You need a guild or a CategoryChannel

#

The context object has a guild attribute

fervent cradle
full basin
#

First, learn about async functions and how they work. Then learn about async libraries. And then explain what you're trying to do.

uneven beacon
fervent cradle
full basin
uneven beacon
full basin
#

self?

uneven beacon
full basin
#

Because the name of the variable doesn't break it

#

"Doesn't work" doesn't explain what's not working.

#

.idw

winter condorBOT
#

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.

uneven beacon
#

well
same error

uneven beacon
full basin
#

Show the error

uneven beacon
full basin
#

ctx.guild.create_voice_channel(name)

#

No idea why you're passing category= and providing the context object

#

Learn about OOP read the guides

uneven beacon
#

ah

uneven beacon
uneven beacon
hushed cargo
#

Oki

#

Like they right but that wasn’t the nicest way of saying it-

#

Ouuu they typingggg this gonna be interesting:p

full basin
#

You need to get the category first, you can use ctx.guild.get_channel(IDHere) where IDHere is the category ID. Then pass that to the category kwarg

hushed cargo
#

Can confirm

full basin
hushed cargo
#

Oh trust me Ik- sometimes i loveee it when ppl are mean to me

full basin
#

It's not being rude, either way. It's just a message, you don't receive any emotion from it. You see it the way you want.

hushed cargo
#

But like- sometimes being called mean stuff is just 😩

#

So please continue:D

uneven beacon
full basin
#

No

#

get_channel will return a CategoryChannel object

#

Which is what you pass to category=

uneven beacon
#

i see

#

how should i pass it tho?

full basin
#

The function returns the object

#

Assign it to a variable...

uneven beacon
#

ohhhh

#

alright

hushed cargo
#

Category = bla bla bla category id
Await ctx.guild.create thingy (category =Category)

#

Ez

gleaming falcon
#

Do we have a command for a “learn basic python before trying to make a bot” message?

winter condorBOT
#
proud mason
#

and that

gleaming falcon
#

Cool, thanks. It would’ve been helpful for the previous convo in this channel 🙂

swift pumice
#

Are you guys the devs of pycord.wavelength too or is that an independant thing?

grizzled sentinel
#

Yes, but I dont think the project is in production.

young bone
twin fractal
#

How do i add a role to the author, i tried await ctx.author.roles_add(role)
But it’s giving me this:

grizzled sentinel
twin fractal
#

I’m using slash_command from from discord.commands import slash_command

twin fractal
swift pumice
proud mason
swift pumice
#

I didnt know pycord had a package for it, is that imported as a discord component? And does it interact similarly as that package then? I have a working code for the pycord.wavelink package, how simple is migration?

proud mason
#

It is imported as a separate package

#

I think it is import wavelink

fervent cradle
#

how do i set custom status?

umbral island
#

What can cause “Unclosed Client Session” error to happen?

fervent cradle
umbral island
fervent cradle
#

how to fix

#

prints a blank field

#

slash commands btw

proud mason
winter condorBOT
# fervent cradle prints a blank field

https://docs.pycord.dev/en/master/intents.html
https://discord.com/developers/docs/topics/gateway#gateway-intents

import discord
from discord.ext import commands

# Get specific intents for fine control
intents = discord.Intents()
intents.emojis = True
intents.guilds = True
intents.messages = True  # Required for prefix commands!
...
# Get all non-priveliged intents; this excludes presences, members and message_content 
intents = discord.Intents.default()

# Set priveliged intents: these must be enabled on dev portal
intents.members = True
intents.presences = True
intents.message_content = True  # Required for prefix commands >= 2.0.0b5

# Get all intents; all intents must be enabled on dev portal.
intents = discord.Intents.all()

# Apply intents when creating your bot
bot = commands.bot(prefix="?", intents=intents)
Discord Developer Portal

Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.

fervent cradle
green hinge
#

Can I create an input field on Discord other than via modals?
So what I have in mind is a field like autocomplete so that a user can enter something there? 🙂

full basin
#

Command options?

green hinge
# full basin Command options?

So my thought right now is this:
After I click on a button a dropdown menu is shown to me, if I select something here another dropdown menu is shown to me. And if I have selected something there I want an input field where the user can write something in. Is this possible?

full basin
#

Prompt a modal?

green hinge
fervent cradle
#

how do i set arguments when using flags? @proud mason

#

i tried but the flag gives always none

full basin
fervent cradle
green hinge
full basin
#

You'd need to send a button which opens a modal again

green hinge
full basin
#

No

green hinge
# full basin No

Okay 👍🏻
Can I create another dropdown menu when I have made a selection in the first one?

alpine kernel
#

when making views for cleanliness sake, is it common practice put each view into their own .py in a views folder?

waxen skiff
#

i hate how if theres an error in a cog, instead of it telling you theres an error, the cog just doesnt fucking load. wtf

fervent cradle
waxen skiff
#

u want my whole file? lol

#

theres no error idfk where the problem is

fervent cradle
gleaming falcon
#

Is it a linting error? like if you try to execute the cog directly, will it run without error, or do you get some hints there?

waxen skiff
errant craneBOT
waxen skiff
gleaming falcon
#

Might want to show your directory structure.

Mine is something like

bot.py
-- commands\
   mycog.py
   ...
-- utils\
   display.py

Within mycog.py, I can reference utils.display just fine, even though my entry point is bot

waxen skiff
#

that’s how mins is

#

mine*

#

and it doesn’t matter cus it works any other time

gleaming falcon
#

I don't get your sys.path call then.
Presumably if your db modules are in a db directory, your cog should simply be able to directly import db.utils

waxen skiff
#

maybe it can then

#

that’s not my issue though

gleaming falcon
#

Added your file to PyCharm just to see if there was something obvious, but the only errors I'm getting are from db.utils and crops. Although it is warning me about ctx.respond in your plant command, though that would be a runtime error and wouldn't prevent the cog from loading.

waxen skiff
#

yep, i have no idea

#

so dumb

#

it loads fine when i remove this:

#
@discord.option("amount", min_value=1, max_value=100, description="The amount of seeds you want to buy. Leave blank to buy all you can buy (won't automatically buy more than you can plant)", required=False, default=None, type=int)```
waxen skiff
#

well damn, thank you

#

idk how to shorten this...

gleaming falcon
#

"Number of seeds to purchase. Leave empty to buy as many as possible for your farm."
82 characters. I'm sure it could be smoothed out even more

waxen skiff
#

thank you

gleaming falcon
#

fwiw, I always run my bot on a test key using Pycharm's debugging tool, it definitely spits out a lot of these errors. (Discord itself can sometimes be cryptic)

waxen skiff
#

how can i make it wherre only i can run a slash command

errant craneBOT
#

Here's the slash perms example.

waxen skiff
#

this might be it, nvm

#

nope, not it

#

and i dont want an if, i only want it to show up for me

full basin
#

You can't

#

Best workaround is registering it in your dev guild

gleaming falcon
#

Unless I'm misunderstanding, you def can, but you have to manually do it in the Integrations of the Guild/Server

#

Example for a slash command in my own bot

#

Unintuitively, when you select your bot in Integrations, you have to scroll up to get to the command overrides.

full basin
#

There's also @is_owner decorator but it doesn't hide the command

full basin
gleaming falcon
#

For sure, but there was no context on how widespread the bot was. Certainly would make more sense if it's a single-server bot (like mine is). Otherwise, having a command server would be a good solution.

#

(And for the record, I really wish Discord would add that as an API endpoint)

glacial vale
#

when I add a new command to a cog and restart the bot the new command doesnt show up.... what gives?

glacial vale
#

sync?

#

I have a for loop and run this on startup

bot.load_extension(str(dotted_path))
#

dotted_path being the path to each of my cogs

young bone
#

it can take sometimes a short of time that discord shows the new commands

#

and update the commands

glacial vale
#

yea I mean that would be acceptable but it just never shows up

waxen skiff
silver moat
waxen skiff
#
@bot.slash_command(guild_ids=[1067194420543377459])
async def query(ctx, *, str):
    await ctx.message.add_reaction("❌")

'NoneType' object has no attribute 'add_reaction'

fringe socket
#

@waxen whale Rename this thread to "The Basic Pycord Help (The Quick Questions Only)"

spare juniper
#

bfhu

waxen skiff
#

thats pretty much what it is...

spare juniper
#

uhhhh

#

hold on

#

what

spare juniper
limber urchin
waxen skiff
#

thats the issue?

#

how does it not exist

limber urchin
#

How would it exist? When you use a slash command it doesn't create a message

waxen skiff
#

oh duh

#

smh, thanks

spare juniper
#

shit i really need sleep

waxen skiff
#

same...

waxen skiff
#

also wondering why after i run one command, i cant search for any more

#

ill show a screen recording of it

proud mason
#

Wdym by set arguments?

#

You have to define the flags in the class

undone falcon
#

how often does the on_resumed() event is called ? I wanted to use it when my bot reconnect if my internet fails, but it is calling that fonction very often

#

(sometime calling it each 10 minutes)

proud mason
#

Well then your internet must be failing every 10 minutes

undone falcon
#

damn my poor internet

#

I really need to host my bot on a cloud

#

and why do I get guild as . sometimes ?

#

for exemple

proud mason
undone falcon
#

yes !

#

and it only does it sometimes

#

most of the time it works as intended

fervent cradle
#

Why .none() ?

undone falcon
#

wanted to make sure I had no extra intent that I dont need

fervent cradle
#

You just need to enable them yourself

#

By passing those intents and value

undone falcon
#

I see, but it does not change anything tho to the result

fervent cradle
undone falcon
proud mason
proud mason
#

What does it say normally?

#

The name of the guild?

undone falcon
proud mason
#

💀

limber urchin
#

The guild name doesn't turn into ".". You already have a "." in your string

proud mason
#

Oh right

#

I didn't notice that lmao

limber urchin
#

And is there a reason you're using .format instead of just an f-string?

undone falcon
proud mason
#

Those guilds might not be in cache ig. Does on guild remove have a raw event?

limber urchin
#

It's also possible the guilds are just unavailable, in which case the guilds won't have a name (or any data)

copper dew
#

just wondering: is there a way to disable and remove a slash command per guild? the bot that im migrating used to support this feature, since it was prefixed

limber urchin
undone falcon
#

I was just curious

#

and thank you for the answers !

proud mason
proud mason
#

Is champymarty your alt 👀

#

"i was just curious"

"I was just curious"

undone falcon
proud mason
undone falcon
#

ahah not my alt no !

#

strange coincidence !

copper dew
#

oh yeah it's a coincidence

uneven beacon
#

is there any way to add multiple answers for a choice in a slash command?
like if you use "user=discord.Member" you can only choose one user
is there a way to choose multiple?

fervent cradle
#

What's the problem in the code? I can't fix it:

@bot.command(description="Bans a member from the guild")
async def ban(ctx, user: discord.Member, reason: discord.Option(str)):
    if reason is None:
        await ctx.respond("You must provide a reason!", ephemeral=True)
    else:
        banned_user = bot.get_user(user.id)
        await banned_user.send(embed=ban_dm)

        await user.ban(reason=reason)
        await ctx.respond(embed=success)

    
    success = discord.Embed(
        title="Success!",
        description=f"{user.name} has been successfully banned for **{reason}**!"
    )
    ban_dm = discord.Embed(
        title="You've been banned!",
        description=f"**Reason:** {reason}"
    )

This is the error: discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: AttributeError: 'NoneType' object has no attribute 'send'

young bone
#

You already got the User with user:discord.Member

fervent cradle
#

don't i have to use their id?

young bone
#

What?

proud mason
fervent cradle
proven widget
#

i changed the bot photo and name on portal but when the bot is up its not changed how to fix it?

uneven beacon
proud mason
uneven beacon
uneven beacon
#

i have another question
how can i get a channel id by using the name of it?

twin fractal
#

I’m getting this error
My code

@commands.Cog.listener
    async def on_message(msg): 
        for i in range(len(self.data)):
            if (f"<@{self.data[i]}>" in msg.content) and not (msg.author.bot): 
                msg.reply(f"<@{self.data[i]}> is away right now, reason: **{self.data[i+1]}**")
                return None
                break
        if msg.author.id in self.data:
            i = self.data.index(msg.author.id)
            self.data.remove(msg.author.id)
            self.data.remove(self.data[i+1])
            await msg.channel.send(f"{ctx.author.mention} is no longer AFK!")
#

First one is code
Second one is error

#

Wow that copy paste really didn’t work out

young bone
#

where is ()?

twin fractal
young bone
#

add () at the listener

twin fractal
#

Oh ok

fervent cradle
twin fractal
#

now i’m getting this error

young bone
#

self, msg: discord.Message

twin fractal
#

self, f”…” ?

young bone
#

do you know basic python?

twin fractal
#

Uh

#

Kinda?

young bone
#

What do you mean with "Kinda"?

twin fractal
#

I didn’t have the time to learn cause of school

#

And i still only have 1 week of weekend

young bone
#

without the basic´s it will be really hard for you to create a bot

#

that will be the same with any programming language

twin fractal
#

Ik Ik

#

But i just wanna create a server bot

#

For my server

#

Not a public bot, i don’t think it’ll really be that bad

#

i do know a some

young bone
#

It will eat a lot of time

twin fractal
young bone
twin fractal
#

idk bro

uneven beacon
#

how can i get a channel id by using the name of it?

young bone
uneven beacon
#

but i dont know how

young bone
#

discord.utils.get(abc, name="")

young bone
uneven beacon
uneven beacon
young bone
#

did you just copy and paste it?

#

you have to replace abc with stuff like member.guild.channels or other stuff

uneven beacon
#

i did

#

i replaced the abc

#

ctx.guild.get_channel

#

( i have no idea what im doing )

young bone
#

replace it with ctx.guild.channels

uneven beacon
#

it worked
thank you : D

young bone
#

you can do id=ID or name=""

uneven beacon
young bone
grizzled sentinel
#

Also it is always best to ask questions here. If you have a lot fell free to open a thread.

young bone
#

^

fervent cradle
#

what's the difference between cog listener and bot event

proud mason
fervent cradle
#

Alright thanks

green hinge
#

How can I make it so that after I select something in Water, the next dropdown menu is displayed with Fish?

class Wasser(discord.ui.Select):
    def __init__(self, bot: discord.Bot):
        self.bot = bot
        options = [discord.SelectOption(label=water) for water in bot.waters]
        super().__init__(
            placeholder="Wähle das Gewässer aus",
            min_values=1,
            max_values=1,
            options=options,
        )
        
    async def callback(self, interaction: discord.Interaction):
        view = interaction.response.view
        view.add_item(Fisch(self.bot))
        await interaction.response.update(view=view)

class Fisch(discord.ui.Select):
    def __init__(self, bot: discord.Bot):
        self.bot = bot
        options = [discord.SelectOption(label=water) for water in bot.waters]
        super().__init__(
            placeholder="Wähle deinen Fisch aus",
            min_values=1,
            max_values=1,
            options=options,
        )
        
    async def callback(self, interaction: discord.Interaction):
      await interaction.response.send_message(f"Deine Auswahl ist: {self.values[0]}")```
proud mason
fervent cradle
#

Why is it not printing anything?

async def on_ready():
    print('I am online')
Connection = Sql connection line but removed for security reasons yk
Connection.close()
for guilds in bot.guilds:
    print(guilds.id)```
green hinge
# proud mason Interaction.response.edit_message

Where is my mistake?

    await item.callback(interaction)
  File "c:\Users\User\Documents\Coding\OnlyFrames\cogs\spot.py", line 38, in callback
    view = interaction.response.view
AttributeError: 'InteractionResponse' object has no attribute 'view'```
proud mason
proud mason
#

is that in the main file?

fervent cradle
proud mason
fervent cradle
#

on print? im litearly being blind i can tell lol

#

oh

#

im fr stupid

#

sorry @proud mason haha

green hinge
orchid grotto
proud mason
proud mason
proud mason
# orchid grotto

use the discord.option decorator or the discord.Option typehint to set cmd options

green hinge
proud mason
green hinge
rose moon
#

when running my code i get error:

cannot import name 'Option' from 'discord' (/home/container/.local/lib/python3.11/site-packages/discord/init.py)

rose moon
full basin
#

And re-install py-cord

rose moon
proud mason
full basin
#

Then remove it from the requirements file? bruh

proud mason
green hinge
rose moon
proud mason
rose moon
serene spindle
#

which one are you using?

rose moon
#

can i send links here?

young bone
#

Is it replit?

rose moon
#

nope

young bone
#

I use my free RaspberryPi

rose moon
young bone
#

No, but great for bot hosting

serene spindle
#

I use Lightbulb and I have access to the terminal. So I can manage everything with pip myself

rose moon
#

is there any free bot hosting?