Here is my code I am using Discord.js and the weather API I have my config.json and my index in a seperate file
const { Client, SlashCommandBuilder, MessageEmbed } = require('discord.js');
const { WEATHER_API_KEY, GIPHY_API_KEY } = require('../config.json')
const axios = require('axios');
// TODO: const giphyurl = `https://api.giphy.com/v1/gifs/random?api_key=${GIPHY_API_KEY}&tag=${encodeURIComponent(query)}`;
module.exports = {
data: new SlashCommandBuilder()
.setName('weather')
.setDescription('View the weather for your chosen area')
.addStringOption(option => option.setName('zipcode').setDescription('The zipcode you want to see the weather from')),
async execute(interaction, MessageEmbed) {
console.log(interaction.options)
const zipcode = interaction.options.getString('zipcode');
//*const zipcode = interaction.options.get('zipcode').value;
//const zipcode = interaction.options.getString('zipcode') ?? "no zipcode provided";
axios.get(`https://api.openweathermap.org/data/2.5/weather?zip=${zipcode}&units=metric&appid=${WEATHER_API_KEY}`).then(response => {
const apiData = response;
const currentTemp = Math.ceil(apiData.data.main.temp)
const wind = apiData.data.wind.speed;
const icon = apiData.data.weather[0].icon
const country = apiData.data.sys.country
const cloudness = apiData.data.weather[0].description;
const { pressure, humidity, temp_max, temp_min } = response.data.main;
//*const weatherEmbed = new EmbedBuilder()
const weatherEmbed = new MessageEmbed()
.setColor("0xd1e1fa")
.setTitle(`The temperature is currently ${currentTemp}u00B0C in ${zipcode}, ${country}`)
.addFields(
{ name: `Maximum Temperature:`, value: `${temp_max}u00B0C`, inline: true },
{ name: `Minimum Temperature:`, value: `${temp_min}u00B0C`, inline: true },
{ name: `Humidity:`, value: `${humidity} %`, inline: true },
{ name: `Wind Speed:`, value: `${wind} m/s`, inline: true },
{ name: `Pressure:`, value: `${pressure} hpa`, inline: true },
{ name: `Cloudiness:`, value: `${cloudness}`, inline: true },
)
.setThumbnail(`http://openweathermap.org/img/w/${icon}.png`)
.setFooter('Requested by ' + interaction.user.username);
interaction.reply({ embeds: [weatherEmbed] })
}).catch(err => {
interaction.reply(`Please enter a valid zipcode`)
})
},
};
here is my error
{
intents: IntentsBitField { bitfield: 1 },
rest: {
userAgentAppendix: 'discord.js/14.11.0 Node.js/v20.3.1',
agent: Agent {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
[Symbol(kCapture)]: false,
[Symbol(destroyed)]: false,
[Symbol(onDestroyed)]: null,
[Symbol(closed)]: false,
[Symbol(onClosed)]: [],
[Symbol(dispatch interceptors)]: [Array],
[Symbol(options)]: [Object],
[Symbol(maxRedirections)]: 0,
[Symbol(factory)]: [Function: defaultFactory],
[Symbol(clients)]: [Map],
[Symbol(finalizer)]: FinalizationRegistry {},
[Symbol(onDrain)]: [Function (anonymous)],
[Symbol(onConnect)]: [Function (anonymous)],
[Symbol(onDisconnect)]: [Function (anonymous)],
[Symbol(onConnectionError)]: [Function (anonymous)],
[Symbol(Intercepted Dispatch)]: [Function: Intercept]
},
api: 'https://discord.com/api',
authPrefix: 'Bot',
cdn: 'https://cdn.discordapp.com',
headers: {},
invalidRequestWarningInterval: 0,
globalRequestsPerSecond: 50,
offset: 50,
rejectOnRateLimit: null,
retries: 3,
timeout: 15000,
version: '10',
hashSweepInterval: 14400000,
hashLifetime: 86400000,
handlerSweepInterval: 3600000
},
closeTimeout: 5000,
waitGuildTimeout: 15000,
shardCount: 1,
makeCache: [Function (anonymous)],
partials: [],
failIfNotExists: true,
presence: { status: 'online', user: { id: null } },
sweepers: { threads: { interval: 3600, lifetime: 14400 } },
ws: {
large_threshold: 50,
version: 10,
presence: { activities: [], afk: false, since: null, status: 'online' }
},
jsonTransformer: [Function: toSnakeCase],
shards: [ 0 ]
}
TypeError: interaction.options.getString is not a function
at Object.execute (/Users/commands/feather.js:14:41)
at Client.<anonymous> index.js:43:23)
at Client.emit (node:events:511:28)
at InteractionCreateAction.handle node_modules/discord.js/src/client/actions/InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] /node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket node_modules/discord.js/src/client/websocket/WebSocketManager.js:354:31)
at WebSocketManager.<anonymous> node_modules/discord.js/src/client/websocket/WebSocketManager.js:238:12)
at WebSocketManager.emit node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
at WebSocketShard.<anonymous> node_modules/@discordjs/ws/dist/index.js:1103:51)
at WebSocketShard.emit node_modules/@vladfrangu/async_event_emitter/dist/index.js:282:31)
I am completely stumped any help would be great!
I have used interaction.options.getString(‘zipcode’) and interaction.options.get(‘zipcode’).value to retrieve the value of the zipcode option, neither have worked. I am trying to have the bot pull weather from the API using the provided zip code