93 lines
2.1 KiB
Python
93 lines
2.1 KiB
Python
import asyncio
|
|
import random
|
|
import os
|
|
import platform
|
|
import sys
|
|
import traceback
|
|
|
|
import discord
|
|
from discord.ext import commands
|
|
from discord import app_commands
|
|
from dotenv import load_dotenv
|
|
|
|
if sys.platform == "Linux":
|
|
import uvloop
|
|
else:
|
|
import winloop
|
|
|
|
load_dotenv()
|
|
TOKEN = os.getenv("TOKEN")
|
|
|
|
description = """haunter"""
|
|
|
|
intents = discord.Intents.all()
|
|
intents.members = True
|
|
intents.message_content = True
|
|
|
|
libs = [
|
|
"jishaku",
|
|
"lib.mod",
|
|
]
|
|
|
|
|
|
def get_prefix(bot, message):
|
|
|
|
prefixes = ["?"]
|
|
return commands.when_mentioned_or(*prefixes)(bot, message)
|
|
|
|
|
|
class Bot(commands.Bot):
|
|
|
|
async def on_ready(self):
|
|
for lib in libs:
|
|
try:
|
|
await bot.load_extension(lib)
|
|
except Exception as e:
|
|
print(f"[!] Failed to load extension: {lib}")
|
|
traceback.print_exc()
|
|
print(f"\n[^] Loaded {len(libs)} extensions loaded successfully.")
|
|
|
|
# for guild in bot.guilds:
|
|
# await bot.tree.sync(guild=discord.Object(id=guild.id))
|
|
# print(f"[^] Sync'd application commands to {len(bot.guilds)} servers")
|
|
|
|
print(f"[*] I am {bot.user} (ID: {bot.user.id})")
|
|
game = discord.Game(name="https://traps.moe", activity=random.randint(0, 3))
|
|
await bot.change_presence(status=discord.Status.online, activity=game)
|
|
print("------")
|
|
|
|
|
|
if sys.platform == "Linux":
|
|
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
|
|
loop = asyncio.new_event_loop()
|
|
else:
|
|
asyncio.set_event_loop_policy(winloop.EventLoopPolicy())
|
|
loop = asyncio.new_event_loop()
|
|
|
|
bot = Bot(
|
|
command_prefix=get_prefix,
|
|
description=description,
|
|
intents=intents,
|
|
loop=loop,
|
|
)
|
|
|
|
|
|
@bot.command()
|
|
async def joined(ctx, member: discord.Member):
|
|
"""Says when a member joined."""
|
|
await ctx.send(f"{member.name} joined {discord.utils.format_dt(member.joined_at)}")
|
|
|
|
|
|
@bot.group()
|
|
async def cool(ctx):
|
|
if ctx.invoked_subcommand is None:
|
|
await ctx.send(f"No, {ctx.subcommand_passed} is not cool")
|
|
|
|
|
|
@bot.hybrid_command(name="first_slash")
|
|
async def first_slash(ctx):
|
|
await ctx.send("You executed the slash command!")
|
|
|
|
|
|
bot.run(TOKEN)
|