# A simple discord bot to allow users to share their favorite coordinates. # There are four commands available : /AddCoords , /ShowAllCoords , /ShowCoords "name" and /DeleteCoords "name" # # To setup the bot : # Edit the script bellow with the name of your global variable holding the bot token (here it is "DISCORD_TOKEN" for reference) # Edit the script bellow the number of your channel ID where the bot operates (here it is 1420839826379682632 for reference) # The bot should have the following rights : message_content and members # All the basic users should not have any rights on the channel dedicated to coordinates beside "View Channel" and "Read Message History" # # Command : AddCoords # Description : Add a set of coordinates # Usage : /AddCoords "name" x y z # Example : /AddCoords "House" 1321 65 711 # /AddCoords "Nether portal" 132 45 1842 # # Command : ShowAllCoords # Description : Show all registered coordinates # Usage : /ShowAllCoords # Example : /ShowAllCoords # Stronghold { 244 ; 11 ; 6299 } # My House { 6423 ; 92 ; 23 } # Nether Portal { 132 ; 45 ; 1842 } # House { 1321 ; 65 ; 711 } # # Command : ShowCoords # Description : Show specifics coordinates using a word filter # Usage : /ShowCoords "name" # Example : /ShowCoords "House" # My House { 6423 ; 92 ; 23 } # House { 1321 ; 65 ; 711 } # # Command : DeleteCoords # Description : Delete a set of coordinates # Usage : /DeleteCoords "name" # Example : /AddCoords "Troll" 99 99 99 # /ShowAllCoords # Troll { 99 ; 99 ; 99 } # Stronghold { 244 ; 11 ; 6299 } # My House { 6423 ; 92 ; 23 } # Nether Portal { 132 ; 45 ; 1842 } # House { 1321 ; 65 ; 711 } # /DeleteCoords "House" # /ShowAllCoords # Stronghold { 244 ; 11 ; 6299 } # My House { 6423 ; 92 ; 23 } # Nether Portal { 132 ; 45 ; 1842 } # House { 1321 ; 65 ; 711 } # import os import discord from dotenv import load_dotenv from discord.ext import commands channelID = 1420839826379682632 load_dotenv() TOKEN = os.getenv("DISCORD_TOKEN") intents = discord.Intents.default() intents.members = True intents.message_content = True bot = commands.Bot(command_prefix='/', intents=intents) @bot.event async def on_ready(): print(f'{bot.user.name} has connected to Discord!') try: channel = bot.get_channel(channelID) except: print(f"Couldn't get the channel, Check the passed channel ID") @bot.command() async def AddCoords(ctx, nameCoord=None, xCoord=None, yCoord=None, zCoord=None): channel = bot.get_channel(channelID) await channel.send(f"{nameCoord.title()} {{ {xCoord} ; {yCoord} ; {zCoord} }}") @bot.command() async def ShowAllCoords(ctx): msgHistory = "" channel = bot.get_channel(channelID) async for message in channel.history(): msgHistory += message.content + "\n" await ctx.send(msgHistory) @bot.command() async def ShowCoords(ctx, nameCoord=None): channel = bot.get_channel(channelID) async for message in channel.history(): if (nameCoord in message.content): await ctx.send(message.content) @bot.command() async def DeleteCoords(ctx, nameCoord=None): channel = bot.get_channel(channelID) async for message in channel.history(): if (nameCoord in message.content): await message.delete() bot.run(TOKEN)