Nuggies-bot / dropdown-roles-example

Apache License 2.0
22 stars 11 forks source link

Getting error on last discordjs. Unhandled Rejection at: Promise Promise #2

Closed malosaa closed 2 years ago

malosaa commented 2 years ago

I did change it this one : Nuggies.dropdownroles.create(client, { content: embed, role: dpmanager, channelID: interaction.channel.id, type: 'single' })

Getting this error as soon as i type DONE

here the error:

[FATAL] Possibly Unhandled Rejection at: Promise  Promise {
  <rejected> TypeError: Cannot destructure property 'content' of 'undefined' as it is undefined.
      at Function.create (C:\Users\HOMESECURITY-SYSTEM\Desktop\bot13\node_modules\nuggies\src\classes\v13\dropdownroles.js:40:32)
      at MessageCollector.<anonymous> (C:\Users\HOMESECURITY-SYSTEM\Desktop\bot13\Commands\Utility\create-br.js:49:26)
      at MessageCollector.emit (node:events:402:35)
      at MessageCollector.stop (C:\Users\HOMESECURITY-SYSTEM\Desktop\bot13\node_modules\discord.js\src\structures\interfaces\Collector.js:197:10)
      at MessageCollector.<anonymous> (C:\Users\HOMESECURITY-SYSTEM\Desktop\bot13\Commands\Utility\create-br.js:25:61)
      at MessageCollector.emit (node:events:390:28)
      at MessageCollector.handleCollect (C:\Users\HOMESECURITY-SYSTEM\Desktop\bot13\node_modules\discord.js\src\structures\interfaces\Collector.js:108:12)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
}  reason:  Cannot destructure property 'content' of 'undefined' as it is undefined.
Assassin-1234 commented 2 years ago

may I ask what Nuggies version you're using?

Assassin-1234 commented 2 years ago

and your discord.js version

malosaa commented 2 years ago

i did post the wrong error my bad

here is the error im getting

[FATAL] Possibly Unhandled Rejection at: Promise  Promise {
  <rejected> TypeError: Cannot read properties of undefined (reading 'id')
      at MessageCollector.filter (C:\Users\HOMESECURITY-SYSTEM\Desktop\bot13\Commands\Utility\create-dp.js:18:55)
      at MessageCollector.handleCollect (C:\Users\HOMESECURITY-SYSTEM\Desktop\bot13\node_modules\discord.js\src\structures\interfaces\Collector.js:100:32)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
}  reason:  Cannot read properties of undefined (reading 'id')

if i look at row 18 of create-dp.js its this const filter = m => m.author.id === interaction.user.id;

and 55 is USER

nuggies version "3.1.3", and discord 13.1.0

It sends this message on discord, but after i reply i get an error Send messages in roleID label emoji syntax! Once finished say done.

@Assassin-1234

malosaa commented 2 years ago

are you using the slash commands branch? if so, with what discord.js version?

i updated the above message. Nuggies 3.1.3 Discord 13.1.0

Assassin-1234 commented 2 years ago

can I see the part where you're using .create function

malosaa commented 2 years ago

can I see the part where you're using .create function

this is the full js im using.

// require Nuggies
const Nuggies = require('nuggies');
const Discord = require('discord.js');

module.exports = {
  name: "create-dp",
  description: "Creates dropdown role!",
  userPerms: ["MANAGE_GUILD"],
  botPerms: [],
  run: async (client, interaction, args) => {
    if(!interaction.member.permissions.has('MANAGE_SERVER')) return interaction.reply('You do not have the permission \`MANAGE_SERVER\`');
    const dpmanager = new Nuggies.dropdownroles();
    interaction.reply('Send messages in `roleID label emoji` syntax! Once finished say `done`.');

    /**
     * @param {Discord.Message} m
     */
    const filter = m => m.author.id === interaction.user.id;
    const collector = interaction.channel.createMessageCollector({ filter, max: 10000 });

    collector.on('collect', async (msg) => {
        if (!msg.content) return interaction.channel.send('Invalid syntax');
        if (msg.content.toLowerCase() == 'done') return collector.stop('DONE');
        if (!msg.content.split(' ')[0].match(/[0-9]{18}/g)) return interaction.channel.send('Invalid syntax');

        const roleid = msg.content.split(' ')[0];
        const role = interaction.guild.roles.cache.get(roleid);
        if (!role) return interaction.channel.send('Invalid role');

        const label = msg.content.split(' ').slice(1, msg.content.split(' ').length - 1).join(' ');

        const reaction = (await msg.react(msg.content.split(' ').slice(msg.content.split(' ').length - 1).join(' ')).catch(/*() => null*/console.log));

        const final = {
            role: roleid, label: label, emoji: reaction ? reaction.emoji.id || reaction.emoji.name : null,
        };
        dpmanager.addrole(final);
    })

    collector.on('end', async (msgs, reason) => {
        if (reason == 'DONE') {
            const embed = new Discord.MessageEmbed()
                .setTitle('Dropdown roles!')
                .setDescription('Click on the buttons to get the specific role or vice-versa')
                .setColor('RANDOM')
                .setTimestamp();
            Nuggies.dropdownroles.create(client, { content: embed, role: dpmanager, channelID: interaction.channel.id, type: 'single' })
        }
    });
  },
};
LegItMate commented 2 years ago

Is the command handling same as the one in v13 branch or have you used a custom one?

malosaa commented 2 years ago

Is the command handling same as the one in v13 branch or have you used a custom one?

i did not see the v13 branch, i just tested it and it throws an error as soon as i type the word done.

Yes its a bit different,

You use this: module.exports.run = async (client, message, args) => {

Mine handler starts like this:

module.exports = {
  name: "create-dp",
  description: "Creates dropdown role!",
  userPerms: ["MANAGE_GUILD"],
  botPerms: [],

  run:  async (client, message, args) => {

the error now, when i type the word done:

[FATAL] Possibly Unhandled Rejection at: Promise  Promise {
  <rejected> TypeError: Cannot destructure property 'content' of 'undefined' as it is undefined.
      at Function.create (C:\Users\HOMESECURITY-SYSTEM\Desktop\bot13\node_modules\nuggies\src\classes\v13\dropdownroles.js:40:32)
      at MessageCollector.<anonymous> (C:\Users\HOMESECURITY-SYSTEM\Desktop\bot13\Commands\Utility\create-dp.js:46:26)
      at MessageCollector.emit (node:events:402:35)
      at MessageCollector.stop (C:\Users\HOMESECURITY-SYSTEM\Desktop\bot13\node_modules\discord.js\src\structures\interfaces\Collector.js:197:10)
      at MessageCollector.<anonymous> (C:\Users\HOMESECURITY-SYSTEM\Desktop\bot13\Commands\Utility\create-dp.js:23:61)
      at MessageCollector.emit (node:events:390:28)
      at MessageCollector.handleCollect (C:\Users\HOMESECURITY-SYSTEM\Desktop\bot13\node_modules\discord.js\src\structures\interfaces\Collector.js:108:12)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
}  reason:  Cannot destructure property 'content' of 'undefined' as it is undefined.
Assassin-1234 commented 2 years ago

that's the problem, your handler is only for normal commands and not slash while ours handles interaction. Use this for normal message commands.

malosaa commented 2 years ago

that's the problem, your handler is only for normal commands and not slash while ours handles interaction. Use this for normal message commands.

So this one is for slash commands ? i did try the one u said and its not working , that version is for v12 and not 13. When i change the permission to permission.has it starts but after done i get this error

[FATAL] Possibly Unhandled Rejection at: Promise  Promise {
  <rejected> TypeError: Cannot destructure property 'content' of 'undefined' as it is undefined.
      at Function.create (C:\Users\HOMESECURITY-SYSTEM\Desktop\bot13\node_modules\nuggies\src\classes\v13\dropdownroles.js:40:32)
      at MessageCollector.<anonymous> (C:\Users\HOMESECURITY-SYSTEM\Desktop\bot13\Commands\Utility\create-dp.js:47:26)
      at MessageCollector.emit (node:events:402:35)
      at MessageCollector.stop (C:\Users\HOMESECURITY-SYSTEM\Desktop\bot13\node_modules\discord.js\src\structures\interfaces\Collector.js:197:10)
      at MessageCollector.<anonymous> (C:\Users\HOMESECURITY-SYSTEM\Desktop\bot13\Commands\Utility\create-dp.js:23:61)
      at MessageCollector.emit (node:events:390:28)
      at MessageCollector.handleCollect (C:\Users\HOMESECURITY-SYSTEM\Desktop\bot13\node_modules\discord.js\src\structures\interfaces\Collector.js:108:12)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
}  reason:  Cannot destructure property 'content' of 'undefined' as it is undefined.
Assassin-1234 commented 2 years ago

change the create line to

Nuggies.dropdownroles.create(client, { content: embed, role: dpmanager, channelID: message.channel.id, type: 'single' })
malosaa commented 2 years ago

many thanks, the slash command works now ! thanks for the help.