Support message command

This commit is contained in:
Choco
2023-02-18 18:57:12 +08:00
parent 2d50bded75
commit 9e5997e4ec
11 changed files with 1120 additions and 1205 deletions

69
main.py
View File

@@ -1,21 +1,15 @@
import discord
import sys, os, traceback, aiohttp
import update
import function
from function import (
langs_setup,
settings_setup,
local_langs,
get_lang,
invite_link,
error_log
)
from discord.ext import commands
from dotenv import load_dotenv
from datetime import datetime
from voicelink import VoicelinkException
load_dotenv()
function.settings_setup()
class Translator(discord.app_commands.Translator):
async def load(self):
@@ -31,12 +25,17 @@ class Translator(discord.app_commands.Translator):
class Vocard(commands.Bot):
async def on_message(self, message):
pass
async def on_message(self, message: discord.Message, /) -> None:
if message.author.bot or not message.guild:
return False
if self.user.mentioned_in(message) and not message.mention_everyone:
await message.channel.send(f"My prefix is `{self.command_prefix}`")
await self.process_commands(message)
async def setup_hook(self):
langs_setup()
settings_setup()
function.langs_setup()
for module in os.listdir('./cogs'):
if module.endswith('.py'):
try:
@@ -57,18 +56,50 @@ class Vocard(commands.Bot):
print(f"Python Version: {sys.version}")
print("------------------")
elif isinstance(error, (commands.CommandOnCooldown, commands.MissingPermissions, commands.RangeError, commands.BadArgument)):
pass
elif isinstance(error, commands.MissingRequiredArgument):
command = f" Correct Usage: {ctx.prefix}" + (f"{ctx.command.parent.qualified_name} " if ctx.command.parent else "") + f"{ctx.command.name} {ctx.command.signature}"
position = command.find(f"<{ctx.current_parameter.name}>") + 1
error = f"```css\n[You are missing argument!]\n{command}\n" + " " * position + "^" * len(ctx.current_parameter.name) + "```"
elif not issubclass(error.__class__, VoicelinkException):
error = function.get_lang(ctx.guild.id, "unknownException") + function.invite_link
if (guildId := ctx.guild.id) not in function.error_log:
function.error_log[guildId] = {}
function.error_log[guildId][round(datetime.timestamp(datetime.now()))] = str(traceback.format_exc())
try:
return await ctx.reply(error, ephemeral=True)
except:
pass
class CommandCheck(discord.app_commands.CommandTree):
async def interaction_check(self, interaction: discord.Interaction, /) -> bool:
if not interaction.guild:
await interaction.response.send_message("This command can only be used in guilds!")
return False
return await super().interaction_check(interaction)
intents = discord.Intents.default()
intents.members = True
intents.message_content = True if function.bot_prefix else False
member_cache = discord.MemberCacheFlags(
voice=True,
joined=False
)
bot = Vocard(command_prefix="?",
bot = Vocard(command_prefix=function.bot_prefix,
help_command=None,
tree_cls=CommandCheck,
chunk_guilds_at_startup = False,
member_cache_flags=member_cache,
activity=discord.Activity(type=discord.ActivityType.listening,name="/help"),
activity=discord.Activity(type=discord.ActivityType.listening,name="/help"),
case_insensitive = True,
intents=intents)
@bot.tree.error
@@ -79,10 +110,10 @@ async def app_command_error(interaction: discord.Interaction, error):
elif isinstance(error, (discord.app_commands.CommandOnCooldown, discord.app_commands.errors.MissingPermissions)):
pass
elif not issubclass(error.__class__, VoicelinkException):
error = get_lang(interaction.guild_id, "unknownException") + invite_link
if (guildId := interaction.guild_id) not in error_log:
error_log[guildId] = {}
error_log[guildId][round(datetime.timestamp(datetime.now()))] = str(traceback.format_exc())
error = function.get_lang(interaction.guild_id, "unknownException") + function.invite_link
if (guildId := interaction.guild_id) not in function.error_log:
function.error_log[guildId] = {}
function.error_log[guildId][round(datetime.timestamp(datetime.now()))] = str(traceback.format_exc())
try:
if interaction.response.is_done():
return await interaction.followup.send(error, ephemeral=True)