initial commit
This commit is contained in:
74
main.py
Normal file
74
main.py
Normal file
@@ -0,0 +1,74 @@
|
||||
import asyncio
|
||||
import discord
|
||||
import traceback
|
||||
|
||||
from discord.ext import commands
|
||||
from discord.utils import oauth_url
|
||||
|
||||
from loguru import logger as logging
|
||||
from dotenv import dotenv_values
|
||||
|
||||
# TODO: Log issues that happen
|
||||
# TODO: Statistics of uptime
|
||||
|
||||
|
||||
class NutBot(commands.Bot):
|
||||
def __init__(self):
|
||||
super().__init__(command_prefix=".", intents=discord.Intents.all())
|
||||
self.bot = super()
|
||||
|
||||
async def setup_hook(self) -> None:
|
||||
await self.load_extension('NutCog')
|
||||
|
||||
async def on_ready(self):
|
||||
perms = 469830672
|
||||
invite = oauth_url(super().user.id, permissions=discord.Permissions(perms))
|
||||
logging.info(f"Invite link: {invite}")
|
||||
|
||||
async def on_command_error(self, context, exception):
|
||||
if isinstance(exception, commands.NoPrivateMessage):
|
||||
await context.send('{}, This command cannot be used in DMs.'.format(context.author.mention))
|
||||
elif isinstance(exception, commands.UserInputError):
|
||||
pass # Silent ignore
|
||||
await context.send('{}, {}'.format(context.author.mention, self.format_error(context, exception)))
|
||||
elif isinstance(exception, commands.NotOwner):
|
||||
await context.send('{}, {}'.format(context.author.mention, exception.args[0]))
|
||||
elif isinstance(exception, commands.MissingPermissions):
|
||||
permission_names = [name.replace('guild', 'server').replace('_', ' ').title() for name in
|
||||
exception.missing_perms]
|
||||
await context.send('{}, you need {} permissions to run this command!'.format(
|
||||
context.author.mention, utils.pretty_concat(permission_names)))
|
||||
elif isinstance(exception, commands.BotMissingPermissions):
|
||||
permission_names = [name.replace('guild', 'server').replace('_', ' ').title() for name in
|
||||
exception.missing_perms]
|
||||
await context.send('{}, I need {} permissions to run this command!'.format(
|
||||
context.author.mention, utils.pretty_concat(permission_names)))
|
||||
elif isinstance(exception, commands.CommandOnCooldown):
|
||||
await context.send(
|
||||
'{}, That command is on cooldown! Try again in {:.2f}s!'.format(context.author.mention,
|
||||
exception.retry_after))
|
||||
elif isinstance(exception, commands.MaxConcurrencyReached):
|
||||
types = {discord.ext.commands.BucketType.default: "`Global`",
|
||||
discord.ext.commands.BucketType.guild: "`Guild`",
|
||||
discord.ext.commands.BucketType.channel: "`Channel`",
|
||||
discord.ext.commands.BucketType.category: "`Category`",
|
||||
discord.ext.commands.BucketType.member: "`Member`",
|
||||
discord.ext.commands.BucketType.user: "`User`"}
|
||||
await context.send(
|
||||
'{}, That command has exceeded the max {} concurrency limit of `{}` instance! Please try again later.'.format(
|
||||
context.author.mention, types[exception.per], exception.number))
|
||||
elif isinstance(exception, commands.CheckFailure):
|
||||
await context.send('{}, {}'.format(context.author.mention, exception.args[0]))
|
||||
else:
|
||||
await context.send(
|
||||
'```\n%s\n```' % ''.join(traceback.format_exception_only(type(exception), exception)).strip())
|
||||
# Print traceback to console
|
||||
print(''.join(traceback.format_exception(type(exception), exception, exception.__traceback__)).strip())
|
||||
if isinstance(context.channel, discord.TextChannel):
|
||||
pass # Silent ignore
|
||||
else:
|
||||
pass
|
||||
|
||||
|
||||
bot = NutBot()
|
||||
bot.run(token=dotenv_values(".env")['BOT_TOKEN'])
|
||||
Reference in New Issue
Block a user