#how to fetch buyer and seller ids?

1 messages · Page 1 of 1 (latest)

lunar yew
#

.

#
async def confirm(dealid, status, interaction):
    for dealid in deals:
        deal = deals[dealid]
        if deal['channel'].id != interaction.channel.id:
            return
        
        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())
                return
        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'))
                await asyncio.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 5 minutes\n**SAVE YOUR PRODUCT IF THE SELLER SENT IT HERE**",
                      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")
                seller.add_roles(customer)
                buyer.add_roles(customer)

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

i jst need variable so it gets the buyer and seller id

#

but idk how to fetch it

fading pelican
#

fetch what? from where?

lunar yew
#

get the ids from the channel or responses

fading pelican
#

i dont think you understand python at all

burnt sigil
lunar yew
burnt sigil
#

What?

lunar yew
#

well the bot is making ticket

burnt sigil
#

You already got the IDs, whatever deal is, you're using deal['seller_id']

lunar yew
#

yeah

#

but like what do i do then

burnt sigil
#

You already got the IDs then

#

Do whatever you need to do with the IDs

#

The only issue you specified is how to fetch the IDs

lunar yew
#

i need to make variable that holds the id

#

seller.add_roles(customer)
buyer.add_roles(customer)

burnt sigil
#

Bud

lunar yew
#

like variable seller and buyer

burnt sigil
#

You need the member object. seller will be a member instance.

#

You got the ID, you get the member.

#

I don't know what's confusing about that, consider reading your own code if you don't know what data you're handling.

lunar yew
#

no i mean i dont understand you kinda

burnt sigil
#

bruh

#

seller = interaction.guild.get_member(deal['seller_id'])

lunar yew
#

so like guild.get_member(deal['seller_id')]?

#

yeah okay

#

thanks

#

@burnt sigil

#

Traceback (most recent call last):
File "C:\Users\uuu\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ui\view.py", line 427, in _scheduled_task
await item.callback(interaction)
File "C:\Users\uuu\Downloads\Lynx_Auto\Lynx Auto\main.py", line 200, in callback
await self.confirm_product(status, interaction)
File "C:\Users\uuu\Downloads\Lynx_Auto\Lynx Auto\main.py", line 177, in confirm_product
await confirm(deal, 'T', interaction)
File "C:\Users\uuu\Downloads\Lynx_Auto\Lynx Auto\main.py", line 233, in confirm
seller.add_roles(customer)
AttributeError: 'NoneType' object has no attribute 'add_roles'

burnt sigil
#

The user isn't in the server

lunar yew
#

he is

#

that's the thing

burnt sigil
#

Do you have guild members intents?

#

It is a privileged intent.

lunar yew
#

yup

burnt sigil
#

And is deal['seller_id'] returning a proper int of a user ID?...

lunar yew
#

should be

#

i'll try print it 1 sec

#

well i get the seller id

#

but not buyer

#

but still it says that seller id is nonetype

fading pelican
#

well if seller id is already none there's your problem

lunar yew
#

it cant be

fading pelican
#

you said it is

lunar yew
#

cuz it prints out the seller id

#

556400559318368277
[2024-06-08 18:59:02] [ERROR ] discord.ui.view: Ignoring exception in view <confirmProductbuttons timeout=None children=2> for item <Button style=<ButtonStyle.success: 3> url=None disabled=False label='Product Received!' emoji=None row=None>
Traceback (most recent call last):
File "C:\Users\uuu\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ui\view.py", line 427, in _scheduled_task
await item.callback(interaction)
File "C:\Users\uuu\Downloads\Lynx_Auto\Lynx Auto\main.py", line 200, in callback
await self.confirm_product(status, interaction)
File "C:\Users\uuu\Downloads\Lynx_Auto\Lynx Auto\main.py", line 177, in confirm_product
await confirm(deal, 'T', interaction)
File "C:\Users\uuu\Downloads\Lynx_Auto\Lynx Auto\main.py", line 233, in confirm
seller.add_roles(customer)
AttributeError: 'NoneType' object has no attribute 'add_roles'

fading pelican
lunar yew
fading pelican
#

that doesnt say seller id is none at all

lunar yew
#

well what's the issue with it

#
       print (deal['channel'])
        print(deal['buyer_id'])
        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())
                return
        if status == 'T':
                channel = bot.get_channel(deal['channel'].id)
                print(deal['seller_id'])
                print(deal['buyer_id'])
                await channel.send(embed=succeed('**Product Confirmed!**\nThe product has been confirmed and we will now send the money to the seller'))
                await asyncio.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 5 minutes\n**SAVE YOUR PRODUCT IF THE SELLER SENT IT HERE**",
                      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")
                seller = interaction.guild.get_member(deal['seller_id'])
                buyer = interaction.guild.get_member(deal['buyer_id'])
                seller.add_roles(customer)
                buyer.add_roles(customer)
fading pelican
#

is the seller id actually an int?

lunar yew
#

well should be

#

should i jst make it int?

#

just incase it's not

fading pelican
#

print isinstance(deal['seller_id'], int)

lunar yew
#

int(seller).add_roles(customer)
int(buyer).add_roles(customer)

#

did it like this

fading pelican
#

...

#

since when does an int object have add_roles as a method?

#

I dont mean to offend but i think you should learn python a bit better before diving into pycord

lunar yew
#

well yeah that's my first pycord project

#

and i'm learning python for like 3 months by now

fading pelican
#

the get_member function takes IDs as ints
if you saved the ID as string, it wont work

lunar yew
#

yeah lemme check it

#

it's prob a sting cuz i put it into embeds afterwards

#

oops

#

yeah

#

it's string

fading pelican
#

then cast it as int

lunar yew
#

yeah

#

changed it to
seller = interaction.guild.get_member(int(deal['seller_id']))
buyer = interaction.guild.get_member(int(deal['buyer_id']))

#
[2024-06-08 19:20:18] [ERROR   ] discord.ui.view: Ignoring exception in view <confirmProductbuttons timeout=None children=2> for item <Button style=<ButtonStyle.success: 3> url=None disabled=False label='Product Received!' emoji=None row=None>
Traceback (most recent call last):
  File "C:\Users\uuu\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ui\view.py", line 427, in _scheduled_task
    await item.callback(interaction)
  File "C:\Users\uuu\Downloads\Lynx_Auto\Lynx Auto\main.py", line 200, in callback
    await self.confirm_product(status, interaction)
  File "C:\Users\uuu\Downloads\Lynx_Auto\Lynx Auto\main.py", line 177, in confirm_product
    await confirm(deal, 'T', interaction)
  File "C:\Users\uuu\Downloads\Lynx_Auto\Lynx Auto\main.py", line 231, in confirm
    seller = interaction.guild.get_member(int(deal['seller_id']))
ValueError: invalid literal for int() with base 10: 'LakfEpgoMccKJ3F4tpcsuBir8jtz4Lpmbu'
#

got this error now

whole light
#

'LakfEpgoMccKJ3F4tpcsuBir8jtz4Lpmbu'

This is not a number.

lunar yew
#

i found the issue now i think

#

used seller_id instead of owner

#

and owner stores the member id

#

yeah i think i fixed it

#

what the hell

#
[2024-06-08 19:28:22] [ERROR   ] discord.ui.view: Ignoring exception in view <confirmProductbuttons timeout=None children=2> for item <Button style=<ButtonStyle.success: 3> url=None disabled=False label='Product Received!' emoji=None row=None>
Traceback (most recent call last):
  File "C:\Users\uuu\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ui\view.py", line 427, in _scheduled_task
    await item.callback(interaction)
  File "C:\Users\uuu\Downloads\Lynx_Auto\Lynx Auto\main.py", line 200, in callback
    await self.confirm_product(status, interaction)
  File "C:\Users\uuu\Downloads\Lynx_Auto\Lynx Auto\main.py", line 177, in confirm_product
    await confirm(deal, 'T', interaction)
  File "C:\Users\uuu\Downloads\Lynx_Auto\Lynx Auto\main.py", line 233, in confirm
    await seller.add_roles(customer)
  File "C:\Users\uuu\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\member.py", line 1051, in add_roles
    await req(guild_id, user_id, role.id, reason=reason)
AttributeError: 'int' object has no attribute 'id'
whole light
#

customer is not a .Role object check that.

lunar yew
#

seller = interaction.guild.get_member(int(deal['owner']))
buyer = interaction.guild.get_member(int(deal(['buyer_id'])))
await seller.add_roles(customer)
await buyer.add_roles(customer)

#

how to fix that

#

wait no

#

mb

whole light
#

You must first get the role on the server from the .Guild object

lunar yew
lunar yew
#

oh

#

so guild.get_role(#role)?

whole light
lunar yew
#

customer = interaction.guild.get_role(customer)

#

like that?

#

or should i delete the variable

whole light
#

You can directly pass the ID

lunar yew
#

so remove the variable

#

cuz it's not needed

whole light
#

If you need the ID later in your code you can leave it like this. If you only need to get the role you can directly pass the ID in the get_role() method

lunar yew
#

ion need it

#

interaction.guild.get_role(customer)
seller = interaction.guild.get_member(deal['owner'])
buyer = interaction.guild.get_member(deal['buyer_id'])

#

so like this

whole light
#

You must save the role, example: role = interaction.guild.get_role(customer) and then add them

lunar yew
#

yeah but replace the role with customer

whole light
#

Check if it already works

lunar yew
#

okok

lunar yew
#

didnt fix it

#

Traceback (most recent call last):
File "C:\Users\uuu\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ui\view.py", line 427, in _scheduled_task
await item.callback(interaction)
File "C:\Users\uuu\Downloads\Lynx_Auto\Lynx Auto\main.py", line 200, in callback
await self.confirm_product(status, interaction)
File "C:\Users\uuu\Downloads\Lynx_Auto\Lynx Auto\main.py", line 177, in confirm_product
await confirm(deal, 'T', interaction)
File "C:\Users\uuu\Downloads\Lynx_Auto\Lynx Auto\main.py", line 236, in confirm
await buyer.add_roles(role)
AttributeError: 'NoneType' object has no attribute 'add_roles'

neon totem
#

"NoneType" read the error

lunar yew
#

yeah ik

#

but why

#

role = interaction.guild.get_role(customer)
seller = interaction.guild.get_member(deal['owner'])
buyer = interaction.guild.get_member(deal['buyer_id'])
await seller.add_roles(role)
await buyer.add_roles(role)

neon totem
#

so, what happend when you do a get_x?

#

and we already told you what you have to do

lunar yew
neon totem
#

.get_x

frosty palmBOT
#

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.

lunar yew
#

so should i use fetch instead of get?

neon totem
#

no

whole light
#

iInteraction's hmmm .guild does not have these methods. I did not realize

neon totem
#

you should use both

lunar yew
#

oh okay

#

interaction.guild.fetch_role(customer)
role = interaction.guild.get_role(customer)

#

like this right?

neon totem
#

what?

lunar yew
#

i'm so confused abt fetching

neon totem
#

get_x is looking at your cache

#

fetch is doing an API call to discord

lunar yew
#

thats what i asked

#

to use fetch instead of get there

lunar yew
#

so i should use fetch in that line

#

instead of get

neon totem
#

read that again

lunar yew
#

yeah

#

so

#

just

#

use the fetch

#

or idfk what u want me to know

#

cuz its not in the bot cache atm

#

since i never used the role

#

in the code

#

@neon totem

neon totem
#

you do a check if get_x is none and if its none you gonna do a fetch_x

lunar yew
#

yeh

#

that

#

is what i wanted to do

#

since get didnt work

lunar yew
# neon totem you do a check if get_x is none and if its none you gonna do a fetch_x
Traceback (most recent call last):
  File "C:\Users\uuu\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ui\view.py", line 427, in _scheduled_task
    await item.callback(interaction)
  File "C:\Users\uuu\Downloads\Lynx_Auto\Lynx Auto\main.py", line 200, in callback
    await self.confirm_product(status, interaction)
  File "C:\Users\uuu\Downloads\Lynx_Auto\Lynx Auto\main.py", line 177, in confirm_product
    await confirm(deal, 'T', interaction)
  File "C:\Users\uuu\Downloads\Lynx_Auto\Lynx Auto\main.py", line 233, in confirm
    role = interaction.guild.fetch_role(customer)
AttributeError: 'Guild' object has no attribute 'fetch_role'
fading pelican
#

we aren't here to regurgitate the docs to you, we're here to help with issues that go beyond what can be reasonably solved by reading the docs

lunar yew
#

@neon totem

#

i have another issue

#

cuz like

#
    
    if status == 'T':
                channel = bot.get_channel(deal['channel'].id)
                print(deal['owner'])
                print(deal['buyer_id'])
                await channel.send(embed=succeed('**Product Confirmed!**\nThe product has been confirmed and we will now send the money to the seller'))
                await asyncio.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 5 minutes\n**SAVE YOUR PRODUCT IF THE SELLER SENT IT HERE**",
                      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")

                
                print(deal['buyer_id'] + " role")
                role =  interaction.guild.get_role(customer)
                seller =  interaction.guild.get_member(deal['owner'])
                buyer = interaction.guild.get_member(deal['buyer_id'])
                await seller.add_roles(role)
                await buyer.add_roles(role)
#

tho when i print out the print(deal['buyer_id'] + " role")

#

i get 828956748487852043 role which is correct

#

but then i get this error

[2024-06-08 22:33:48] [ERROR   ] discord.ui.view: Ignoring exception in view <confirmProductbuttons timeout=None children=2> for item <Button style=<ButtonStyle.success: 3> url=None disabled=False label='Product Received!' emoji=None row=None>
Traceback (most recent call last):
  File "C:\Users\uuu\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ui\view.py", line 427, in _scheduled_task
    await item.callback(interaction)
  File "C:\Users\uuu\Downloads\Lynx_Auto\Lynx Auto\main.py", line 201, in callback
    await self.confirm_product(status, interaction)
  File "C:\Users\uuu\Downloads\Lynx_Auto\Lynx Auto\main.py", line 178, in confirm_product
    await confirm(deal, 'T', interaction)
  File "C:\Users\uuu\Downloads\Lynx_Auto\Lynx Auto\main.py", line 239, in confirm
    await buyer.add_roles(role)
AttributeError: 'NoneType' object has no attribute 'add_roles'
#

or does anybody know how to fix it?

fading pelican
#

read the last one of the stacktrace

#

buyer is none

lunar yew
#

but when i print it out

#

it shows the buyer id

fading pelican
#

great

#

that's not the problem here

#

buyer is None, not buyer id

lunar yew
#

well then what is

lunar yew
fading pelican
#

that's for you to find out

lunar yew
#
buyer = interaction.guild.get_member(deal['buyer_id'])
fading pelican
#

wrong id, ID is not saved as int, etc..

#

I guess it's not an int because that was already the issue before

lunar yew
#

it should be int

#

cuz the seller works

#

but not the buyer

fading pelican
#

then check.

#

and make sure that the ID is actually correct

lunar yew
#

yeah okay

#

id is 100% correct

#

checked it lots of times

fading pelican
#

then make sure the person is actually in the server, and that it's an int

lunar yew
#

yeah checking the int now

#

i use alt for testing it so i'm definetly in the server

fading pelican
#

is the account invoking the command the seller by any chance

lunar yew
#

wdym

fading pelican
#

I mean exactly what I said

lunar yew
#

ugh lemme jst translate it

#

you might have a mistake there

#

ugh

#

there's no command

fading pelican
#

ah yea
to make it easier can you just show your bot definition and your intent settings in the discord developer website

lunar yew
#

oh yeah it's not int again

fading pelican
#

yea

fading pelican
#

?

lunar yew
#

it's the bot definiton

#

but i have all intents on

fading pelican
#

yea it doesn't matter now if the int was the issue

lunar yew
#

so that wouldnt be any error with that

lunar yew
# fading pelican yea it doesn't matter now if the int was the issue

Traceback (most recent call last):
File "C:\Users\uuu\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ui\view.py", line 427, in _scheduled_task
await item.callback(interaction)
File "C:\Users\uuu\Downloads\Lynx_Auto\Lynx Auto\main.py", line 201, in callback
await self.confirm_product(status, interaction)
File "C:\Users\uuu\Downloads\Lynx_Auto\Lynx Auto\main.py", line 178, in confirm_product
await confirm(deal, 'T', interaction)
File "C:\Users\uuu\Downloads\Lynx_Auto\Lynx Auto\main.py", line 238, in confirm
buyer = int(interaction.guild.get_member(deal['buyer_id']))
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

#

is it because the buyer_id is a list not string?

fading pelican
#

dude

#

what kind of object has the add_roles method, tell me

#

i think it's not an object of type int

lunar yew
fading pelican
#

an int has add_roles as a method?

lunar yew
#

so like that?
buyer = interaction.guild.get_member(int(deal['buyer_id']))

fading pelican
#

yes

lunar yew
#

oh ok

#

awesome

#

it works

#

thanks