so I am working on a command that makes like a vote embed, and it doesn't really work. when I use (in my case) $repvote #user it doesn't recognize the user or anything.., let me know for any solutions!
if (message.author.bot) return;
if (message.content.startsWith(prefix + "repvote")) {
if (!message.member.hasPermission("MANAGE_ROLES")) return message.channel.send('You do not have that permission! :x:').then(message.react('❌'));
let repUser = message.mentions.members.first()
if(!repUser) return message.channel.send("Please mention the user you want to setup the vote for!").then(message.react('❌')).then(msg => { msg.delete({ timeout: 5000 });
const repVoteEmbed = new Discord.MessageEmbed()
repVoteEmbed.setTitle("Vote for Representative Members :crown:")
repVoteEmbed.setDescription(`User ${repUser} wants to recieve Representative Members :crown: role! Do you agree?`)
repVoteEmbed.setFooter(`Vote by: ${message.author.tag}, started on : ${message.createdAt}`)
message.channel.send({repVoteEmbed}).then(message.react('✔')).then(message.react('❌'))
})
}})```
You missing message.channel.send(embed).then(msg =>....
Message channel send return a promise of the sent message, so you need use it to react
const Discord = require('discord.js');
const bot = new Discord.Client();
bot.on('message', async (message) => {
if (message.author.bot) return;
if (message.content.startsWith(prefix + 'repvote')) {
if (!message.member.hasPermission('MANAGE_ROLES')) return message.channel.send('You do not have that permission! :x:').then(message.react('❌'));
let repUser = message.mentions.members.first();
if (!repUser) {
message.channel.send('Please mention the user you want to setup the vote for!').then((declineMsg) => {
message.react('❌');
declineMsg.delete({
timeout: 5000,
});
});
return;
}
const repVoteEmbed = new Discord.MessageEmbed();
repVoteEmbed.setTitle('Vote for Representative Members :crown:');
repVoteEmbed.setDescription(`User ${repUser} wants to recieve Representative Members :crown: role! Do you agree?`);
repVoteEmbed.setFooter(`Vote by: ${message.author.tag}, started on : ${message.createdAt}`);
message.channel.send(repVoteEmbed).then((msg) => {
msg.react(`✔`).then(() => msg.react('❌'));
});
}
});
Related
Every time I do a command on my bot that has to do with MySQL an error occurs, and my bot shut down
module.exports.run = async (bot, message, con, log, role, makeid, args) => {
con.query(`SELECT discord_id,Blacklisted,Reason FROM whitelistbot WHERE discord_id = '${message.author.id}'`, function (err, results, fields) {
if(results.length) {
if(results[0].Blacklisted === "True") {
let blacklisted = results[0].Blacklisted
let reason = results[0].Reason
const embedn = new discord.MessageEmbed()
.setColor('#0099ff')
.setDescription('**Bot Whitelist**')
.addField('Info Buyer','```md\n#Blacklist = '+blacklisted+'\n#Reason = '+reason+'\n```', true)
.setTimestamp()
message.author.send(embedn).catch(error => {
const embed2 = new discord.MessageEmbed()
.setColor('#0099ff')
.setDescription('**Bot Whitelist**')
.addField('Send Message Fail','```\nI cannot message you, open your messages!\n```', true)
.setTimestamp()
message.channel.send(embed2)
})
Hoping someone can help me solve this issue thank you in advance!
Regarding to this post: https://stackoverflow.com/a/69903276/1547821
it shows an approach with less boilerplate, to prevent a users query output (GET) to only the user who is logged in.
But how to do this, to get i.e. all members of the related group which the logged-in user participates?
This example below is my hook, but i want to have it in before->find hook as a query injection or addition.
module.exports = (options = {}) => {
return async context => {
const groupMembers = await context.app.service('groups').options.model.relatedQuery('users').for(context.params.user.id)
console.log(groupMembers)
return context
}
}
It doesn't help me as after->find hook, because total and etc. doesn't match then. Aswell my keeps doesn't work.
Appreciating any hints.
One solution would be to add a userId column to your groups model. This will contain a user of the group.
//in your /services/groups.hook.js
const { authenticate } = require('#feathersjs/authentication').hooks;
const { setField } = require('feathers-authentication-hooks');
module.exports = {
before: {
all: [],
find: [
authenticate('jwt'),
setField({
from: 'params.user.id',
as: 'params.query.userId',
}),
],
get: [],
create: [],
update: [],
patch: [],
remove: [disallow('external')],
},
//after and error options go here
};
This should return only results where the logged in user's Id matched the Id in the group table.
Ps: try console logging the context object for more insight. Also the userId column in groups model should be associated to the id column of users model.
Thanks. Meanwhile I found a solution for the before->find.hook:
context => {
if(context.params.user !== undefined) {
const groupMembers = await context.service.options.model.relatedQuery('groups').for(context.params.user.id)
if(groupMembers) {
context.params.query['$joinEager'] = 'groups'
context.params.query['groups.id'] = groupMembers[0].id
}
}
return context;
};
Well, first that's my code here
client.on('message', async (message) => { //فايف ام داتابيس
if(message.channel.type == 'dm') return;
var prefix = prefixx.get(message.guild.id);
if(message.author.bot) return;
if(message.content.toLowerCase().startsWith(prefix + 'ip')) {
if(!message.member.hasPermission('ADMINISTRATOR')) return message.channel.send('ما عندك رتبة عشان تستخدم الأمر هذا');
let args = message.content.split(" ");
connection1.query(
`select ifnull((select last_login from vrp_users where id = ${args[1]}),'لا يوجد ايدي بهذا الرقم') As ResultFound`, function (error, result, fields) {
if (error) throw error;
console.log(`Got IP of user ${args[1]}`);
if(!result) return message.channel.send('There is an error');
if(error) return message.channel.send('There is an error');
let embed = new Discord.MessageEmbed() .setColor('RANDOM') .setTitle(`اي بي ${args[1]}`) .setThumbnail(message.guild.iconURL( { dynamic : true } )) .setAuthor(client.user.tag, client.user.avatarURL( {dynamic : true} )) .addField('IP', `\`${result[0].ResultFound}\``);
message.channel.send(embed)
}
);
}
});
the result comes like this :
77.223.232.147 23:50:55 29/06/2020
i want the result be only the ip can you guys help me?
Try this:
.addField('IP', `\`${result[0].ResultFound.split(' ')[0]}\``);
For example, if the result is what you provided in your question:
const result = '77.223.232.147 23:50:55 29/06/2020'
// split the message by every space
const array = result.split(' ');
console.log(array[0]); // IP adress
console.log(array[1]); // time (I presume)
console.log(array[2]); // date
I have developed an app which basically has admin and client portal running in separate ports and when an order is placed from client side, the admin dashboard should be able to get the new order shown.
Basically the view has to be refreshed to keep an updated UI.
For which i have referred the below link:
http://beyondscheme.com/2016/angular2-discussion-portal
Below is what i have tried.
order-issue.component.ts
ngOnInit() {
const user_id = {
user_ids: this.user_id
};
// To display the Pending Orders into the table
this.orderService.getAllOrders("Pending").subscribe(data => {
if (data.success && data.Allorders.length != 0) {
for (let i = 0; i < data.Allorders.length; i++) {
this.orderService
.getOrderItemsByNo(data.Allorders[i].orderNo)
.subscribe(subData => {
data.Allorders[i].orderItems = subData;
});
}
this.source = data.Allorders; //To display the data into smart table
this.refreshData(); //For real time refresh
} else {
this.flashMessage.show("No Pending Orders", {
cssClass: "alert-success",
timeout: 300000
});
}
});
private refreshData(): void {
this.commentsSubscription = this.orderService.getAllOrders("Pending").subscribe(data => {
this.data = data;
console.log(data); //able to see the new orders
this.subscribeToData();
});
private subscribeToData(): void {
this.timerSubscription = Observable.timer(5000).first().subscribe(() => this.refreshData());
}
My service(orderService) will get all the orders:
getAllOrders(status) {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
return this.http.post(`${BASE_URL}/orders/getAllOrdersWithItems`, { status: status }, { headers: headers })
.map(res => res.json());
}
Ok i am able to fix it with below change.
//Function which refreshes the data in real time without page refresh
private refreshData(): void {
this.commentsSubscription = this.orderService.getAllOrders("Pending").subscribe(data => {
this.source = data.Allorders; //Updated here! and it worked
console.log(this.source);
this.subscribeToData(); //On success we call subscribeToData()
});
}
I need to develop an app for a conference and i'm trying to make this with Ionic2, AngularJS2 and Firebase.
I'm not starting from scratch, I clone this repository : https://github.com/driftyco/ionic-conference-app.
My repository : https://github.com/wowadrien/SFGP
My problem is that I need to filter the session first by day, next by room and then by theme so I add a level in the tree of my json to sort the session by room.
I've change the code of the data provider as this :
processData(data: any) {
this.data = data.json();
this.data.tracks = [];
// loop through each day in the schedule
this.data.schedule.forEach((day: any) => {
// loop through each timeline group in the day
day.groups.forEach((group: any) => {
// loop through each session in the timeline group
group.sessions.forEach((session: any) => {
//loop trough each subsession in the timeline session
session.subsessions.forEach((subsession: any) =>{
subsession.speakers = [];
if (subsession.speakerNames) {
subsession.speakerNames.forEach((speakerName: any) => {
let speaker = this.data.speakers.find((s: any) => s.name === speakerName);
if (speaker) {
subsession.speakers.push(speaker);
speaker.subsessions = speaker.subsessions || [];
speaker.subsessions.push(subsession);
}
});
}
if (subsession.tracks) {
subsession.tracks.forEach((track: any) => {
if (this.data.tracks.indexOf(track) < 0) {
this.data.tracks.push(track);
}
});
}
});
});
});
});
return this.data;
}
It doesn't work and i've tried about 20 differents solutions since last week but none of them was good.
I'm hopeless and lonely in this project so please, I need help !
Adrien