let pickupLine
const commands = {
twitter: {
response: 'www.twitter.com'
},
website: {
response: 'www.example.com'
},
pickupline: {
response: async () => {
try {
const response = await axios.get(pickupLineUrl)
pickupLine = response.data.pickup_line
console.log(response.data.pickup_line)
return pickupLine
} catch (error) {
console.error(error)
}
}
}
}
I'm trying to re write my twitch chatbot to be cleaner and i need the functions to return the value when the user types in !pickupline in chat. I can't use the global variable like i did in my other script, as it returns the output directly from the function. I've tried so many things including reading stackoverflow and brushing up on promises, .then, etc. It logs in the console just fine. The data is there. It's the return that just isn't working. It returns [object Promise] in chat. I shouldn't even need the global variable here, i was just trying all sorts of things. I should be able to say return response.data.pickup_line or use a .then(data .... return data.data.pickup_line or whatever. Please help :/