Combreal

coordsBot.py

Aug 27th, 2025
547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.57 KB | Gaming | 0 0
  1. # A simple discord bot to allow users to share their favorite coordinates.
  2. # There are four commands available : /AddCoords   ,   /ShowAllCoords   ,   /ShowCoords "name"    and    /DeleteCoords "name"
  3. #
  4. # To setup the bot :
  5. # Edit the script bellow with the name of your global variable holding the bot token (here it is  "DISCORD_TOKEN" for reference)
  6. # Edit the script bellow the number of your channel ID where the bot operates (here it is 1420839826379682632 for reference)
  7. # The bot should have the following rights : message_content and members
  8. # All the basic users should not have any rights on the channel dedicated to coordinates beside "View Channel" and "Read Message History"
  9. #
  10. # Command : AddCoords
  11. # Description : Add a set of coordinates
  12. # Usage : /AddCoords "name" x y z
  13. # Example : /AddCoords "House" 1321 65 711
  14. #           /AddCoords "Nether portal" 132 45 1842
  15. #
  16. # Command : ShowAllCoords
  17. # Description : Show all registered coordinates
  18. # Usage : /ShowAllCoords
  19. # Example : /ShowAllCoords
  20. #           Stronghold      { 244 ; 11 ; 6299 }
  21. #           My House      { 6423 ; 92 ; 23 }
  22. #           Nether Portal      { 132 ; 45 ; 1842 }
  23. #           House      { 1321 ; 65 ; 711 }
  24. #
  25. # Command : ShowCoords
  26. # Description : Show specifics coordinates using a word filter
  27. # Usage : /ShowCoords "name"
  28. # Example : /ShowCoords "House"
  29. #           My House      { 6423 ; 92 ; 23 }
  30. #           House      { 1321 ; 65 ; 711 }
  31. #
  32. # Command : DeleteCoords
  33. # Description : Delete a set of coordinates
  34. # Usage : /DeleteCoords "name"
  35. # Example : /AddCoords "Troll" 99 99 99
  36. #           /ShowAllCoords
  37. #           Troll      { 99 ; 99 ; 99 }
  38. #           Stronghold      { 244 ; 11 ; 6299 }
  39. #           My House      { 6423 ; 92 ; 23 }
  40. #           Nether Portal      { 132 ; 45 ; 1842 }
  41. #           House      { 1321 ; 65 ; 711 }
  42. #           /DeleteCoords "House"
  43. #           /ShowAllCoords
  44. #           Stronghold      { 244 ; 11 ; 6299 }
  45. #           My House      { 6423 ; 92 ; 23 }
  46. #           Nether Portal      { 132 ; 45 ; 1842 }
  47. #           House      { 1321 ; 65 ; 711 }
  48. #
  49.  
  50. import os
  51. import discord
  52. from dotenv import load_dotenv
  53. from discord.ext import commands
  54.  
  55. channelID = 1420839826379682632
  56.  
  57. load_dotenv()
  58. TOKEN = os.getenv("DISCORD_TOKEN")
  59.  
  60. intents = discord.Intents.default()
  61. intents.members = True
  62. intents.message_content = True
  63. bot = commands.Bot(command_prefix='/', intents=intents)
  64.  
  65. @bot.event
  66. async def on_ready():
  67.     print(f'{bot.user.name} has connected to Discord!')
  68.     try:
  69.         channel = bot.get_channel(channelID)
  70.     except:
  71.         print(f"Couldn't get the channel, Check the passed channel ID")
  72.    
  73. @bot.command()
  74. async def AddCoords(ctx, nameCoord=None, xCoord=None, yCoord=None, zCoord=None):
  75.     channel = bot.get_channel(channelID)
  76.     await channel.send(f"{nameCoord.title()}      {{ {xCoord} ; {yCoord} ; {zCoord} }}")
  77.  
  78. @bot.command()
  79. async def ShowAllCoords(ctx):
  80.     msgHistory = ""
  81.     channel = bot.get_channel(channelID)
  82.     async for message in channel.history():
  83.         msgHistory += message.content + "\n"
  84.     await ctx.send(msgHistory)
  85.  
  86. @bot.command()
  87. async def ShowCoords(ctx, nameCoord=None):
  88.     channel = bot.get_channel(channelID)
  89.     async for message in channel.history():  
  90.         if (nameCoord in message.content):
  91.             await ctx.send(message.content)
  92.  
  93. @bot.command()
  94. async def DeleteCoords(ctx, nameCoord=None):
  95.     channel = bot.get_channel(channelID)
  96.     async for message in channel.history():  
  97.         if (nameCoord in message.content):
  98.             await message.delete()
  99.  
  100. bot.run(TOKEN)
Advertisement