Here's the code that the error is in, the error is on the last line that you see here and i'm not sure how to solve it,
I'm pretty new to all of this, so some advice would be useful. I need to solve this issue as quick as possible as we are using this bot as a moderation tool in one of my Discord servers. Thank you all!
}
if (command === "slap") {
const options = [
"https://tenor.com/view/no-angry-anime-slap-gif-7355956",
"https://tenor.com/view/when-you-cant-accept-reality-slap-anime-gif-14694312",
"https://tenor.com/view/anime-slap-slap-in-the-face-smash-gif-17314633"
]
if (message.mentions.users.first()) {
message.channel.send(message.author.username + " slapped " + message.mentions.users.first().username)
} else {
message.channel.send("You have to mention a user to slap")
}
}
if (command === "shutdown") {
if (message.content.toLowerCase() == "shutdown") {
}
message.channel.send("Shutting down...").then(() => {
bot.destroy();
}
You missed a closing ) and }, this is easier to see with formatting:
if (command === "slap") {
const options = [
"https://tenor.com/view/no-angry-anime-slap-gif-7355956",
"https://tenor.com/view/when-you-cant-accept-reality-slap-anime-gif-14694312",
"https://tenor.com/view/anime-slap-slap-in-the-face-smash-gif-17314633"
]
if (message.mentions.users.first()) {
message.channel.send(message.author.username + " slapped " + message.mentions.users.first().username)
} else {
message.channel.send("You have to mention a user to slap")
}
}
if (command === "shutdown") {
if (message.content.toLowerCase() == "shutdown") {
}
message.channel.send("Shutting down...").then(() => {
bot.destroy();
})
}
Related
Not sure how to get the id of my target because it keeps reading it as undefined. I may have set up my argument incorrectly but I'm fairly sure that's not the issue. My command to kick is !o kick #user kick reason if that helps.
const { message } = require("discord.js")
module.exports = {
name: 'kick',
description: 'This command kicks a member',
execute(message, args){
if (message.member.hasPermission(["KICK_MEMBERS"])) {
const target = message.mentions.members.first();
if(target){
let [target, ...reasonKick] = args;
[...reasonKick].join(' ');
message.guild.members.cache.find(target => target.id)
const memberTarget = message.guild.members.cache.get(target.id);
if (message.guild.me.hasPermission("KICK_MEMBERS")) {
if (message.author.id === memberTarget) {
message.reply('why would you want to kick yourself?');
}
else if (message.client.user.id === memberTarget) {
message.channel.send('Nice try, but you can\'t kick me.')
}
else if (message.member.roles.highest.position > message.guild.members.cache.get(memberTarget).roles.highest.position) {
memberTarget.kick()
message.channel.send(`**${target.tag}** has been kicked. Reason: **${reasonKick}**.`);
}
else {
message.reply(`I don\'t have the required permission to kick **${target.tag}**`);
}
} else {
message.reply('I don\'t have the required permission to kick members');
}
} else{
message.reply('you must mention the member you want to kick.')
.catch;
}
} else {
message.reply("you do not have the permission to do that.")
.catch;
}
},
};
// - someCollection.find('property', value);
// + someCollection.find(element => element.property === value)
A mention already returns a member object, theres no need to try and get a member based on the mention's id.
Replace all of your memberTarget, with target
I'm using discord.js v12 and I'm trying to make a account that adds a role or removes it if the user already has the role but I get error SyntaxError: unexpected token "{" I tried to find what's wrong but couldn't find anything please help
module.exports = {
name: 'notifications',
description: 'Adds/removes the order ping from you',
aliases: ['notif'],
execute(message) {
pingrole = '809748975162359809'
if (message.member.roles.cache.some(c => c.id === "Cybers taco stand employee") {
if (message.member.roles.cache.some(r => r.name === "orders ping")) {
message.author.roles.add(pingrole)
message.channel.send("Added your orders ping")
} else {
message.author.roles.remove(pingrole)
message.channel.send("Removed your orders ping role")
}
} else {
message.channel.send('You are not an employee')
}
}
}
You didn't declare the variable and you were missing one ")" at the end of if statement.
module.exports = {
name: 'notifications',
description: 'Adds/removes the order ping from you',
aliases: ['notif'],
execute(message) {
let pingrole = '809748975162359809'
if (message.member.roles.cache.some(c => c.id === "Cybers taco stand employee")) {
if (message.member.roles.cache.some(r => r.name === "orders ping")) {
message.author.roles.add(pingrole)
message.channel.send("Added your orders ping")
} else {
message.author.roles.remove(pingrole)
message.channel.send("Removed your orders ping role")
}
} else {
message.channel.send('You are not an employee')
}
}
}
Okay so I am having trouble trying to DM a user who was kicked from the server right now it DM's the person who kicked the member. I don't know what I did wrong but I want the bot to DM the user who was kicked so they know why they were kicked frokm the server
const { RichEmbed } = require("discord.js")
const { red_dark } = require("../../colors.json");
module.exports = {
name: "kick",
description: "Kick a user from the guild!",
usage: "!kick",
category: "moderation",
accessableby: "Moderator",
aliases: ["k"],
run: async (bot, message, args, user) => {
try{
if (message.member.hasPermission("KICK_MEMBERS")) {
if (message.mentions.users.size != 0) {
if (message.mentions.members.first().kickable) {
let reason = args.slice(1).join(" ")
if(!reason) return message.channel.send("No reason was provided!")
else {
message.member.send("This is a test message")
message.mentions.members.first().kick().then(m => {
message.channel.send(`**${m.user.username}** has been kicked from **${message.guild.name}**. Bye bye!`)
});
}
} else {
message.channel.send(`:x: **${message.mentions.user.first().username}** is too priveledged for me to kick.`);
}
} else {
message.channel.send(':x: Please tag the user you would like to kick.')
}
} else {
message.channel.send(`:x: **${message.author.username}**, You do not have permission to kick. You must have the \`Kick Members\` permission.`);
}
} catch (err) {
message.channel.send(`:x: Either I am unable to kick **${message.mentions.users.first().username},** or I do not have permission to kick members.`);
}
}
}
You currently send a the DM to message.member. What you would need to do it to send it to the same person you actually kick, which you currently do with message.mentions.members.first().kick().
So with that clarified, you need to do message.mentions.members.first().send("This is a test message")
I just found this issue because I was trying to solve the duplicate post request issue when I am using workbox-background-sync. There is a function of my web app to upload the photos. But every time I did uploaded twice to the database. Here is the code I have:
const bgSyncQueue = new workbox.backgroundSync.Queue(
'photoSubmissions',
{
maxRetentionTime: 48 * 60,//48 hours
callbacks: {
queueDidReplay: function (requests) {
if (requests.length === 0) {
removeAllPhotoSubmissions();
}
else {
for(let request of requests) {
if (request.error === undefined && (request.response && request.response.status === 200)) {
removePhotoSubmission();
}
}
}
}
}
});
workbox.routing.registerRoute(
new RegExp('.*\/Home\/Submit'),
args => {
const promiseChain = fetch(args.event.request.clone())
.catch(err => {
bgSyncQueue.addRequest(args.event.request);
addPhotoSubmission();
changePhoto();
});
event.waitUntil(promiseChain);
},
'POST'
);
It may because the fetch(args.event.request.clone()). If I remove it, then there is no duplication anymore. I am using workbox 3.6.1 .
Finally I found the solution. Below is my code:
const photoQueue = new workbox.backgroundSync.Plugin('photoSubmissions', {
maxRetentionTime: 48 * 60, // Retry for max of 48 Hours
callbacks: {
queueDidReplay: function (requests) {
if (requests.length === 0) {
removeAllPhotoSubmissions();
}
else {
for(let request of requests) {
if (request.error === undefined && (request.response && request.response.status === 200)) {
removePhotoSubmission();
}
}
}
}
}
});
const myPhotoPlugin = {
fetchDidFail: async ({originalRequest, request, error, event}) => {
addPhotoSubmission();
changePhoto();
}
};
workbox.routing.registerRoute(
new RegExp('.*\/Home\/Submit'),
workbox.strategies.networkOnly({
plugins: [
photoQueue,
myPhotoPlugin
]
}),
'POST'
);
I removed fetch. If we still want to controll by ourselves, we need to use respondWith(). I have tested it, it is working. But I would like to use more workbox way to solve the problem. I am using workbox 3.6.3 and I created my own plugin to include a callback function fetchDidFail to update my views. Here are the references I found:
one and two. There are no duplicate posts anymore.
I added the IceCandidate after completing the offer and answer, but it still calls errors: 'RTCPeerConnection': the icecandidate cannot be added. This is part of my code:
else if (data.user_type == 'signaling') {
if (!rtcPeerConn)
startSignaling();
var message = JSON.parse(data.user_data);
if (message.sdp) {
rtcPeerConn.setRemoteDescription(new RTCSessionDescription(message.sdp),
function () { // if we received an offer, we need to answer
if (rtcPeerConn.remoteDescription.type == 'offer' && myUserType=="doctor") {
rtcPeerConn.createAnswer(sendLocalDesc, logError);
}
}, logError);
} else {
rtcPeerConn.addIceCandidate(new RTCIceCandidate(message.candidate));
}
}