discord.js

How can I count the number of messages in one channel of each user?

人盡茶涼 提交于 2019-12-11 16:04:34
问题 I want to code a discord bot with the discord.js ... But in the documentation, I don't found a function to count the number of messages in a channel of each user... Is there a function to use the searchbar with filters like an user? 回答1: The search is not ( yet ) avaible for Bots. You could Channel#fetchMessages but this would be very Api intensive. Best way would be to get a database and increment it when the user sends a message, but that will only count messages when the bot is running. 来源

How to avoid having “quota exceeded for 'ReadGroup'” error in google api

∥☆過路亽.° 提交于 2019-12-11 15:59:09
问题 I've created a bot which goes in Google Spreadsheet getting some datas before sending them by DM to 50 guild members into Discord. However, due to high requests of datas, I've got an error message saying that I've exceeded the quota for group 'ReadGroup' and limit 'USER-100s'. To avoid getting this error, I've created a buffer function however it still doesn't work, does anyone know how to avoid getting this limit error? Here is the main code which is launched when I type a specific commande

Scheduled messages without setInterval()

感情迁移 提交于 2019-12-11 15:57:01
问题 I want to schedule some things like sending messages with my discord bot. E.g.: I want the bot to send "Good Morning" every day at 8 am or announce some things. My problem is: I can't use something like setInterval() to execute every 24 hours because if the bot goes offline or has to be restarted it would reset or delay the interval. Question: How do I execute something at a specific point in time without having to worry about the bot sometimes being offline? 回答1: You can use the cron package

How to check if .fetchMessage gets an actual message

一笑奈何 提交于 2019-12-11 15:54:18
问题 The title should get the word out quickly; I'm figuring out how to check if the message the bot fetched is actually a message or a fake ID. I've tried • if(!mmm) • if(mmm.deleted !== true) Didn't work. if (!args.length) return await message.channel.send(`You didn't provide a ID!`).then(msg => {msg.delete(30000)}).then(message.delete(50)).catch(error => console.log(error)); else if (isNaN(args)) { return message.reply('that doesn\'t seem to be a valid number.').then(msg => {msg.delete(30000)})

Discord.js - Guild ID is undefined even though definition is there

僤鯓⒐⒋嵵緔 提交于 2019-12-11 15:21:00
问题 Making a discord bot. Everything works fine, except the one command of -!prefix . -! being the prefix, and the command taking the args and changing the prefix of the server. Before I go into detail about this while thing, here's the bot's code, maybe I simply did something wrong in the consts: Hastebin Link The error here is in line 52, according to the console: Console Log I'm confused as to what to do with this being "undefined." I've tried using the message.guild.id property as the

Getting Bot Variable Into Different Commando Files

蹲街弑〆低调 提交于 2019-12-11 15:14:30
问题 I use commando for my discord.js bot, and it's linked to the client. I want to be able to use the bot variable in a different file, mainly to help check if the bot has the correct permissions. My Bot variable: const bot = new commando.Client({ commandPrefix: '!', owner: config.ownerID, unknownCommandResponse: false }); This is currently in my index.js file, but is there a way for me to be able to use it in a different command file? 回答1: You could do index.js const bot = new commando.Client({

Basic one-message dice roller?

淺唱寂寞╮ 提交于 2019-12-11 15:11:35
问题 This is the same discord bot I've asked about in the last question I posted here, and I want to add a simple dice rolling function that doesn't take up multiple messages so I don't spam the server I'm in. So far, I have the barebones code for the dice roller itself working here: if (message.content.toLowerCase().includes("rei!d100")) { var response = [Math.floor(Math.random() * ((100 - 1) + 1) + 1)]; message.channel.send(response).then().catch(console.error); } And as of right now it just

Add reaction of custom emoji to a message

三世轮回 提交于 2019-12-11 14:59:06
问题 What can I tweak in my code that will allow me to use custom emojis to react to a message? I have tried this: let suggestions = message.guild.channels.find("name", "suggestions"); if (message.channel === suggestions) { message.channel.send().then(newMessage => { newMessage.react('<:information :412438127148531723>') }) } But I receive the error: emoji_id: Value "412438127148531723>" is not snowflake. 回答1: EDIT: I didn't notice that you were trying to send an empty message via .send() , doing

discord.js send and wait before editing a message

随声附和 提交于 2019-12-11 14:53:11
问题 I want my bot, to send my emotes , wait 1 seconds and edit the message to my others emotes . Here's my code : message.channel.send('my emotes') .then((msg) => { setTimeout(function() { msg.edit('my other emotes'); }, 1000)}); And he send me this error : Cannot read property 'edit' of undefined Thanks you for helping me. 回答1: ok so finaly the code that works is : message.channel.send('my emote') .then((msg)=> { setTimeout(function(){ msg.edit('my others emotes'); }, 1000) }); 来源: https:/

Command Handler with Sub-Categorized folders

拈花ヽ惹草 提交于 2019-12-11 14:23:02
问题 This is the command handler I'm currently using, and it works as it's supposed to. try { let ops = { active: active } let commandFile = require(`./commands/${cmd}.js`) commandFile.run(client, message, args, ops); } catch (e) { console.log(e); } But as you can see, it just reads into the commands folder and pulls the .js files from there. What I'm looking to do, is to have the commands be sub-categorized for my own "OCD" purposes, so that I can keep track of them better on my end. Is there any