discord-guess-img-bot/cogs/base.py

76 lines
3.0 KiB
Python

"""
Base Cog - 基礎功能
開發者:唐宋
"""
import discord
from discord.ext import commands
from discord import app_commands
class Base(commands.Cog):
"""基礎功能 Cog"""
def __init__(self, bot):
self.bot = bot
# --- Slash Commands ---
@app_commands.guilds(discord.Object(id=605678541530726421))
@app_commands.command(name='info', description='顯示機器人資訊')
async def slash_info(self, interaction: discord.Interaction):
"""顯示機器人資訊"""
embed = discord.Embed(
title='📖 機器人資訊',
color=discord.Color.blue()
)
embed.add_field(name='名稱', value=self.bot.user.name, inline=True)
embed.add_field(name='ID', value=self.bot.user.id, inline=True)
embed.add_field(name='伺服器數量', value=len(self.bot.guilds), inline=True)
embed.add_field(name='成員數量', value=sum(g.member_count for g in self.bot.guilds), inline=True)
embed.set_footer(text=f'由 Discord.py {discord.__version__} 驅動')
await interaction.response.send_message(embed=embed)
@app_commands.guilds(discord.Object(id=605678541530726421))
@app_commands.command(name='ping', description='測試機器人連線')
async def slash_ping(self, interaction: discord.Interaction):
"""測試機器人連線"""
latency = round(self.bot.latency * 1000)
await interaction.response.send_message(f'🏓 Pong! 延遲: {latency}ms')
@app_commands.guilds(discord.Object(id=605678541530726421))
@app_commands.command(name='echo', description='回覆你的訊息')
async def slash_echo(self, interaction: discord.Interaction, message: str):
"""回覆你的訊息"""
await interaction.response.send_message(f'🔊 {message}')
# --- Prefix Commands (向後相容) ---
@commands.command(name='info')
async def info(self, ctx):
"""顯示機器人資訊"""
embed = discord.Embed(
title='📖 機器人資訊',
color=discord.Color.blue()
)
embed.add_field(name='名稱', value=self.bot.user.name, inline=True)
embed.add_field(name='ID', value=self.bot.user.id, inline=True)
embed.add_field(name='伺服器數量', value=len(self.bot.guilds), inline=True)
embed.add_field(name='成員數量', value=sum(g.member_count for g in self.bot.guilds), inline=True)
embed.set_footer(text=f'由 Discord.py {discord.__version__} 驅動')
await ctx.send(embed=embed)
@commands.command(name='ping')
async def ping(self, ctx):
"""測試機器人連線"""
latency = round(self.bot.latency * 1000)
await ctx.send(f'🏓 Pong! 延遲: {latency}ms')
@commands.command(name='echo')
async def echo(self, ctx, *, message):
"""回覆你的訊息"""
await ctx.send(f'🔊 {message}')
# 需要注入 bot 變數
async def setup(bot):
"""註冊 Base cog"""
await bot.add_cog(Base(bot))