Use The AI Response
Access the AI’s Reply
info
The response object has a nested structure. To access just the text reply:
tip
response.choices[0].message.content
Use a Variable as Input
info
You can store the question as a variable and use it in the API call.
tip
const userPrompt = "What is AI?";
const response = await client.chat.completions.create({
model: "gpt-3.5-turbo",
messages: [{ role: "user", content: `${userPrompt}` }]
});
Define an async
Function
info
async
means this function can use await
inside it.
tip
async function askOpenAI(prompt) {
const response = await client.chat.completions.create({
model: "gpt-3.5-turbo",
messages: [{ role: "user", content: prompt }]
});
return response.choices[0].message.content;
}
Use the AI Reply in Your Command
info
Replace your original interaction.reply()
with a call to your AI function.
tip
const answer = await askOpenAI(userPrompt);
await interaction.reply(answer);