Guest User

Untitled

a guest
Oct 31st, 2023
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. ```@bot.event
  2. async def on_message(message):
  3. if message.author.bot:
  4. return
  5.  
  6. if "traded with" in message.content:
  7. mentioned_user = message.mentions[0] # Assuming only one user is mentioned
  8. channel = message.channel
  9.  
  10. # Send a reaction to the initial trade message
  11. await message.add_reaction(":hourglass:") # Awaiting confirmation
  12.  
  13. await confirmation_trade(mentioned_user, message.author, message)
  14.  
  15. async def confirmation_trade(mentioned_user, initial_user, initial_message):
  16. def check(m):
  17. return m.author == mentioned_user and m.content.lower() in ['confirm', 'confirmed']
  18.  
  19. try:
  20. response = await bot.wait_for('message', timeout=60.0, check=check)
  21. except nextcord.ext.TimeoutError:
  22. await initial_message.edit(content="Trade confirmation timed out. Trade not confirmed.")
  23. await initial_message.clear_reaction(":hourglass:")
  24. else:
  25. # Update user roles after confirmation
  26. guild = initial_message.guild
  27. roles = [role for role in guild.roles if role.name.isdigit()]
  28. roles.sort(key=lambda role: int(role.name))
  29.  
  30. for user in [mentioned_user, initial_user]:
  31. user_roles = user.roles
  32. role_names = [str(role.name) for role in user_roles]
  33.  
  34. user_role_integers = [int(name) for name in role_names if name.isdigit()]
  35.  
  36. current_role = max(user_role_integers + [0])
  37. next_role_name = str(current_role + 1)
  38.  
  39. if next_role_name not in role_names:
  40. for role in roles:
  41. if role.name == next_role_name:
  42. await user.add_roles(role)
  43.  
  44. role_to_remove = nextcord.utils.get(roles, name=str(current_role))
  45. if role_to_remove:
  46. await user.remove_roles(role_to_remove)
  47.  
  48. await initial_message.add_reaction(":white_check_mark:")
  49. await initial_message.clear_reaction(":hourglass:")```
Advertisement
Add Comment
Please, Sign In to add comment