|
import discord |
|
import os |
|
import threading |
|
from discord.ext import commands |
|
|
|
|
|
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): |
|
|
|
if message.author == bot.user: |
|
return |
|
|
|
await bot.process_commands(message) |
|
|
|
@bot.event |
|
async def on_message_delete(message): |
|
log_channel_id = 1104111048614752466 |
|
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() |