discord.js

How to add a role with an ID that is saved in an JSON file discord.js v12?

我怕爱的太早我们不能终老 提交于 2021-02-11 15:00:19
问题 I'm making a warn command and I've run into a problem with the role giving. First, I have a command that sets the warned role for the guild. It reacts to &setwarnedrole {role ID}. It saves the role ID into a JSON file, next to the guild ID. Then, the warn command reads the file, and gets the role ID that was stored with the guild ID the command is executed in. You use &warn {user ping/user ID} to warn people. But when I do that, it gives me an error: TypeError [INVALID_TYPE]: Supplied roles

Make a list of kickable members in Discord.js

爱⌒轻易说出口 提交于 2021-02-11 14:57:36
问题 So I am trying to clean up my old server, and I want my bot to kick everyone below a role named "bot". (and keep everyone above it) So I think (correct me if I am wrong) would be to create a list of kickable members and then kick each one (forEach). However, I can't find a way to make this list. Any help would be appreciated. Thanks! 回答1: You can compare role positions with Role.comparePositionTo // <guild> is a placeholder for the guild object const role = <guild>.roles.cache.find(r => r

I would like to have a message sent in a certain channel that the bot is turning off or on

此生再无相见时 提交于 2021-02-11 14:39:44
问题 So I'm new to making bots and coding and stuff and this might be a newbie question but anyway, I don't have a hosting server for my bot so i was thinking that maybe when the bot turned off it would send a message in a channel But I have no clue how to do that or if its possible. I was able to get it to happen when the bot turns on but I don't know how to have it occur when the bot turns off. I don't even know where to start. What I have so far is when I type node . in the terminal the bot

message.guild.members.getMember not working

老子叫甜甜 提交于 2021-02-11 14:27:09
问题 I am creating a user info command and DiscordJS keeps saying TypeError: message.guild.members.get is not a function The function I'm using is this let target = message.guild.members.getMember(toFind); Is there something I need to update with a newer version of DiscordJS? I haven't been able to find anything yet. Thanks, Jude Wilson 回答1: The new version of Discord.js is v12, there has been many breaking changes The function you are probably looking for is: message.guild.members.fetch(id) You

Server greetings

旧时模样 提交于 2021-02-11 14:21:46
问题 I tried to make server greetings message but it doesn't even work for me, I saw that you can try to do this using ch.name === 'name' but I want my bot to send message to channel with specific id client.on("guildMemberAdd", (member) => { const channel = member.guild.channels.cache.find((ch) => ch.id === `channel-id`); if (!channel) return; channel.send(`Welcome to the server, ${member}!`); }); 回答1: I believe you need to turn on Privileged Gateway Intents on the Dev Portal (https://discord.com

How to make discord.js 11 not case sensitive?

折月煮酒 提交于 2021-02-11 14:19:28
问题 I have an anti swear made in discord js 11 and it uses a file called bannedwords.txt. Is there a way I can make it read the file without being case sensitive. For instance if one of the banned words was chicken, I wanna make it so it bans CHICKen, CHicken, Chicken, chicken, ChiCKeN, you get the point. How do I do this? 回答1: You can use the toLowerCase() method of strings to achieve this. Simply call it on both the message being checked for swearing, and/or on the banned word it is being

discordjs using base64 image in webhook embed

吃可爱长大的小学妹 提交于 2021-02-11 14:18:36
问题 How do I insert an image into a discord embed using webhook. I have the image saved as a base64 string which I get from database. I have tried this but I only get an empty embed const data = b64image.split(',')[1]; const buf = new Buffer.from(data, 'base64'); const file = new Discord.MessageAttachment(buf, 'img.jpeg'); const embed = new Discord.MessageEmbed() .setImage('attachment://img.jpeg') webhookClient.send('', { username: userName, embeds: [embed], }); 回答1: I tried with a smaller image,

Random Message Reply Discord.js 2020

≡放荡痞女 提交于 2021-02-11 14:17:49
问题 I've been trying to put a random reply but the other answers and tutorials I found didn't exactly work. Most of the tutorials have const messages = [ "seriously?! You thought I would reply", "hm, yeh thats a pretty random question - Don't ya think?", "Ok I'm actually running out of options now", "Please stop asking me", "Ok, im done!", "⛔" ]; const randomMessage = messages[Math.floor(Math.random() * messages.length)]; And to complete it and send the message module.exports = { name: 'random',

Make discord bot (js) echo message, but removing the command from the message?

末鹿安然 提交于 2021-02-11 13:50:33
问题 So what I want in the end is this: user: "*cmd hello" bot: "hello" I tried replacing it, searched different ways to edit it, but nothing worked so far. if (receivedMessage.content.includes("*cmd")) { receivedMessage.content.replace('*cmd', ' '); receivedMessage.channel.send(receivedMessage.content); receivedMessage.channel.send("s/*cmd/-"); } (^found out that you can edit stuff by typing s/oldtext/newtext, but sadly it doesn't seem to work with the bot. Replacing didn't work, either.) if

Discord bot sends response twice

风流意气都作罢 提交于 2021-02-11 13:41:40
问题 I'm coding a discord.js bot, and whenever I send a command, it gives a response twice. I've concluded it's because I have too many instances running. I try to delete the instances, but it doesn't delete. Sometimes it says "Some instances could not be deleted", and sometimes it doesn't delete at all. And through Terminal SERVICE VERSION ID VM_STATUS DEBUG_MODE default 20191208t223728 aef-default-20191208t223728-0l57 RUNNING default 20191208t223728 aef-default-20191208t223728-jb53 RUNNING