Untitled

 avatar
unknown
php
3 years ago
1.6 kB
4
Indexable
function generateDiscordWebhook($channel_id, $guild_id){
	  
		$webhook = $this->client->request('POST', "https://discord.com/api/v9/channels/$channel_id/webhooks", [
		  'json' => [
			'name' => 'webhook-' . time() . '-' . rand(0, 999999), // random name
			'guild_id' => $guild_id,
		  ]
		]);
	  
		$webhook = json_decode($webhook->getBody(), true);
	  
		// return full webhook URL
		return "https://discord.com/api/webhooks/{$webhook['id']}/{$webhook['token']}";
	  }
		

	  function autoGenerateWebhook() {
		// Set the path to the webhooks file
		$webhook_file = ROOT_PATH . '/webhooks.txt';
	  
		// Read the guild/channel JSON file
		$guilds = json_decode(file_get_contents($this->guild_channel_file), true);
		$webhooks = [];
	  
		// Iterate over the guilds and channels
		foreach ($guilds as $guild_id => $channels) {
		  // Iterate over the channels for each guild
		  foreach ($channels as $channel_id) {
			// Create 15 webhooks for each channel
			for ($i = 0; $i < 15; $i++) {
			  try {
				// Generate the webhook URL
				$webhook_url = $this->generateDiscordWebhook($channel_id, $guild_id);
				$webhooks[$guild_id][$channel_id][] = $webhook_url;
	  
				// Echo the webhook URL
				echo $webhook_url . "\n";
	  
				// Append the webhook URL to the file
				file_put_contents($webhook_file, $webhook_url . "\n", FILE_APPEND);
	  
				// Sleep for 1 second
				sleep(1);
			  } catch (\GuzzleHttp\Exception\ClientException $e) {
				// If there was an error creating the webhook, switch to the next channel
				continue 2;
			  }
			}
		  }
		}
	  }
Editor is loading...