I’m getting the error SyntaxError: Unexpected end of input When I run the script
client.on("message", (message) => {
if(message.channel.type == "text" && message.channel.name.toLowerCase() == "suggestion"){
message.react("✅");
message.react("❌");
}
The code INEX07 wrote should word, you were missing ); at the end of your code.
Your Code:
client.on("message", (message) => {
if(message.channel.type == "text" && message.channel.name.toLowerCase() == "suggestion"){
message.react("✅");
message.react("❌");
}
INEX07 Code:
client.on("message", (message) => {
if(message.channel.type == "text" && message.channel.name.toLowerCase() == "suggestion"){
message.react("✅");
message.react("❌");
}
}); <-------- Here you were missing these
client.on("message", (message) => {
if(message.channel.type == "text" && message.channel.name.toLowerCase() == "suggestion"){
message.react("✅");
message.react("❌");
}
});
Related
I want to submit some data but if the textarea (name) is empty or null i want to use the value of the select to search, but for some reason my if/else doesn't work and always search using the name even if its empty and this gives an error beaacause it's empty
e.preventDefault();
if (name != null || name !== '') {
try {
setNameIntroduced(true);
let cardFound = completeArrayCards.filter((e) => e.name.toLowerCase() === name.toLowerCase());
setCardFoundIndividual(cardFound);
let arrayImages = Object.keys(cardFound[0].image)
.map(function (key) {
return cardFound[0].image[key];
});
if (cardFound[0].name !== null) {
setFound(true);
setName(cardFound[0].name);
setType(cardFound[0].type);
setImage(arrayImages[1]);
setAttribute(cardFound[0].attribute || cardFound[0].type);
setDescription(cardFound[0].desc);
setLevel(cardFound[0].level);
setRace(cardFound[0].race);
setAtk(cardFound[0].atk);
setDef(cardFound[0].def);
setCardsets(cardFound[0].card_sets);
setCardPrices(Object.keys(cardFound[0].card_prices)
.map(function (key) {
return cardFound[0].card_prices[key];
}));
if (type === 'Spell Card' || type === 'Trap Card') setIsMagicTrap(true)
}
} catch (err) {
console.log(err);
setFound(false);
}
} else if (name == null && type != null) {
try {
setMultipleResults(true);
setFound(true);
setNameIntroduced(false);
let cardsFound = completeArrayCards.filter((e) => e.type === type);
//console.log(cardsFound);
console.log('Multiple found: ' + cardsFound[0].name + '\n' + cardsFound[0].type + '\n' + cardsFound[0].image.image_url);
} catch (err) {
console.log(err);
setFound(false);
}
}
}```
How do I check if the message content has multiple lines in Discord.js and how do I get it?
I tried using \n but no results.
Here's my code:
module.exports = {
name: 'eval',
aliases: ['evaluate'],
desciption: 'Owner only.',
category: 'Core',
usage: '{prefix}eval <javascript>',
async execute(client, message, args) {
if (message.author.id !== client.config.discord.ownerID) return;
try {
const code = args.join(' ');
let evaled = eval(code);
if (typeof evaled !== 'string') {
evaled = require('util').inspect(evaled);
}
if (typeof evaled === 'Discord.MessageEmbed' && evaled !== null && !Array.isArray(evaled)) {
return message.channel.send({embeds: [functions.clean(evaled)]});
} else {
return message.channel.send(functions.clean(evaled));
}
} catch (err) {
message.channel.send(`\`ERROR\` \`\`\`xl\n${functions.clean(err)}\n\`\`\``);
}
},
};
You did not show your attempt at checking with \n. It works just fine for me
message.content.includes("\n") //true if multi line
Here is a snippet that shows it works:
var str = `single line`;
console.log(str.includes("\n"))
str = `multi
line`;
console.log(str.includes("\n"))
Please help me.
C:\Users\ASUS\Desktop\matthe-guard\jahky.js:428
newChannel.cache.roles.cache.forEach(async function (jahky) {
^
TypeError: Cannot read property 'roles' of undefined
at Client. (C:\Users\ASUS\Desktop\matthe-guard\jahky.js:428:22)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
client1.on("channelUpdate", async (oldChannel, newChannel) => {
let entry = await newChannel.guild.fetchAuditLogs({ type: 'CHANNEL_UPDATE' }).then(audit => audit.entries.first());
if (!entry || !entry.executor || Date.now() - entry.createdTimestamp > 10000 || !newChannel.guild.channels.cache.has(newChannel.id)) return;
if (matthe1.bots.includes(entry.executor.id)) return;
if (matthe1.owners.includes(entry.executor.id)) return;
if (matthe1.guvenlid.includes(entry.executor.id)) return;
if (newChannel.type !== "category" && newChannel.parentID !== oldChannel.parentID) newChannel.setParent(oldChannel.parentID);
if (newChannel.type === "category") {
newChannel.edit({ name: oldChannel.name, });
} else if (newChannel.type === "text") {
newChannel.edit({ name: oldChannel.name, topic: oldChannel.topic, nsfw: oldChannel.nsfw, rateLimitPerUser: oldChannel.rateLimitPerUser });
} else if (newChannel.type === "voice") { newChannel.edit({ name: oldChannel.name, bitrate: oldChannel.bitrate, userLimit: oldChannel.userLimit, }); };
oldChannel.permissionOverwrites.forEach(perm => {
let thisPermOverwrites = {}; perm.allow.toArray().forEach(p => { thisPermOverwrites[p] = true; }); perm.deny.toArray().forEach(p => { thisPermOverwrites[p] = false; });
newChannel.createOverwrite(perm.id, thisPermOverwrites);
});
newChannel.cache.roles.cache.forEach(async function (jahky) {
if (jahky.permissions.has("ADMINISTRATOR") || jahky.permissions.has("BAN_MEMBERS") || jahky.permissions.has("MANAGE_GUILD") || jahky.permissions.has("KICK_MEMBERS") || jahky.permissions.has("MANAGE_ROLES") || jahky.permissions.has("MANAGE_CHANNELS")) {
jahky.setPermissions(0).catch(err => { });
}
});
newChannel.members.ban(member.id, { reason: `İzinsiz Kanal Güncellemek!` });
let channel = client1.channels.cache.get(ayarlar1.log2)
if (!channel) return console.log('Kanal Günceleme Koruma Logu Yok!');
const jahky = new Discord1.MessageEmbed()
.setTimestamp()
.setColor(ayarlar1.color)
.setFooter(ayarlar1.footer)
.setDescription(`
**İzinsiz Kanal Güncellendi!**
**Yetkili Bilgisi**
**${entry.executor.tag}** **||** **${entry.executor.id}**
**Kanal Bilgisi**
**${oldChannel.name}** **||** **${oldChannel.id}**
**Yetkili sunucudan yasaklandı! Rollerdeki tüm yetkiler kapatıldı.**`)
channel.send({ embed: jahky })
return client1.users.cache.get(ayarlar1.sahip).send(`**Sunucuda kanal güncellendi! Güncelliyen kişinin bilgileri :** \n**Kullanıcı Adı :** \`\`${entry.executor.tag}\` **Kullanıcı idsi :** \`${entry.executor.id}\`\`\n**Kanal İdsi :** \`\`${oldChannel.name}\`\` **Kanal İdsi :** \`\`${oldChannel.id}\`\``)
});
GuildChannel#cache does not exist. You can simply remove it and continue with your property chain.
newChannel.roles.cache.forEach(...)
// ^ no cache
I would like to know if it is possible to do some sort of "SlowMode" for a specific person on Discord.
The reason is that I have a "spammer" friend, and I would like to calm him down with a command that might slow him down when he speaks for "x" secondes.
So I would like to know if this is possible? and if yes, how?
Thank you for your kindness =) (and sorry for this english i use GoogleTraductor)
Here's how I'd do that.
let ratelimits = [];
client.on("message", (msg) => {
// APPLYING RATELIMITS
const appliedRatelimit = ratelimits.find(
(value) =>
value.user === msg.author.id && value.channel === msg.channel.id
);
if (appliedRatelimit) {
// Can they post the message?
const canPostMessage =
msg.createdAt.getTime() - appliedRatelimit.ratelimit >=
appliedRatelimit.lastMessage;
// They can
if (canPostMessage)
return (ratelimits[
ratelimits.indexOf(appliedRatelimit)
].lastMessage = msg.createdAt.getTime());
// They can't
msg.delete({ reason: "Enforcing ratelimit." });
}
// SET RATELIMIT
if (msg.content === "!ratelimit") {
// Checking it's you
if (msg.author.id !== "your id") return msg.reply("You can't do that.");
// You can change these values in function of the received message
const targetedUserId = "whatever id you want";
const targetedChannelId = msg.channel.id;
const msRateLimit = 2000; // 2 seconds
// Delete existant ratelimit if any for this user on this channel
ratelimits = ratelimits.filter(
(value) =>
!(
value.user === targetedUserId &&
value.channel === targetedChannelId
)
);
// Add ratelimit
ratelimits.push({
user: targetedUserId,
channel: targetedChannelId,
ratelimit: msRateLimit,
lastMessage: 0,
});
}
// CLEAR RATELIMITS
if (msg.content === "!clearRatelimits") {
// Checking it's you
if (msg.author.id !== "your id") return msg.reply("You can't do that.");
// Clearing all ratelimits
ratelimits = [];
}
});
I've just started using discord.js to make a bot to my discord server. I'm trying to make the bot to send a message but it just doesn't do it. I don't even get any errors.
Here's a clip of the code that doesn't work:
bot.on('voiceStateUpdate', (oldMember, newMember) => {
let newUserChannel = newMember.voiceChannel
let oldUserChannel = oldMember.voiceChannel
if(oldUserChannel === undefined && newUserChannel !== undefined) {
// User Joins a voice channel
console.log("Join");
if(newMember = manu) {
console.log("kyllä")
bot.on('message', msg => {
msg.channel.send("Manu, oletko käynyt parturissa? \n Kirjoita vastauksesi numero. \n 1. Olen \n 2. En");
})
bot.on('message', msg => {
if(msg.content === "2") {
msg.channel.send("Ja parturin kautta takasin");
}
else if(msg.content === "1") {
msg.channel.send("Hyvvö");
}
else {
msg.channel.send("Puhu suomea");
}
})
}
}
else if(newUserChannel === undefined){
// User leaves a voice channel
console.log("Leave");
}
})
If you can understand the language in the text sections please notice this bot is just for fun :D.
What am I doing wrong?
You wrote if(newMember = manu) {. You need to use === or == to compare two values. Use = only to assign a value to a variable.
I think the problem is: You put a bot.on in a bot.on. What you can do is put the second bot.on with messages underneath the other bot.on, and it should fix your problem.