(node:10124) DeprecationWarning: Collection#find: pass a function instead - discord.js

when i execute !x command it says
(node:10124) DeprecationWarning: Collection#find: pass a function instead
(node:10124) DeprecationWarning: Collection#find: pass a function instead
the issue is at ...let channe.. ..downchan... as the console log says
exports.startScrim = function(guild,host,type,time){
const embed = new RichEmbed()
.setColor(0x91bbff)
.addField("message x","another message"+exports.one(time),false)
.addField("Mode",type.toUpperCase(),true)
.addField("Host",host,true)
.addField("Instructions","message x",false)
let channel = guild.channels.find("name",guilds[guild.id].digitchan);
let channel2 = guild.channels.find("name",guilds[guild.id].countdownchan);
if (channel && channel2) {
channel.send(embed)`
and the next line channel.send(embed) is not even executing. help!

This looks like a duplicate of:
Collection#find: pass a function instead
Sounds like you need to do:
let channel = guild.channels.find(channel => channel.name === guilds[guild.id].digitchan);
let channel2 = guild.channels.find(channel => channel.name === guilds[guild.id].countdownchan);

Related

Same value in replit database

i am having a problem that whenever i type the +warn <#user> then everything goes well , lets take an example that i want to warn any user so i'll type +warn <#user> and then it will show a embed by saying that your are banned by this this and you are banned from this this and also shows that how many warns the user now have and lets also take that he have 1 warn till now, and now warn another user by typing +warn <#user> and then it will show the thing blah blah blah but.. when the bot shows that how many warns the second user have then it will show the same value of warn as the first user like this warns(of the first user): 1 but when with the second user it shows warns(of the second user): 2 and even the second user have 0 warns but it will show 2 and when you retry to warn the first user it will show 3 warns idk why
code:-
const config = require("../config.json");
const Database = require("#replit/database")
const db = new Database()
const { MessageEmbed, username } = require('discord.js')
exports.run = async (client, message, args, Discord) => {
let reason = args.slice(1).join(" ")
if (!reason) reason = "No reason provided"
const user = message.author.id
let warns = await db.get(`warns_${message.author.id}`)
let member = message.mentions.members.first()
if (!member) return message.reply("Please mention a user to warn")
const wembed = new MessageEmbed()
.setTitle(`You have been warned`)
.setDescription(`You have been warned by ${message.author.username}\nFrom the server of: ${message.guild.name}\nWith the reason: ${reason}\nNow you have ${warns} warns`)
if (!member === member.user.bot) {
member.send({embeds: [wembed]})
} else {
message.channel.send(`unable to send dm to ${member}`)
}
const embed = new MessageEmbed()
.setTitle(`Warn to ${member}`)
.setDescription(`${member} has been warned successfully warned\n\n${member} have now ${warns}\nReason: ${reason}`)
message.channel.send({embeds: [embed]})
await db.set(`warns_${message.author.id}`, warns + 1)
member.send({embeds: [wembed]})
}
exports.conf = {
aliases: ['warning']
};
exports.help = {
name: "warn"
};```

TypeError: Cannot read property 'send' of undefined discord.js v12

i have this reaction role system everything works up to the last part where the coulour slection happens
async run(message, client, con) {
await message.channel.send("Give the color for the embed.")
answer = await message.channel.awaitMessages(answer => answer.author.id === message.author.id,{max: 1});
var color = (answer.map(answers => answers.content).join()).toUpperCase()
if(color.toUpperCase()==='CANCEL') return (message.channel.send("The Process Has Been Cancelled!"))
function embstr(){
var finalString = '';
for(var i =0;i<n;i++){
finalString += b[i]+ ' - '+a[i] +'\n';
}
return finalString;
}
const botmsg = message.client.channels.cache.get(channel => channel.id === reactChannel)
const embed = new MessageEmbed()
.setTitle(embtitle)
.setColor(color)
.setDescription(embstr());
botmsg.send(embed);
message.channel.send("Reaction Role has been created successfully")
here is the error message
{
"stack": "TypeError: Cannot read property 'send' of undefined
at SlowmodeCommand.run (B:\\stuff\\Downloads\\Admeeeeeen bot\\src\\commands\\reactionroles\\createreactionrole.js:100:22)
at processTicksAndRejections (node:internal/process/task_queues:93:5)"
}
The .get() method takes in a snowflake as its parameter. AKA an ID of a certain object. It is not an iterator, meaning that what you're currently attempting to do is not right JavaScript wise.
Instead of passing in a parameter to represent a channel object, we'll just want to pass in the ID of the channel that we'd like to get. Alternatively, you could replace .get() with .find() there, which is in fact an iterator that uses this form of a callback, although it's insufficient in our case considering we can just use .get() which is more accurate when it comes to IDs.
/**
* Insufficient code:
* const botmsg = message.client.channels.cache.find(channel => channel.id === reactChannel)
*/
const botmsg = message.client.channels.cache.get(reactChannel /* assuming that reactChannel represents a channel ID */)

How to make this bot listen to argument after prefix and answer?

so i'm trying this 8ball bot, and everything is working fine, but i can't get how can i leave in the condition that only when the bot get "!verda arg1 arg2" it answers one of the replies in the array.
meanwhile my condition is if the user type the prefix "!verda" only, it replies , i want to include the argument too in the condition
const Discord = require("discord.js");
const client = new Discord.Client();
const cfg = require("./config.json");
const prefix = cfg.prefix;
client.on("message", msg => {
if (!msg.content.startsWith(prefix) || msg.author.bot) return;
const args = msg.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase;
if (msg.content === prefix){
let replies = [
"Yes.",
"No.",
"I don't know.",
"Maybe."
];
let result = Math.floor((Math.random() * replies.length));
msg.channel.send(replies[result]);
}
else if (msg.content === "!help"){
msg.channel.send("I have only 1 command [!verda]");
}
})
client.login(cfg.token);
const command = args.shift().toLowerCase;
toLowerCase is a function and therefore should be
const command = args.shift().toLowerCase();
By doing msg.content === prefix, you are checking if the whole content of the message is equal to that of cfg.prefix
if(msg.content.startsWith(`${prefix}8ball`) {
}
The answer was simple as i figured it out, i simply had to join the spaces
if (msg.content === `${prefix} ${args.join(" ")}`)

How to make a counter of people who have been invited to the server?

Its my code
var args = message.content.slice(prefix.length).trim().split(/ +/g);
var command = args.shift().toLowerCase()
if(command == "myinv"){
var invs = (await message.member.guild.fetchInvites().then(invites => invites.findAll("memberCount"))).values()
return message.channel.send(elo)
}
When i use command i got error like this:
(node:22680) DeprecationWarning: Collection#findAll: use Collection#filter instead
(node:22680) UnhandledPromiseRejectionWarning: Error: Value must be specified.
Can anyone help me?
Discord collection has no method .findAll, the one way to get count of invites uses, its
get serverinvites, then filter this collection, because discord not guaranteed property of invite.uses, then you can reduce it for get a summ.
var args = message.content.slice(prefix.length).trim().split(/ +/g);
var command = args.shift().toLowerCase()
if(command == "myinv"){
let invites = message.member.guild.fetchInvites().then(invites => {
let countInvites = invites.filter(invite => (invite.hasOwnProperty('uses'))).reduce((a, b) => {
a.uses + b.uses
}, 0)
message.channel.send(`Total server invite uses: **${countInvites}**`)
})
}

"checkwarns" command giving me this error

Whenever I use my checkwarns command to check the number of warns a user has it gives me this error:
2019-03-20T23:55:35.590941+00:00 app[worker.1]: (node:4)
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'warns' of
undefined
2019-03-20T23:55:35.590958+00:00 app[worker.1]: at
Object.module.exports.run (/app/commands/checkwarns.js:10:35)
I don't know how to fix this I can't find any problems with my code.
const Discord = require("discord.js");
const fs = require("fs");
const ms = require("ms");
let warns = JSON.parse(fs.readFileSync("./warnings.json", "utf8"));
module.exports.run = async(bot, message, args) => {
if (!message.member.hasPermission("MANAGE_MESSAGES")) return
message.reply("You don't have permssion to use this command");
let wUser = message.guild.member(message.mentions.users.first()) ||
message.guild.members.get(args[0])
if (!wUser) return message.reply("Couldn't find that user");
let warnlevel = warns[wUser.id].warns;
if (!warns[wUser.id]) warns[wUser.id] = {
warns: 0
};
message.delete().catch();
let warnembed = new Discord.RichEmbed()
.setTitle("**warns**")
.setColor("#0xff80ff")
.addField("User Warns", warnlevel, true);
message.channel.send(warnembed);
}
module.exports.help = {
name: "checkwarns"
}
I'm using Heroku to host the bot.
Your issue might be occuring here:
let warnlevel = warns[wUser.id].warns;
If the key wUser.id doesn't exist, the value of warns[wUser.id] would be undefined, which doesn't contain any user-defined properties. Hence, you get an error trying to read the value of warns (a user-defined property) in undefined.
To get around this, you want to check whether an object at warns[wUser.id] actually exists first. An easy way to do this is by doing the following:
var warnLevel;
if (warns[wUser.id] != undefined) {
warnLevel = warns[wUser.id].warns
}
else {
// Do something else to initialize either warnLevel or warns[wUser.id] here
}

Resources