Skip to content

Instantly share code, notes, and snippets.

@wolfenrain
Created October 1, 2023 09:18
Show Gist options
  • Save wolfenrain/7bacd65c0c44764c474c34b7e73aa920 to your computer and use it in GitHub Desktop.
Save wolfenrain/7bacd65c0c44764c474c34b7e73aa920 to your computer and use it in GitHub Desktop.
Dart code to create an application owned webhook in Discord
import 'dart:convert';
import 'dart:io';
final client = HttpClient(context: SecurityContext(withTrustedRoots: true));
Future<Map<String, dynamic>> createDiscordWebhook({
required String channelId,
required String authorization,
required String name,
}) async {
final request = await client.postUrl(
Uri.parse('https://discord.com/api/channels/$channelId/webhooks'),
)
..headers.add('Content-Type', 'application/json')
..headers.add('User-Agent', 'DartClient (https://discord.com, 0)')
..headers.add('Authorization', 'Bot $authorization')
..write(json.encode({'name': name}));
final response = await request.close();
return json.decode(utf8.decode(await response.first));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment