fix: Update Discord API integration to use Bot token and channel ID for message handling
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import pool from '@/lib/db';
|
||||
|
||||
if (!process.env.DISCORD_WEBHOOK_URL || !process.env.CRON_SECRET) {
|
||||
throw new Error('Please define DISCORD_WEBHOOK_URL and CRON_SECRET in .env.local');
|
||||
if (!process.env.DISCORD_BOT_TOKEN || !process.env.DISCORD_CHANNEL_ID || !process.env.CRON_SECRET) {
|
||||
throw new Error('Discord or Cron secret environment variables are not configured');
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
@@ -36,8 +36,13 @@ export async function POST(request: Request) {
|
||||
);
|
||||
|
||||
const deletePromises = partsRows.map((part: { discord_message_id: string }) => {
|
||||
const deleteUrl = `${process.env.DISCORD_WEBHOOK_URL}/messages/${part.discord_message_id}`;
|
||||
return fetch(deleteUrl, { method: 'DELETE' });
|
||||
const deleteUrl = `https://discord.com/api/v10/channels/${process.env.DISCORD_CHANNEL_ID}/messages/${part.discord_message_id}`;
|
||||
return fetch(deleteUrl, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Authorization': `Bot ${process.env.DISCORD_BOT_TOKEN}`,
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
await Promise.allSettled(deletePromises);
|
||||
|
||||
Reference in New Issue
Block a user