LengoLabs / qbot

Qbot is an advanced, easy to setup, free, and unbranded Discord-Roblox ranking bot. If at any time during setting it up you need assistance, you can join the support server.
https://discord.gg/J47m7t4
MIT License
75 stars 136 forks source link

How do I dm multiple people in one command instead of doing them one by one? #45

Closed frostgit-dev closed 4 years ago

frostgit-dev commented 4 years ago

Ok so, I tried everything like copy pasting args[0], and it did not work. Here is the code. No errors at all but it does not dm all the persons. This is a qbot plugin also just so you know I modified the dm command a bit by embedding it.

exports.run = async (client, message, args) => {
  let filter = (msg) => msg.author.id === message.author.id;
  if (
    message.member.roles.cache.some(role =>
      ["DM Permissions"].includes(role.name)
    )
  ) {
    let mention =
      (await message.mentions.members.first()) ||
      (await message.guild.members.cache.get(args[0]));
    const tosend = args.slice(1).join(" ");
    if (tosend) {
      if (mention) {
        await mention.send ({
              embed: {
                color: `RANDOM`,
                title: `Message from ${message.member.displayName}:`,
           description: `${tosend}`,
                footer: {
                  text: `United States Armed Forces`,
                  icon_url: `https://cdn.discordapp.com/emojis/72404865910268370`
                },
                timestamp: new Date()
              }
             })

          .then(async () => {
            message.channel.send({
              embed: {
                color: 9240450,
                description: "Successfully sent DM!",
                author: {
                  name: message.author.tag,
                  icon_url: message.author.displayAvatarURL()
                }
              }
            });
            if (process.env.logchannelid === "false") return;
            let logchannel = await message.guild.channels.cache.get(
              process.env.logchannelid
            );
            logchannel.send({
              embed: {
                color: 2127726,
                description: `<@${message.author.id}> (${message.author.tag}) sent a DM to <@${mention.id}> (${mention.user.tag}) saying: \`${tosend}\``,
                author: {
                  name: message.author.tag,
                  icon_url: message.author.displayAvatarURL()
                },
                footer: {
                  text: "DM Logs"
                },
                timestamp: new Date()
              }
            });
          })
          .catch(async (err) => {
            return message.channel.send({
              embed: {
                color: 16733013,
                description: "That person does not have their DMs on!",
                author: {
                  name: message.author.tag,
                  icon_url: message.author.displayAvatarURL()
                }
              }
            });
          });
      } else {
        let findname = await message.guild.members.fetch({
          query: args[0],
          limit: 1
        });
        if (findname.first().id) {
          const msg = await message.channel.send({
            embed: {
              color: 39423,
              description: `Do you want to send this DM to <@${
                findname.first().id
              }> (${findname.first().user.tag})?`,
              author: {
                name: message.author.tag,
                icon_url: message.author.displayAvatarURL()
              },
              footer: {
                text: `Options: yes | no`
              }
            }
          });
          message.channel
            .awaitMessages(filter, { max: 1, time: 60000 })
            .then(async collected => {
              if (collected.size === 0) {
                message.channel.send({
                  embed: {
                    description: `You took too long. Prompt cancelled.`,
                    color: 16733013,
                    author: {
                      name: message.author.tag,
                      icon_url: message.author.displayAvatarURL()
                    }
                  }
                });
              } else {
              let answer = collected.first().content.toLowerCase();
              if (answer === "no") {
                return message.channel.send({
                  embed: {
                    color: 9240450,
                    description: `Did not send a DM.`,
                    author: {
                      name: message.author.tag,
                      icon_url: message.author.displayAvatarURL()
                    }
                  }
                });
              } else {
              if (answer === "yes") {
        await findname.first()
          .send({
              embed: {
                color: `RANDOM`,
                title: `Message from ${message.member.displayName}:`,
              description: `${tosend}`,
                timestamp: new Date(),
                footer: {
                  text: `United States Armed Forces`,
                  icon_url: `https://cdn.discordapp.com/emojis/7240486591042370`
                },
              }
             })
          .then(async () => {
            message.channel.send({
              embed: {
                color: 9240450,
                description: "Successfully sent DM!",
                author: {
                  name: message.author.tag,
                  icon_url: message.author.displayAvatarURL()
                }
              }
            });
            if (process.env.logchannelid === "false") return;
            let logchannel = await message.guild.channels.cache.get(
              process.env.logchannelid
            );
            logchannel.send({
              embed: {
                color: 2127726,
                description: `<@${message.author.id}> (${message.author.tag}) sent a DM to <@${findname.first().id}> (${findname.first().user.tag}) saying: \`${tosend}\``,
                author: {
                  name: message.author.tag,
                  icon_url: message.author.displayAvatarURL()
                },
                footer: {
                  text: "DM Logs"
                },
                timestamp: new Date()
              }
            });
          })
          .catch(async (err) => {
            return message.channel.send({
              embed: {
                color: 16733013,
                description: "That person does not have their DMs on!",
                author: {
                  name: message.author.tag,
                  icon_url: message.author.displayAvatarURL()
                }
              }
            });
          });
              } else {
                return message.channel.send({embed: {
                  color: 16733013,
                  description: 'That is not a valid option.',
                  author: {
                    name: message.author.tag,
                    icon_url: message.author.displayAvatarURL()
                  }
                }})
              }
              }
            }
            });
        }
      }
    } else
      message.channel.send({
        embed: {
          color: 16733013,
          description: "You did not say what to send! Bruh.",
          author: {
            name: message.author.tag,
            icon_url: message.author.displayAvatarURL()
          }
        }
      });
  } else {
    message.channel.send({
      embed: {
        color: 16733013,
        description: "You need the `DM Permissions` role to use this command!",
        author: {
          name: message.author.tag,
          icon_url: message.author.displayAvatarURL()
        }
      }
    });
  }
};
ghost commented 4 years ago

Discord prevents you DM'ing everyone in a guild due to abuse and rate limiting.

TypicallyShad commented 4 years ago

Discord prevents you DM'ing everyone in a guild due to abuse and rate limiting.

This is true, @K00L1000, but he may have not wanted to DM everyone in a guild, maybe around 5 people at the same time which is fine I believe.

However, I'm sorry to say but we are no longer providing support with custom code, this place is reserved for errors & issues with setting up qbot, not your own code. We will help with any security issues such as someone inviting your bot and abusing, etc.

You can expect support on this when we open our server again, otherwise, please close this issue.