#how to fetch buyer and seller ids?
1 messages · Page 1 of 1 (latest)
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
fetch what? from where?
get the ids from the channel or responses
i dont think you understand python at all
Just get them with guild.get_member? You already have their IDs
no the thing is its for tckets
What?
well the bot is making ticket
You already got the IDs, whatever deal is, you're using deal['seller_id']
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
i need to make variable that holds the id
seller.add_roles(customer)
buyer.add_roles(customer)
Bud
like variable seller and buyer
.
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.
no i mean i dont understand you kinda
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'
The user isn't in the server
yup
And is deal['seller_id'] returning a proper int of a user ID?...
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
well if seller id is already none there's your problem
it cant be
you said it is
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'
?
yeah that's the error
that doesnt say seller id is none at all
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)
is the seller id actually an int?
print isinstance(deal['seller_id'], int)
...
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
well yeah that's my first pycord project
and i'm learning python for like 3 months by now
.
the get_member function takes IDs as ints
if you saved the ID as string, it wont work
yeah lemme check it
it's prob a sting cuz i put it into embeds afterwards
oops
yeah
it's string
then cast it as int
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
'LakfEpgoMccKJ3F4tpcsuBir8jtz4Lpmbu'
This is not a number.
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'
customer is not a .Role object check that.
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
You must first get the role on the server from the .Guild object
i did that in the first 2 lines
Ye
customer = interaction.guild.get_role(customer)
like that?
or should i delete the variable
You can directly pass the ID
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
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
You must save the role, example: role = interaction.guild.get_role(customer) and then add them
yeah but replace the role with customer
Check if it already works
okok
nope
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'
"NoneType" read the error
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)
he told me this
wdym
.get_x
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.
so should i use fetch instead of get?
no
you should use both
oh okay
interaction.guild.fetch_role(customer)
role = interaction.guild.get_role(customer)
like this right?
what?
i'm so confused abt fetching
^
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
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'

Models are classes that are received from Discord and are not meant to be created by the user of the library. Attributes key, url. Methods def is_animated, async read, def replace, async save, def ...
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
@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?
well then what is
why though
that's for you to find out
buyer = interaction.guild.get_member(deal['buyer_id'])
wrong id, ID is not saved as int, etc..
I guess it's not an int because that was already the issue before
then make sure the person is actually in the server, and that it's an int
is the account invoking the command the seller by any chance
wdym
I mean exactly what I said
ah yea
to make it easier can you just show your bot definition and your intent settings in the discord developer website
oh yeah it's not int again
yea
you know what middleman is?
?
yea it doesn't matter now if the int was the issue
so that wouldnt be any error with that
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?
dude
what kind of object has the add_roles method, tell me
i think it's not an object of type int
buyer = int(interaction.guild.get_member(deal['buyer_id']))
an int has add_roles as a method?
so like that?
buyer = interaction.guild.get_member(int(deal['buyer_id']))
yes

