51 lines
1.6 KiB
Python
Executable File
51 lines
1.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import argparse
|
|
import logging
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import discord
|
|
import discord.utils
|
|
|
|
logger = logging.getLogger("VocalMaisBot")
|
|
|
|
|
|
class VocalMaisBot(discord.Client):
|
|
|
|
def __init__(self, token: str):
|
|
super().__init__()
|
|
self.run(token)
|
|
|
|
async def on_ready(self):
|
|
logger.info("Connected and ready!")
|
|
logger.debug(f"Logged as {self.user}")
|
|
|
|
oauth_url = discord.utils.oauth_url(
|
|
self.user.id,
|
|
discord.Permissions(manage_channels = True, read_messages = True, send_messages = True, move_members = True)
|
|
)
|
|
logger.info(f"You can invite the bot to your server using the following link: {oauth_url}")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
argparser = argparse.ArgumentParser(description = "Discord bot to automatically create temporary voice channels for users when they connect to a special channel", formatter_class = argparse.ArgumentDefaultsHelpFormatter)
|
|
argparser.add_argument("-t", "--token-file", default = ".token", help = "File where the discord bot token is stored")
|
|
# argparser.add_argument("-c", "--config-file", default = "config.json", help = "Bot config file")
|
|
argparser.add_argument("-v", "--verbose", action = "store_true", help = "Print debug messages")
|
|
|
|
ARGS = argparser.parse_args()
|
|
|
|
logging.basicConfig(
|
|
level = logging.DEBUG if ARGS.verbose else logging.INFO,
|
|
format = "%(asctime)s %(name)s [%(levelname)s] %(message)s'"
|
|
)
|
|
|
|
token_file_path = Path(ARGS.token_file).absolute()
|
|
if not token_file_path.is_file():
|
|
logger.error(f"Token file {token_file_path} does not exist")
|
|
sys.exit(1)
|
|
with token_file_path.open("r") as token_file:
|
|
token = token_file.readline().strip()
|
|
|
|
VocalMaisBot(token)
|