openai / dallify-discord-bot Goto Github PK
View Code? Open in Web Editor NEWExample code for using OpenAI’s NodeJS SDK with discord.js SDK to create a Discord Bot that uses Slash Commands.
License: MIT License
Example code for using OpenAI’s NodeJS SDK with discord.js SDK to create a Discord Bot that uses Slash Commands.
License: MIT License
Hi, i'm having troubles making this running... I made all the required steps and i still get theses errors:
My config.json file
{
"DISCORD_BOT_TOKEN": "MTA2OTY4MDQ3NjQ5MjY3NzEyMA.GGN4Qc.**********************",
"DISCORD_BOT_CLIENT_ID": "10696804***********",
"OPENAI_API_KEY": "sk-DNDM3CQUlM0K4HyBR3vNT3BlbkFJTo****************",
"ALLOWED_SERVER_IDS": [
"1069008854811164693",
"1069008854811164693"
]
}
*/
if (!DISCORD_BOT_CLIENT_ID) {
throw "DISCORD_BOT_CLIENT_ID must be set in env or config";
}
if (!DISCORD_BOT_TOKEN) {
throw "DISCORD_BOT_TOKEN must be set in env or config";
}
if (!OPENAI_API_KEY) {
throw "OPENAI_API_KEY must be set in env or config";
}
export const MAX_IMAGES = 4; // the API supports 1 to 10 images per request
export const DEFAULT_IMAGES = 2; // This is used when no number is given
export const IMAGE_SIZE: number = 256;
export const EXPAND_ACTION_PADDING = 120; // How many pixels the Expand action adds on each side
export const EXPAND_ACTION_NUM_IMAGES = 2; // how many images to show for an expand action
export const LOG_ERRORS = true;
if (DEFAULT_IMAGES > MAX_IMAGES) {
throw `DEFAULT_IMAGES must not be greater than MAX_IMAGES`;
}
// The API only supports these
if (![256, 512, 1024].includes(IMAGE_SIZE)) {
throw `Invalid IMAGE_SIZE ${IMAGE_SIZE}`;
}
I guess i had not to add these values to constants.ts, however here is how it is
import * as config from "./config.json";
export const DISCORD_BOT_TOKEN = MTA2OTY4MDQ3NjQ5MjY3NzEyMA.GGN4Qc.LQX9ycHT9wZfpJKzGXsQIdXB9LBo1jT0Jg9iks
process.env.DISCORD_BOT_TOKEN ?? config.DISCORD_BOT_TOKEN;
export const DISCORD_BOT_CLIENT_ID = 1069680476492677120
process.env.DISCORD_BOT_CLIENT_ID ?? config.DISCORD_BOT_CLIENT_ID;
export const OPENAI_API_KEY = sk-DNDM3CQUlM0K4HyBR3vNT3BlbkFJToEgfnSocbkNfil2****
The errors i get;
alfred@pictocube:~/DALL-E/dallify-discord-bot-main$ npm run start
> [email protected] start
> ts-node src/Bot.ts
/home/alfred/DALL-E/dallify-discord-bot-main/node_modules/ts-node/src/index.ts:859
return new TSError(diagnosticText, diagnosticCodes, diagnostics);
^
TSError: ⨯ Unable to compile TypeScript:
src/utils/constants.ts:2:34 - error TS2304: Cannot find name 'MTA2OTY4MDQ3NjQ5MjY3NzEyMA'.
2 export const DISCORD_BOT_TOKEN = MTA2OTY4MDQ3NjQ5MjY3NzEyMA.GGN4Qc.LQX9ycHT9wZfpJKzGXsQIdXB9LBo1jT0Jg9iks
~~~~~~~~~~~~~~~~~~~~~~~~~~
src/utils/constants.ts:3:43 - error TS2339: Property 'DISCORD_BOT_TOKEN' does not exist on type '({ DISCORD_BOT_TOKEN: string; DISCORD_BOT_CLIENT_ID: string; OPENAI_API_KEY: string; ALLOWED
_SERVER_IDS: string[]; const?: undefined; number?: undefined; throw?: undefined; } | { if(: any, DISCORD_BOT_CLIENT_ID: any): never; if(DEFAULT_IMAGES: any, MAX_IMAGES: any): never; ... 6 m
ore ...; ALLOWED_SERVER_IDS?: undefi...'.
3 process.env.DISCORD_BOT_TOKEN ?? config.DISCORD_BOT_TOKEN;
src/utils/constants.ts:5:47 - error TS2339: Property 'DISCORD_BOT_CLIENT_ID' does not exist on type '({ DISCORD_BOT_TOKEN: string; DISCORD_BOT_CLIENT_ID: string; OPENAI_API_KEY: string; ALLOWED_SERVER_IDS: string[]; const?: undefined; number?: undefined; throw?: undefined; } | { if(: any, DISCORD_BOT_CLIENT_ID: any): never; if(DEFAULT_IMAGES: any, MAX_IMAGES: any): never; ... 6 more ...; ALLOWED_SERVER_IDS?: undefi...'.
5 process.env.DISCORD_BOT_CLIENT_ID ?? config.DISCORD_BOT_CLIENT_ID;
~~~~~~~~~~~~~~~~~~~~~
src/utils/constants.ts:7:31 - error TS2304: Cannot find name 'sk'.
7 export const OPENAI_API_KEY = sk-DNDM3CQUlM0K4HyBR3vNT3BlbkFJToEgfnSocbkNfil2****
~~
src/utils/constants.ts:7:34 - error TS2304: Cannot find name 'DNDM3CQUlM0K4HyBR3vNT3BlbkFJToEgfnSocbkNfil2UW25'.
7 export const OPENAI_API_KEY = sk-DNDM3CQUlM0K4HyBR3vNT3BlbkFJToEgfnSocbkNfil2****
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/utils/constants.ts:8:40 - error TS2339: Property 'OPENAI_API_KEY' does not exist on type '({ DISCORD_BOT_TOKEN: string; DISCORD_BOT_CLIENT_ID: string; OPENAI_API_KEY: string; ALLOWED_SERVER_IDS: string[]; const?: undefined; number?: undefined; throw?: undefined; } | { if(: any, DISCORD_BOT_CLIENT_ID: any): never; if(DEFAULT_IMAGES: any, MAX_IMAGES: any): never; ... 6 more ...; ALLOWED_SERVER_IDS?: undefi...'.
8 process.env.OPENAI_API_KEY ?? config.OPENAI_API_KEY;
~~~~~~~~~~~~~~
src/utils/constants.ts:9:129 - error TS2339: Property 'ALLOWED_SERVER_IDS' does not exist on type '({ DISCORD_BOT_TOKEN: string; DISCORD_BOT_CLIENT_ID: string; OPENAI_API_KEY: string; ALLOWED_SERVER_IDS: string[]; const?: undefined; number?: undefined; throw?: undefined; } | { if(: any, DISCORD_BOT_CLIENT_ID: any): never; if(DEFAULT_IMAGES: any, MAX_IMAGES: any): never; ... 6 more ...; ALLOWED_SERVER_IDS?: undefi...'.
9 export const ALLOWED_SERVER_IDS: string[] = process.env.ALLOWED_SERVER_IDS ? process.env.ALLOWED_SERVER_IDS.split(",") : config.ALLOWED_SERVER_IDS ?? []; // only servers with these ids can use the bot
~~~~~~~~~~~~~~~~~~
at createTSError (/home/alfred/DALL-E/dallify-discord-bot-main/node_modules/ts-node/src/index.ts:859:12)
at reportTSError (/home/alfred/DALL-E/dallify-discord-bot-main/node_modules/ts-node/src/index.ts:863:19)
at getOutput (/home/alfred/DALL-E/dallify-discord-bot-main/node_modules/ts-node/src/index.ts:1077:36)
at Object.compile (/home/alfred/DALL-E/dallify-discord-bot-main/node_modules/ts-node/src/index.ts:1433:41)
at Module.m._compile (/home/alfred/DALL-E/dallify-discord-bot-main/node_modules/ts-node/src/index.ts:1617:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1300:10)
at Object.require.extensions.<computed> [as .ts] (/home/alfred/DALL-E/dallify-discord-bot-main/node_modules/ts-node/src/index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:1103:32)
at Function.Module._load (node:internal/modules/cjs/loader:942:12)
at Module.require (node:internal/modules/cjs/loader:1127:19) {
diagnosticCodes: [
2304, 2339,
2339, 2304,
2304, 2339,
2339
]
}
Any help would be greatly appreciated, thanks!
Hi, I've gone over the instructions multiple times but I can't get the bot to work.
First time launching it I would get the "no guild" error but after a restart this went away.
I see the Bot in my server and set it up with appropriate permissions.
Whenever I try to use /draw "something" I get an error on Discord: "Error: You don't have permission to do that."
And the following error on the console output of node "Permissions error: Guild ############## not allowed." the ###### matches my server ID I got using the instructions provided.
I'm at a bit of a loss here.
Do you have any idea what might cause this or is there a way to turn on more verbose logging?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.