discord.js

Getting ID from tagged user

好久不见. 提交于 2019-12-11 07:49:13
问题 Hey I was wondering if I can check if someone is being tagged and if they are get the user ID of the person tagged and use it as reporting let [cmd, user, proof, reason] = msg.content.split(' '); let reporting = user //user being reported (usually tagged) let reported = msg.author.tag let reportedID = msg.author.id let embedReply = new Discord.RichEmbed() .setColor("PURPLE") .setTitle("Ready to send?") .setDescription("Please check if this is correct:") .addField("Your name:", `${reported} ($

Way to check if a channel exists

家住魔仙堡 提交于 2019-12-11 06:29:28
问题 module.exports.run = async (bot, message, args) => { let ticketreason = args[1]; let ticketname = "ticket" + ticketreason; message.guild.createChannel("tickets", "category") message.guild.createChannel(ticketname, "text"); } So I've got this very simple and basic code here. I am trying to find a way to check if a channel exists before creating it. I've attempted to search around the discord.js documentation a few times for a solution, but I've had no luck so far. I need an explanation for how

Sending a message the first channel with discord.js

耗尽温柔 提交于 2019-12-11 05:19:32
问题 I've seen a lot of bots that have a greeting message when they join. Its usually sent to the first channel of the server. For example: bot joins the guild Bot: Hey! Thanks for inviting me! The code i have right now is really simple: client.on("guildCreate", guild => { the code goes here }); I dont know how to send a message to a random (first) channel though. If anyone could please tell me how the other bots do it I would be really greatful. 回答1: I'm using Discord.js version 11.4.2, and I was

Command to send text to a specific channel

孤街醉人 提交于 2019-12-11 04:51:49
问题 I want to make a command that sends the text to a channel of my choosing. Example: !command "text" Then the "text" is sent to the channel I chose. 回答1: That's the same code from this thread, I just modified a little part as I told you in the comments. client.on('message', msg => { if (msg.guild && msg.content.startsWith('/log')) { let text = msg.content.slice('/log'.length); // cuts off the /log part let channel = msg.guild.channels.find('name', 'channel_name_here'); if (channel) channel.send

Check if user ID exists in Discord server

夙愿已清 提交于 2019-12-11 04:11:39
问题 My Discord bot needs to check whether a user is in the server or not. I'm using node.js and discord.js. var USER_ID = randomNumbers if (client.guild.member(USER_ID).exists){ do something } Is there a way to do this? 回答1: If you have the Guild object, you can use the Guild.member() method. let guild = client.guilds.get('guild ID here'), USER_ID = '123123123'; if (guild.member(USER_ID)) { // there is a GuildMember with that ID } 回答2: This is very similar to Way to check if a channel exists and

Adding a role (autorole) on join from a json file

你。 提交于 2019-12-11 04:08:20
问题 I am fairly new to JS, and to learn I decided to make a bot for Discord, I have learned a lot and am continuing to learn. I had the idea for an "autorole". I know the conventional way of doing it. bot.on('guildMemberAdd', member => { var role = member.guild.roles.find('name', 'Member'); member.addRole(role); }); However, I want it to get the role from a .json file. The rest of the code is fine, I can write to the json with >autorole Role . I am just unsure on how to incorporate the json into

Variable for toggle function and enabling/disabling

冷暖自知 提交于 2019-12-11 01:39:10
问题 As in my previous question I was making a troll function now I'm trying to figure out how to make it toggle to make it work so my friend doesn't have to ban it every now and then. The toggle command works but its not actually internally working. NOTE: I have two discord accounts so I could test it on the other one. The part where it uses the toggle is in the bottom const Discord = require("discord.js"); const client = new Discord.Client; var enabled = true client.on("message", message => { if

How to reply to any DMs sent to the bot?

随声附和 提交于 2019-12-10 19:17:43
问题 I am trying to make my bot replying to any DM sent to it. So I currently have this: client.on('msg', () => { if (msg.channel.DMChannel) { msg.reply("You are DMing me now!"); } }); But unfortunately, it does not reply to any DM. I've tried to replace msg.channel.DMChannel with msg.channel.type == 'dm' but this didn't work. I also tried to replace msg.reply with msg.author.send and msg.channel.send but they all didn't work. Any help would be appreciated. Thanks! 回答1: On the official

Discord bot: Fix ‘FFMPEG not found’

只愿长相守 提交于 2019-12-10 15:25:00
问题 I want to make my Discord bot join voice chat but every time I make it I get a error into log(cmd) saying, FFMPEG not found , please help me. Picture of the error: This is the code: client.on('message', message => { // Voice only works in guilds, if the message does not come from a guild, // we ignore it if (!message.guild) return; if (message.content === '/join') { // Only try to join the sender's voice channel if they are in one themselves if (message.member.voiceChannel) { message.member

Is there a command to send private message to all members of a group?

梦想与她 提交于 2019-12-10 12:17:45
问题 Is there any way to make a command send a private message to all members of the discord group using discord.js? Exemple: /private TEST This message is sent to everyone in the group in private chat instead of channel chat. 回答1: You can iterate through Guild.members. When you receive a message that starts with /private , you take the rest and send it to every member of the guild by using Guild.members.forEach(). Here's a quick example: client.on('message', msg => { if (msg.guild && msg.content