Use native node.js fetch (#53)

This commit is contained in:
Justin Beckwith
2024-07-26 09:54:53 -07:00
committed by GitHub
parent db5c93cd1b
commit b366a6d678
3 changed files with 1176 additions and 6 deletions

1171
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,12 @@
{
"name": "getting-started",
"name": "discord-getting-started",
"private": true,
"version": "1.0.0",
"description": "Discord example app",
"main": "app.js",
"type": "module",
"engines": {
"node": "16.x"
"node": ">=18.x"
},
"scripts": {
"start": "node app.js",
@@ -17,8 +18,7 @@
"dependencies": {
"discord-interactions": "^3.2.0",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"node-fetch": "^3.3.0"
"express": "^4.18.2"
},
"devDependencies": {
"nodemon": "^2.0.15"

View File

@@ -1,5 +1,4 @@
import 'dotenv/config';
import fetch from 'node-fetch';
import { verifyKey } from 'discord-interactions';
export function VerifyDiscordRequest(clientKey) {
@@ -20,7 +19,7 @@ export async function DiscordRequest(endpoint, options) {
const url = 'https://discord.com/api/v10/' + endpoint;
// Stringify payloads
if (options.body) options.body = JSON.stringify(options.body);
// Use node-fetch to make requests
// Use fetch to make requests
const res = await fetch(url, {
headers: {
Authorization: `Bot ${process.env.DISCORD_TOKEN}`,