modbot / app.py
lunarflu's picture
lunarflu HF Staff
Duplicate from lunarflu/lunarbot
bd28673
raw
history blame
1.45 kB
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()