File size: 1,450 Bytes
bd28673 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import discord
import os
import threading
from discord.ext import commands
#
# Set up discord bot
intents = discord.Intents.default()
intents.message_content = True
intents.messages = True
bot = commands.Bot(command_prefix="!", intents=intents)
@bot.event
async def on_ready():
print('Logged on as', bot.user)
@bot.command(name='shutdown', hidden=True)
@commands.is_owner()
async def shutdown(ctx):
await ctx.send('Shutting down...')
await bot.close()
@bot.event
async def on_message(message):
# don't respond to ourselves
if message.author == bot.user:
return
await bot.process_commands(message)
@bot.event
async def on_message_delete(message):
log_channel_id = 1104111048614752466 # 1104111048614752466 = lunarlogs
log_channel = bot.get_channel(log_channel_id)
if log_channel:
embed = discord.Embed(title="Message Deleted", description=f"Author: {message.author.mention}\nContent: {message.content}", color=discord.Color.red())
await log_channel.send(embed=embed)
DISCORD_TOKEN = os.environ.get("LUNARBOT_TOKEN", None)
def run_bot():
try:
bot.loop.run_until_complete(bot.start(DISCORD_TOKEN))
except KeyboardInterrupt:
bot.loop.run_until_complete(bot.close())
except discord.ConnectionClosed:
print("Connection closed. Reconnecting in 5 seconds...")
asyncio.sleep(5)
run_bot()
threading.Thread(target=run_bot).start() |