bonjour, j’essaie de coder un bot discord chatgpt avec une commande / (du nom de "ping"), mais je n’arrive pas recuperer le contenu apres la commande. es que vous pourriez donc m’aider s’il vous plait
require("dotenv").config()
const {Client, GatewayIntentBits, ReactionEmoji} = require("discord.js");
const bot = new Client({
intents : [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
"Guilds"
]
});
// setting up open ai
const {Configuration, OpenAIApi} = require("openai")
const configuration = new Configuration({
organization:process.env.OPENAI_ORG,
apiKey:process.env.OPENAI_KEY
});
const openai = new OpenAIApi(configuration)
bot.on("ready", async () => {
await bot.application.commands.set([
{
name: "ping",
description: "Pong!"
}
]);
console.log("Le bot est prêt !");
});
bot.on("interactionCreate", async (interaction) => {
if (interaction.commandName === "ping");
if (!interaction.isCommand()) return;
const response = await openai.createCompletion({
model: "text-davinci-003",
prompt : `Hey, donnez-moi une réponse pour cela : ${message.content}`,
temperature: 0.5,
max_tokens: 300,
top_p: 1.0,
frequency_penalty: 0.5,
presence_penalty: 0.0,
});
message.reply(`${response.data.choices[0].text}`)});
bot.login(process.env.DISCORD_KEY);
l’erreur :
Uncaught ReferenceError ReferenceError: message is not defined
at <anonymous> (c:\Users\Kareen\Desktop\my_ai_bot\index.js:44:65)
at emit (events:513:28)
at handle (c:\Users\Kareen\Desktop\my_ai_bot\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports (c:\Users\Kareen\Desktop\my_ai_bot\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at handlePacket (c:\Users\Kareen\Desktop\my_ai_bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:352:31)
at onPacket (c:\Users\Kareen\Desktop\my_ai_bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:489:22)
at onMessage (c:\Users\Kareen\Desktop\my_ai_bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:328:10)
at callListener (c:\Users\Kareen\Desktop\my_ai_bot\node_modules\ws\lib\event-target.js:290:14)
at onMessage (c:\Users\Kareen\Desktop\my_ai_bot\node_modules\ws\lib\event-target.js:209:9)
at emit (events:513:28)
at receiverOnMessage (c:\Users\Kareen\Desktop\my_ai_bot\node_modules\ws\lib\websocket.js:1180:20)
at emit (events:513:28)
at dataMessage (c:\Users\Kareen\Desktop\my_ai_bot\node_modules\ws\lib\receiver.js:541:14)
at getData (c:\Users\Kareen\Desktop\my_ai_bot\node_modules\ws\lib\receiver.js:459:17)
at startLoop (c:\Users\Kareen\Desktop\my_ai_bot\node_modules\ws\lib\receiver.js:158:22)
at _write (c:\Users\Kareen\Desktop\my_ai_bot\node_modules\ws\lib\receiver.js:84:10)
at writeOrBuffer (internal/streams/writable:392:12)
at _write (internal/streams/writable:333:10)
at Writable.write (internal/streams/writable:337:10)
at socketOnData (c:\Users\Kareen\Desktop\my_ai_bot\node_modules\ws\lib\websocket.js:1274:35)
at emit (events:513:28)
+0
-0