#how to fix this?

1 messages Β· Page 1 of 1 (latest)

steel current
#

what is "deal"

#

and ...

#

.get_x

arctic slateBOT
#

Any function that starts with get_ in Py-cord is retrieving the related object from your bots cache. If the object is not in the bots cache the get_ method will return None. Because of this behavior you should check if the get_x method is None and if it is use the fetch_x method.

Why Is Using fetch_ Without Using get_ First Bad?
The fetch_ method makes a call to the discord API. This API call is unneeded if you already have the information. It will also make your command take longer because it will have to send and than wait for a response from the discord API. It will also contribute to the discord APIs global rate limit of 50 requests per second.

What Is Cache?
The cache is a temporary storage inside your bot. It holds many objects from members to messages. When you restart your bot the cache will be empty. When the cache is full it will delete older objects to make space for the new objects.

astral summit
#

if you mean that

#

chatgpt told me that channel variable doesnt have value but it does

long nest
#

it obviously doesnt

#

and the error literally tells you that

astral summit
#

yeah but it should

long nest
#

But it doesnt

astral summit
#

i didnt put whole code there

#

wait

#
async def confirm(dealid, status, interaction):
    for dealid in deals:
        deal = deals[dealid]
        if deal['channel'].id == interaction.channel.id:
            print (deal['channel'])
            if status == 'F':
                channel = bot.get_channel(deal['channel'].id)
                await channel.send(embed=fail('**Product Missing!**\n The product has been marked as missing. Open a dispute if this is wrong'))
                await channel.send(embed=info('Close ticket'), view=CloseTicket())
            if status == 'T':
                channel = bot.get_channel(deal['channel'].id)
                print(deal['seller_id'])
                await channel.send(embed=succeed('**Product Confirmed!**\nThe product has been confirmed and we will now send the money to the seller'))
                time.sleep(5)
                send_ltc(deal['key'],deal['seller_id'],usd_to_satoshis(deal['usd']))
                embed4= discord.Embed(title="βœ… Middleman deal has been completed",
                      description=f"This ticket will be automatically closed in 30 seconds",
                      colour=0x00b0f4)

                embed4.set_author(name="Lynx auto",
                         icon_url="https://i.pinimg.com/originals/d9/9d/2a/d99d2a8400765209c10d9c467c8bfe98.png")

                embed4.set_thumbnail(url="https://i.pinimg.com/originals/d9/9d/2a/d99d2a8400765209c10d9c467c8bfe98.png")


                await channel.send(embed = embed4)
                time.sleep(1)

                channel = bot.get_channel(completed)
                embed5= discord.Embed(title="βœ… Deal completed",
                      description=f"The 
#
middleman deal has been successfully completed (<@{deal['owner']}> <@{deal['buyer_id']}>",
                      colour=0x00b0f4)

                embed5.set_author(name="Lynx auto",
                         icon_url="https://i.pinimg.com/originals/d9/9d/2a/d99d2a8400765209c10d9c467c8bfe98.png")

                embed5.set_thumbnail(url="https://i.pinimg.com/originals/d9/9d/2a/d99d2a8400765209c10d9c467c8bfe98.png")
                await channel.send(embed = embed5)
                time.sleep(30)
                channel = bot.get_channel(deal['channel'].id)
                await channel.delete()
long nest
#

great, but the issue doesnt change

astral summit
#

so it cant find the channel id?

#

it gets stuck on the 2nd message

long nest
astral summit
#

and the id is clearly there

astral summit
#

do yk how to fix it?

astral summit
#

i'm stuck on this for 30 mins

#

channel = bot.fetch_channel(completed)

#

so jst change it to that?

#

i didnt cache stuff yet so thats why im askin

long nest
astral summit
#

or idk lmao

long nest
#

that is not something you do manually.

#

its a default built in library feature

astral summit
#

oh

#

so what should i change in the code

#

if u could help

steel current
#

so simple, you first do a get_x if its None you gonna do a fetch_x

astral summit
#

did it with fetch now

#

got the same error

steel current
#

which error?

astral summit
steel current
#

I really like it that my Internet is so bad that I cannot load images... its so annoying

long nest
#

show your code

astral summit
steel current
#

you still use fetch and get

#

you have to use both in one and you overwrite channel again at the end

astral summit
#

wait

#

so

steel current
#

also if you use time.sleep

#

you gonna block your whole bot

astral summit
#

should i use fetch everywhere instead of get?

astral summit
steel current
#

doesnt matter how many seconds

astral summit
#

wait im confused af now

#

i used get all the time

astral summit
steel current
#

That is not gonna be to rude or anything but do you know basic Python?

long nest
astral summit
#

this is my frist bigger project

astral summit
steel current
#

and you never used asyncio?

astral summit
#

the 2nd one from bottom is alr

astral summit
long nest
#

are you sure your bot can actually see that channel?
and that the channel ID is correct?

long nest
astral summit
#

that's where it bugs out

astral summit
#

or wait

#

lemme jst test it with print

long nest
#

also i may be blind but where do you even set completed

astral summit
#

8

long nest
#

i cant see it in your code

astral summit
astral summit
steel current
long nest
steel current
#

not at int

astral summit
#

fck

#

im dumb

#

πŸ’€

long nest
#

then you can also change back to get

astral summit
#

used wrong thingys

steel current
#

you did ""

astral summit
#

thanks guys

#

i didnt think of that at all

astral summit
long nest
astral summit
#

oh

#

smt like libraries right

#

diff file but same class

long nest
#

No, its just classes

#

nothing to do with library

astral summit
#

yeah i meant library like a different file

long nest
#

then call it different file :>

astral summit
#

okok

empty yoke
astral summit
#

thanks

empty yoke
#

You need to await the fetcj

#

Ok mb

astral summit
#

no need to fetch

#

i jst accidentally made channel id a string

empty yoke
#

fetch can be still useful

#

In case the bot doesn’t find the cache

astral summit
#

huhh

#

it didnt get fixed

#

wth

#

@long nest

#

gettin this now

steel current
#

so what do you have to do?

astral summit
#

fetch?

astral summit
#

ok

long nest
#

make sure the ID is right and that the bot can see the channel first of all

steel current
#
channel: discord.TextChannel = bot.get_channel(ID) or await bot.fetch_channel(ID)
astral summit
#

and then try it again i assume

astral summit
#

ok fixed it now

#

but

#

sleep was never awaited

long nest
#

then await it

astral summit
#

oop

#

yeah

#

forgot to do that

#

mb

#

@long nest

#

idk if im dumb

#

but the bot doesnt send the deal completed msg

#

no error nothing

#

and it closes the ticket right away

#
 embed4= discord.Embed(title="βœ… Middleman deal has been completed",
                      description=f"This ticket will be automatically closed in 30 seconds",
                      colour=0x00b0f4)

                embed4.set_author(name="Lynx auto",
                         icon_url="https://i.pinimg.com/originals/d9/9d/2a/d99d2a8400765209c10d9c467c8bfe98.png")

                embed4.set_thumbnail(url="https://i.pinimg.com/originals/d9/9d/2a/d99d2a8400765209c10d9c467c8bfe98.png")


                await channel.send(embed = embed4)
                await asyncio.sleep(1)

                discord.TextChannel = bot.get_channel(completed)
                embed5= discord.Embed(title="βœ… Deal completed",
                      description=f"The middleman deal has been successfully completed (<@{deal['owner']}> <@{deal['buyer_id']}>",
                      colour=0x00b0f4)

                embed5.set_author(name="Lynx auto",
                         icon_url="https://i.pinimg.com/originals/d9/9d/2a/d99d2a8400765209c10d9c467c8bfe98.png")

                embed5.set_thumbnail(url="https://i.pinimg.com/originals/d9/9d/2a/d99d2a8400765209c10d9c467c8bfe98.png")
                await channel.send(embed = embed5)
                await asyncio.sleep(30)

                channel = bot.get_channel(deal['channel'].id)
                await channel.delete()
long nest
#

what in the fuck are you doing

#

channel = ...

astral summit
#

now it wont work again

long nest
#

there is a very, very big difference between what you did and between zervy's snippet

#

just do channel =

astral summit
#

okay lemme try now

astral summit
#

cant just do channel =

long nest
#

then fix your code

long nest
astral summit
#

well i jst tried whatever he sent me

#

and it worked

#

im trying to fetch it now

#

ok yeah fetching worked

#

but

#

it sends the msg into ticket but not to the channel i want it to

steel current
long nest
#

no, you didnt do anything wrong

astral summit
#

to make it send the msg into the copleted channel

long nest
#

read the code and check where the issue iis

#

youre not setting the channel correctly then

#

we cant do everything for you

astral summit
#

yeah i'm lookin into it

#

but if i fetch the channel

#

it will send it there wont it?

#

or it wont change the chanel variable

long nest
#

all im saying is is that if it sends into the wrong channel, you set the channel variable to the wrong channel

astral summit
#

okay no

#

im dumb

#

i didnt even add the variable there

#

await bot.fetch_channel(completed)
channel = completed

#

would this switch it?

long nest
#

please read that and think real hard

#

that is most basic python

astral summit
#

i'm half asleep rn

#

my brain doesnt think as it should sorry lmao

#

...

#

yeh ik what to do now i think

#

got it