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}**`)
}
}
}
Related
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.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
Here is my code,
const { Client, Intents } = require('discord.js');
const mineflayer = require("mineflayer");
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
let sending = false
let chatData = []
let prefix = ".";
var settings = {
username: "StilShem_tvink",
host: "mstnw.net",
};
const bot = mineflayer.createBot(settings);
bot.on('kicked', (reason, loggedIn) => console.log(reason, loggedIn));
bot.on('error', err => console.log(err));
client.on("ready", async =>{
console.log("Discord bot is online!")
})
bot.on("login", async =>{
console.log("Minecraft bot is online!")
})
bot.on("message", message => {
if(sending == true) {
chatData.push(`${message}`)
}
})
client.on("messageCreate", async msg => {
let args = msg.content.split(" ").slice(1)
if(msg.content.startsWith(".chat")) {
let toSend = args.join(" ");
if(!toSend) return msg.reply("No args")
bot.chat(toSend)
sending = true
msg.channel.send(`${msg.author.tag} just sent ${toSend}`)
setTimeout(() => {
sending = false
msg.channel.send(chatData.join("\n"))
chatData = []
}, 750)
}
})
This code is for minecraft mineflayer with discord. And this code give me error.
C:\Users\ArtemiiYT\node_modules\discord.js\src\util\Util.js:414
if (!allowEmpty && data.length === 0) throw new error(errorMessage);
^
RangeError [MESSAGE_CONTENT_TYPE]: Message content must be a non-empty
string.
at Function.verifyString (C:\Users\ArtemiiYT\node_modules\discord.js\src\util\Util.js:414:49)
at MessagePayload.makeContent (C:\Users\ArtemiiYT\node_modules\discord.js\src\structures\MessagePayload.js:113:22)
at MessagePayload.resolveData (C:\Users\ArtemiiYT\node_modules\discord.js\src\structures\MessagePayload.js:128:26)
at TextChannel.send (C:\Users\ArtemiiYT\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:168:61)
at Timeout._onTimeout (C:\Users\ArtemiiYT\Desktop\Всё\AFK bot\AFKBOTDS\bot.js:46:25)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7) { [Symbol(code)]: 'MESSAGE_CONTENT_TYPE' }
Node.js v17.1.0
I didn't go on my way to run the code, but I think the chatData array is empty. so when you try to .join("\n") all the elements inside it together, you just get an empty string which discord just rejects and you get an error.
so you might want to check if there is anything in the array first.
if you are here for the code just add this in the interval function:
if(chatData.length < 1) {
// maybe inform the user there is no new chat message?
return;
}
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
});
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 () => {
....
}
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
}
};