async def run(): """ Where the bot gets started. If you wanted to create an database connection pool or other session for the bot to use, it's recommended that you create it here and pass it to the bot as a kwarg. """ config = config_load() bot = Bot(config=config, description=os.environ.get('DESCRIPTION')) try: keep_alive() await bot.start(os.environ.get('TOKEN')) except KeyboardInterrupt: await bot.logout()
def main() -> None: TOKEN = get_token() # Define the bot intents = discord.Intents.default() intents.members = True intents.presences = True intents.emojis = True bot = commands.Bot( command_prefix=commands.when_mentioned_or("+"), owner_id=400337254989430784, activity=discord.Game("with my tail!"), case_insensitive=True, intents=intents, ) # Custom Attributes bot.BASE_DIR = getcwd() bot.EMBED_COLOR = 0x0E151D bot.LAUNCH_TIME = datetime.utcnow() bot.logger = Logger(bot, f"{bot.BASE_DIR}/resources/bot.log") # Load all cogs for filename in listdir("./cogs"): if filename.endswith(".py"): bot.load_extension(f"cogs.{filename[:-3]}") @bot.event async def on_ready(): # Called whenever the bot connects to Discord print("Logged in") print(f"Username: {bot.user.name}") print(f"User Id : {bot.user.id}") keep_alive() bot.run(TOKEN)
timestamp=ctx.message.created_at) await ctx.send(embed=ao) @client.command() async def info(ctx): await ctx.send(embed=discord.Embed( description= "**Hello! I am Saturn Advertising’s Bot! I was programmed to keep the server safe and manage modmail. If you spot a bug, contact through my modmail! I am managed by the Technical Team.**", color=0xCC71DF, timestamp=ctx.message.created_at)) @client.command(hidden=True) @commands.is_owner() async def say(ctx, *args): await ctx.message.delete() await ctx.send(' '.join(args)) cogs = [ "admin", ] for i in cogs: client.load_extension(i) keep_alive() client.run(str(os.getenv('TOKEN')))
@bot.event async def on_ready(): bot.add_check(check_command) await bot.change_presence(activity=discord.Activity( name='everything', type=discord.ActivityType(3))) # print(len(bot.commands)) if not started(): bot.loop.create_task(spam_chart_daemon(bot)) bot.loop.create_task(bg_tasks(bot)) # print('ready') @bot.event async def on_command_error(ctx, error): if type(error) == commands.errors.CheckFailure: await ctx.message.delete() msg = await ctx.send( f"You cant use `{ctx.prefix}{ctx.command}` here...") await asyncio.sleep(3) await msg.delete() else: raise error webserver.keep_alive(bot) token = os.environ.get("DISCORD_BOT_SECRET") bot.run(token)
@DISCORD_CLIENT.event async def on_ready(): print(f'We have logged in as {DISCORD_CLIENT.user}') for channel_id in config["channels"].keys(): bot = ChannelBot(channel_id) CHANNEL_BOT[channel_id] = bot SCHEDULER.add_job(bot.send_item_store, "cron", second="0", hour="6-21", timezone=timezone('Europe/Paris')) SCHEDULER.start() @DISCORD_CLIENT.event async def on_message(message): if message.author == DISCORD_CLIENT.user: return if message.content.upper() == "PING": await message.channel.send("pong") if message.content.upper() == "FETCH": channel_id = message.channel.id await CHANNEL_BOT[channel_id].send_item_store() if PROD: keep_alive() DISCORD_CLIENT.run(os.getenv('BOT_TOKEN'))
# gets the right channel and sends embed with info channel = client.get_channel(741445244838477874) await point_embed_maker(channel, house, 5, "awarded", message.author.name, "for being active and sending 50 messages!") await channel.send(f"<@{message.author.id}> ^") #sends ping else: # if the member has not sent enough mesages, closes the file file.seek(0) # moves cursor to beginning of file file.truncate(0) # deletes file contents json.dump(member_dict, file, indent=6) # loads the new dict into file.close() else: # member has never been cached house = find_house(message.author) # checks to see if they have a house if house: # if they have a house with open("house_points.json" , "r+") as file: member_dict = json.load(file) member_dict[house][str(message.author.id)] = {"points": 0, "msgs" : 1} # creates new member cache file.seek(0) # moves cursor to beginning of file file.truncate(0) # deletes file contents json.dump(member_dict, file, indent=6) # loads the new dict into the file # necessary so that the commands module doesn't stop working await client.process_commands(message) keep_alive() # keeps the bot alive using flask and uptime-robot TOKEN = os.environ.get("TOKEN") # get's bot token from hidden .env file client.run(TOKEN) # runs bot