I get an error "';' expected.ts(1005)" not even using TS? [closed] - javascript

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Can anyone explain what is the problem here?
I'm not even using TS this is just javascript
async addChat(message) {
const now = new Date()
const chat = {
message,
username: this.username,
room: this.room,
created_at: firebase.firestore.Timestamp.fromDate(now)
}
const response = await this.chats.add(chat)
return response
}
I'm sorry, dumb mistake, this was outside of my class
class Chatroom {
constructor(room, username) {
this.room = room
this.username = username
this.chats = db.collection('chats')
}
async addChat(message) {
const now = new Date()
const chat = {
message,
username: this.username,
room: this.room,
created_at: firebase.firestore.Timestamp.fromDate(now)
}
const response = await this.chats.add(chat)
return response
}
}

The issue is with your function declaration. You need to either do this
async function addChat() {
....
}
or
addChat = async () => {
....
}

Related

_query is not a function. (In '_query((0, _database.ref) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 15 hours ago.
Improve this question
I am getting an Error when using database _query
Error
ERROR TypeError: _query is not a function. (In '_query((0, _database.ref)(_FirebaseConfig.database, 'users'), (0, _database.orderByChild)('email'), (0, _database.equalTo)(email))', '_query' is undefined)
code:
(note that query is not being highlighted as used )
import { ref, get, set, orderByChild, equalTo, query } from 'firebase/database';
useEffect(() => {
const writeToDatabase = () => {
const email = UserDataFromGoogleAuth.email;
if (email) {
const query = query(ref(database, 'users'), orderByChild('email'), equalTo(email));
get(query)
.then((snapshot) => {
const uuid = snapshot.exists() ? Object.keys(snapshot.val())[0] : uid();
const userRef = ref(database, `/users/${uuid}`);
const userData = {
id: uuid,
name: UserDataFromGoogleAuth.displayName,
email: email,
profilePicture: UserDataFromGoogleAuth.photoURL,
};
return set(userRef, userData);
})
}
};
writeToDatabase();
}, [location, UserDataFromGoogleAuth, props.online, database]);
**
"firebase": "^9.17.1",**
I am getting an Error when using database _query
On this line:
const query = query(ref(database, 'users'), orderByChild('email'), equalTo(email));
You define a variable called query and then try to assign it a value based on calling that same uninitialized variable because it shadow's the query method you are importing from the firebase/database library.
Rename the variable to something else to prevent shadowing the imported method.
const usersWithMatchingEmailQuery = query(ref(database, 'users'), orderByChild('email'), equalTo(email));
get(usersWithMatchingEmailQuery)
.then(/* ... */)
Note: Don't forget to add a catch() to that Promise chain to handle errors.

discord.js channel only command [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed last month.
Improve this question
Kepps crashing
const Discord = require("discord.js")
module.exports = {
name: 'not-dropping',
description: 'sets the dropping status!',
if (message.channel.id === '1059798572855476245') {
execute(message, args) {
message.delete(1000);
const name = ("dropping-🔴")
message.channel.setName(name)
message.channel.send(`Successfully set the dropping status to **${name}**`)
}
}
}
I also tried to change it to Role only but it contiunes crashing.
Having an if-statement in the definition of your export won't work. Instead, call the if-statement only when execute() is run, like this:
const Discord = require("discord.js")
module.exports = {
name: 'not-dropping',
description: 'sets the dropping status!',
execute(message, args) {
if (message.channel.id === '1059798572855476245') {
message.delete(1000);
const name = ("dropping-🔴")
message.channel.setName(name)
message.channel.send(`Successfully set the dropping status to **${name}**`)
}
}
}

Server Boost Tracker Bot Discord [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Help me to send a message when someone Boost The Server, here some code for example.
Please help me, guys :)
bot.on('guildMemberUpdate', (oldMember, newMember) => {
if(oldMember.roles.size < newmember.roles.size) {
const fetchedLogs = await oldMember.guild.fetchAuditLogs({
limit: 1,
type: 'MEMBER_ROLE_UPDATE',
});
const roleAddLog = fetchedLogs.entries.first();
if (!roleAddLog ) return;
const { executor, target, extra } = kickLog;
console.log(`Role ${extra.name} added to ${<#target.id>} by ${<#executor.id>}`)
}
});
You can use GuildMember#premiumSince for an approach that does not rely on roles:
bot.on('guildMemberUpdate', (oldMember, newMember) => {
if (oldMember.premiumSince !== newMember.premiumSince) {
//your code here
}
});
You can check if the Nitro Booster role gets assigned to a member:
bot.on('guildMemberUpdate', async (oldMember, newMember) => {
const hadRole = oldMember.roles.find(role => role.name === 'Nitro Booster');
const hasRole = newMember.roles.find(role => role.name === 'Nitro Booster');
if (!hadRole && hasRole) {
newMember.guild.channels.get(/* channel ID */).send('Someone boosted the server');
}
// if you want to check which members are boosted, you can check how many have the `Nitro Booster` role:
const boostedUsers = newMember.guild.members.array().filter(member => member.roles.find(role => role.name === 'Nitro Booster'));
console.log(boostedUsers.length); // how many members are boosted
});

How to solve nested async database calls in Firebase Functions [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I want to get a list of objects and for each object there is a record in another collection which has to be called also. Both requests return promises and my question is, how to "wait" for the inner promises to be fulfilled before the next outer promises are done.
This is the code:
export async function getAllCompanies(req: Request, res: Response) {
try {
const listCompanies = await db.collection('companies').get()
const companies = listCompanies.docs.map(async doc => {
const data = doc.data()
const location = await db.collection('locations').doc(data.locationId).get()
const locationData = location.data()
return {
id: doc.id,
name: data.name,
address: locationData ? locationData.address : null,
zipCode: locationData ? locationData.zipCode : null,
city: locationData ? locationData.city : null,
country: locationData ? locationData.country : null,
email: data.email,
phoneNumber: data.phoneNumber,
type: data.type,
createTime: doc.createTime.toDate(),
lastUpdateTime: data.lastUpdateTime
}
})
return res.status(200).send({ companies })
} catch (err) {
return handleError(res, err)
}
}
I think you're looking for:
const resolvedCompanies = await Promise.all(companies);
return res.status(200).send({companies: resolvedCompanies});
just before the return res.status(...). This will wait for all of the promises you map-ed into the list of companies to resolve before returning and return the values instead of the promises.

Parsing error Javascript [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
Getting a parsing error in javascript while deploying firebase functions... Its showing unexpected token which if i'm not mistaken means that there is an unexpected character somewhere... Stuck here for weeks now... Can somone help me out please
Code
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.sendNotification = functions.database.ref(`/Notifications/${user_id}/${notification_id}/`).onWrite((change, context) => {
const user_id = context.params.user_id;
const notification_id = context.params.notification_id;
console.log('We have a notification to send to ', user_id);
if (!change.after.val()) {
return console.log("A Notification has been deleted from the database", notification_id);
}
const fromUser = admin.database().ref('/Notifications/${user_id}/${notification_id}').once('value');
return fromUser.then(fromUserResult => {
const fromUserId = fromUserResult.val().from;
console.log('You have a new notification from : ', from_user_id);
const userQuery = admin.database().ref('UserData/${fromUserId}/name').once('value');
return userQuery.then(userResult => {
const userName = userResult.val();
const deviceToken = admin.database().ref(`/UserData/${user_id}/TokenID`).once('value');
return deviceToken.then(result => {
const token_id = result.val();
const payload = {
notification: {
title: '${userName}',
body: "You have recieved a new Message",
icon: "default",
click_action: "com.appmaster.akash.messageplus_TARGET_NOTIFICATION"
},
data: {
from_user_id: fromUserId,
from_user_name: userName
}
};
return admin.messaging().sendToDevice(token_id, payload).then(response => {
return console.log('This was the notofication Feature');
});
});
});
});
You're missing two pairs of }) at the end of the file. So:
...
return admin.messaging().sendToDevice(token_id, payload).then(response =>{
return console.log('This was the notofication Feature');
});
});
});
});
});
It is understandably impossible to see this with your current code.
The lack of indentation makes it incredibly hard to parse. That's why I passed the code through http://jsbeautifier.org/, which makes it much easier to parse.
I also recommend using a tool like https://eslint.org/demo/ to make it easier to find mistakes like this.
you'll still have few bugs in your code. on three places you're using single quote ' instead of back-tick `
...
const fromUser = admin.database().ref(`/Notifications/${user_id}/${notification_id}`).once('value');
...
const userQuery = admin.database().ref(`UserData/${fromUserId}/name`).once('value');
...
const payload = {
notification: {
title: `${userName}`,
body: "You have recieved a new Message",
icon: "default",
click_action: "com.appmaster.akash.messageplus_TARGET_NOTIFICATION"
},
data: {
from_user_id: fromUserId,
from_user_name: userName
}
};

Categories