discord.js

Reading files in chat using discord bot

北战南征 提交于 2020-01-16 08:05:08
问题 As an experiment, I was trying to find whether I could read files that were entered as attachments into chat eg: image files, txt, etc. I've been looking around for a long while and I have still found no information on it. So it possible to do this using Discord.js? If so, how would I go about doing it? 回答1: This can be done using the attachments property of a Message to find the attachment and consequently its URL. You can then download the URL using the http and fs modules. It would look

Reading files in chat using discord bot

冷暖自知 提交于 2020-01-16 08:04:30
问题 As an experiment, I was trying to find whether I could read files that were entered as attachments into chat eg: image files, txt, etc. I've been looking around for a long while and I have still found no information on it. So it possible to do this using Discord.js? If so, how would I go about doing it? 回答1: This can be done using the attachments property of a Message to find the attachment and consequently its URL. You can then download the URL using the http and fs modules. It would look

How can I check if the message author has an admin role using Discord.js?

女生的网名这么多〃 提交于 2020-01-16 04:25:27
问题 I'm building a Discord bot and I want to have an if statement that will only proceed if the message author has an administrator role in the guild. I've tried having role-specific permissions, but this means that there will have to be the exact same name role on all servers that the bot is on. How can I check if the message author has an admin role? (The role has the administrator permission.) 回答1: There's really three different questions needed to be addressed here. They're all related, but

Is there anyway to mark images as spoiler?

佐手、 提交于 2020-01-15 09:30:56
问题 The new discord update added the feature to mark images and text as spoilers for text: you just have to type || text || . For images, there is a check mark at the bottom of the attachment prompt: Is there a way to mark images as spoiler or is the feature too new? This does not work: let image = new Attachment('./img/image.jpg'); message.channel.send("|| " + image + " ||");` 回答1: a quick way of doing it would be starting the filename with SPOILER_ for example img.png would become SPOILER_img

Scan a google document line by line

早过忘川 提交于 2020-01-15 03:26:09
问题 so basically, I'm trying to use node.js to scan a google document, then if a ROBLOX id is on there it tracks it. When it tracks it, if it joins one of the groups in the id list, it auto-exiles it. Any help? I'm a little stuck on the scanning a google document line by line. 回答1: I am not sure about how to do it from a google doc, but if you are willing to move to using text files( .txt ) I think I could be of assistance. Using Nodes FS we can read lines using a Line reader import * as fs from

How to detect if the bot has been mentioned?

送分小仙女□ 提交于 2020-01-14 07:01:34
问题 How can I detect if my bot is mentioned? I tried these thus far: if (msg.content.toLowerCase().includes('@The Guardian of The Bar#5180')) { msg.channel.send("My prefix here is" + prefix + "\n You can start with ``" + prefix + "help``"); } if (msg.content.toLowerCase().includes('@The Guardian of The Bar')) { msg.channel.send("My prefix here is" + prefix + "\n You can start with ``" + prefix + "help``"); } if (msg.content.includes('@The Guardian of The Bar#5180')) { msg.channel.send("My prefix

Send message and shortly delete it

为君一笑 提交于 2020-01-11 07:01:05
问题 I'm trying to make a Discord bot delete its "system messages" after, say, 10 seconds, because I've been seeing a lot of "Invalid command" errors and "Done!" notifications, and I'd like to clear them out for actual messages. This is different from deleting messages where the user has a command; I already have that capability. 回答1: I recommend you send the message, wait for the response and delete the returned message after that time. Here's how it'd work: message.reply('Invalid command') .then

Send message and shortly delete it

牧云@^-^@ 提交于 2020-01-11 06:59:09
问题 I'm trying to make a Discord bot delete its "system messages" after, say, 10 seconds, because I've been seeing a lot of "Invalid command" errors and "Done!" notifications, and I'd like to clear them out for actual messages. This is different from deleting messages where the user has a command; I already have that capability. 回答1: I recommend you send the message, wait for the response and delete the returned message after that time. Here's how it'd work: message.reply('Invalid command') .then

Discord bot still answering multiple times on one event

倾然丶 夕夏残阳落幕 提交于 2020-01-06 14:33:30
问题 Already found same issue, but there are no answer there :C So my problem is same, using Discord.js lib, and this is my code: client.on('message', msg => { var splittedMessage = msg.content.split("#"); if (msg.channel.type == "dm") { if (msg.content === "booya") { msg.channel.send('Hello there, ' + msg.author.username) .then(msg => console.log('Sent #' + msg.id + ': ' + msg.content)) .catch(console.error); return } else { msg.channel.send('No query found') .then(msg => console.log('Sent #' +

Getting an array from folder and sending a random file with discord.js

元气小坏坏 提交于 2020-01-06 14:29:46
问题 I'm trying to create a command, when requested will send a random image from a folder. I don't want to have to name them cause I have a server with a PHP server where my friends can upload images for the bot to post. This is what I have: if(command === "meme") { const path = '/img/memes/'; const fs = require('fs'); fs.readdirSync(path).forEach(file => { ranfile = Math.floor(Math.random()*file.length); message.channel.sendFile(ranfile); }) return; } When I run the bot with Node.js I get this