From 57243190410ca6e6dd536829611354e29d89fc86 Mon Sep 17 00:00:00 2001 From: Brandon4466 Date: Mon, 5 Jun 2023 14:00:18 -0700 Subject: [PATCH] first push --- bot.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 bot.py diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..295d8cf --- /dev/null +++ b/bot.py @@ -0,0 +1,30 @@ +import discord + +token = "MTA5MTE1NTg0MTMyMDc2MzUzNA.Gy-9Nx.do835DtdAXQz8Un5SGGr7WJY3u4CR-m2ytJKho" + +client = discord.Client(intents=discord.Intents.all()) # Create a new client instance +tree = discord.app_commands.CommandTree(client) + +@tree.command(name="status", description="Get the status of the bot.", guild=discord.Object(id=1093674638401351713)) +async def status(interaction): + await interaction.response.send_message("I'm online!") + +@client.event # Event decorator/wrapper +async def on_ready(): # When the bot is ready + await tree.sync(guild=discord.Object(id=1093674638401351713)) + print(f'{client.user} has connected to Discord!') # Print a message to the console + +@client.event # Event decorator/wrapper +async def on_message(message): # When a message is sent + channel = message.channel + if "http://" in message.content or "https://" in message.content and "bot" not in {channel.name}: # If the message contains a link and the channel is not a bot channel + try: + await message.delete() + print(f"Deleted message from @{message.author} in #{message.channel} because it contained a link.") + botchannel = client.get_channel(866994241490386956) # Get the channel with the ID 1234567890 + await botchannel.send(f"Deleted message from @{message.author} in #{message.channel} because it contained a link:\n{message.content}") + + except discord.errors.Forbidden: + print(f"Couldn't delete message from @{message.author} in #{message.channel} because I don't have permission.") + +client.run(token) # Run the bot with the token \ No newline at end of file