add some error handling to startup in case of api breakage
This commit is contained in:
		
							parent
							
								
									ba7a050220
								
							
						
					
					
						commit
						3d7b026f4c
					
				
					 1 changed files with 15 additions and 6 deletions
				
			
		
							
								
								
									
										21
									
								
								src/index.js
									
										
									
									
									
								
							
							
						
						
									
										21
									
								
								src/index.js
									
										
									
									
									
								
							| 
						 | 
					@ -149,11 +149,15 @@ bot.once("ready", async () => {
 | 
				
			||||||
  logger.info("hf:main", "Connected to Discord.");
 | 
					  logger.info("hf:main", "Connected to Discord.");
 | 
				
			||||||
  logger.info("hf:main", `Logged in as: ${formatUsername(bot.user)} (${bot.user.id})`);
 | 
					  logger.info("hf:main", `Logged in as: ${formatUsername(bot.user)} (${bot.user.id})`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const channel = await bot.getDMChannel(config.owner_id);
 | 
					  try {
 | 
				
			||||||
  if (channel) {
 | 
					    const channel = await bot.getDMChannel(config.owner_id);
 | 
				
			||||||
    channel.createMessage({
 | 
					    if (channel) {
 | 
				
			||||||
      content: "<:ms_tick:503341995348066313> Loaded HiddenPhox.",
 | 
					      channel.createMessage({
 | 
				
			||||||
    });
 | 
					        content: "<:ms_tick:503341995348066313> Loaded HiddenPhox.",
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  } catch (err) {
 | 
				
			||||||
 | 
					    logger.error("hf:main", `Failed to send startup message, API probably broken currently.\n${err}`);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  bot.on("ready", () => {
 | 
					  bot.on("ready", () => {
 | 
				
			||||||
    logger.info("hf:main", "Reconnected to Discord.");
 | 
					    logger.info("hf:main", "Reconnected to Discord.");
 | 
				
			||||||
| 
						 | 
					@ -170,6 +174,7 @@ bot.once("ready", async () => {
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // stupid hack
 | 
					      // stupid hack
 | 
				
			||||||
 | 
					      // FIXME: make send optional, check if it is send
 | 
				
			||||||
      const send = options.shift();
 | 
					      const send = options.shift();
 | 
				
			||||||
      options.push(send);
 | 
					      options.push(send);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -198,7 +203,11 @@ bot.once("ready", async () => {
 | 
				
			||||||
      commands.push(formattedCommand);
 | 
					      commands.push(formattedCommand);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    await bot.requestHandler.request("PUT", APIEndpoints.COMMANDS(bot.application.id), true, commands);
 | 
					    try {
 | 
				
			||||||
 | 
					      await bot.requestHandler.request("PUT", APIEndpoints.COMMANDS(bot.application.id), true, commands);
 | 
				
			||||||
 | 
					    } catch (err) {
 | 
				
			||||||
 | 
					      logger.error("hf:main", `Failed to update interaction commands, API probably broken currently.\n${err}`);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue