#Collector

1 messages · Page 1 of 1 (latest)

placid magnet
#

@noble yarrow can you see when you are available

noble yarrow
#

did you do a console log inside the collection.on function? and did that trigger when you tried clicking a button?

placid magnet
#

not triggered

#

I think it's based on the person who wrote the command

#

it will be like this

#

./dm @noble yarrow

noble yarrow
#

ok, can you re-paste the code here for the collection file real quick? just to save me having to find it in all the other code snippets xD

placid magnet
#
const Discord = require('discord.js');
const db = require("quick.db");
const config = require("../../../config.json")
const { MessageEmbed, MessageButton, MessageActionRow } = require("discord.js");

let kabulet1 = new MessageButton()
.setStyle("SUCCESS")
.setLabel("Kabul Et ")
.setEmoji("✔️")
.setCustomId("kabulet1")
let reddet2 = new MessageButton()
.setStyle("DANGER")
.setLabel("Reddet ")
.setEmoji("✖️")
.setCustomId("reddet2")

module.exports = {
    name: "teklifet",
    aliases: ["çık", "çıkmateklifi"],

    execute: async (client, message, args) =>{
    let teamtr = message.mentions.users.first() || message.guild.members.cache.get(args[0]);
    const cccccckkkklt = new Discord.MessageEmbed()
    .setColor('#bf2307')
    .setDescription(`❤️ Çıkma teklifi etmek istediğin kişiyi etiketle veya idsini yaz.`);
    if (!teamtr) return message.reply({embeds: [cccccckkkklt]}).catch((err) => console.log(err), client.tick(message)).then((e) => setTimeout(() => { e.delete(); }, 10000));
    const dmtamam = new Discord.MessageEmbed()
    .setColor('#bf2307')
    .setTimestamp()
    .addField('❤️ Başarıyla çıkma teklifi ettin. Sabırla bekle!', `Onunda sana gönlü var bence 😉`)
    .setFooter('Çıkma teklifi ettin!')
    message.channel.send({embeds: [dmtamam]});
    const dmat = new Discord.MessageEmbed()
    .setColor('#c107bb')
    .setTimestamp()
    .setTitle('Birinden çıkma teklifi geldi! ❤️')
    .addField('Vericeğin cevabı merak ettim doğrusu 😆', `İyi birine benziyor ne dersin ? 😉`)
    .addField('Teklif eden kişi:', `➽ ${message.author}`)
    .setFooter('Çıkma teklifi!')
    teamtr.send({embeds: [dmat], components: [new MessageActionRow({ components: [kabulet1, reddet2]})]})
    const filter = x => x.user.id = teamtr.id
    let collector = message.createMessageComponentCollector({ filter, time: 300000 })
        
    collector.on("collect", async button => {
    console.log(member);
    if(button.customId === "kabulet1") {
    let kabulet = new MessageEmbed()
    .setAuthor(`${client.user.username} Çıkma Teklifi Menü`, client.user.avatarURL())
    .setDescription(`> Çıkma Teklifi:`)
    .addField("✅ Başarıyla Kabul Edildi!")
    .setFooter(`${message.author.username} tarafından kullanıldı.`, message.author.displayAvatarURL({dynamic:true}))
    .setColor("RANDOM")
    message.edit({content: "✅ Kabulet", embeds: [kabulet] })}
    
    if(button.customId === "reddet2") {
    let reddet = new MessageEmbed()
    .setAuthor(`${client.user.username} Çıkma Teklifi Menü`, client.user.avatarURL())
    .setDescription(`> Çıkma Teklifi:`)
    .addField("❌ Başarıyla Reddedildi!")
    .setFooter(`${message.author.username} tarafından kullanıldı.`, message.author.displayAvatarURL({dynamic:true}))
    .setColor("RANDOM")
    message.edit({content: "❌ Reddet", embeds: [reddet] })}
})
}}```
#

message.createMessageComponentCollector
member.createMessageComponentCollector
I changed it to but it didn't work

#

I arranged

noble yarrow
#

ahh ok I... ??think?? i might know the fix...
lemme just work my way through your.. interesting 😛 variable names...

#

so you're assigning the collector to the message that the bot receives...
where I'm pretty sure you need to assign the collector to the message that you send that contains the components...

so on this line:
teamtr.send({embeds: [dmat], components: [new MessageActionRow({ components: [kabulet1, reddet2]})]})
try something like this:
const buttonMessage = await teamtr.send({embeds: [dmat], components: [new MessageActionRow({ components: [kabulet1, reddet2]})]})
(don't forget that .sends are async functions and return promises, so you should probably await them unless you don't care when they finish executing and don't need them to be in order)

and then with this line:
let collector = message.createMessageComponentCollector({ filter, time: 300000 })
make it:
let collector = buttonMessage.createMessageComponentCollector({ filter, time: 300000 })

placid magnet
#

I am trying

#

same

#

ımm

noble yarrow
placid magnet
#
    if (typeof data !== 'string') throw new error(errorMessage);
                                        ^

RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings.```
#

error

placid magnet
noble yarrow
#

is that an error its throwing?

#

whats the error?

placid magnet
#

It gives an error when pressing the button.

noble yarrow
#

whats the error?

placid magnet
#
C:\Users\batub\Desktop\DARK CITY BOT'S\Genel\node_modules\discord.js\src\util\Util.js:416
    if (typeof data !== 'string') throw new error(errorMessage);
                                        ^

RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings.
    at Function.verifyString (C:\Users\batub\Desktop\DARK CITY BOT'S\Genel\node_modules\discord.js\src\util\Util.js:416:41)
    at Function.normalizeField (C:\Users\batub\Desktop\DARK CITY BOT'S\Genel\node_modules\discord.js\src\structures\MessageEmbed.js:544:19)
    at C:\Users\batub\Desktop\DARK CITY BOT'S\Genel\node_modules\discord.js\src\structures\MessageEmbed.js:565:14
    at Array.map (<anonymous>)
    at Function.normalizeFields (C:\Users\batub\Desktop\DARK CITY BOT'S\Genel\node_modules\discord.js\src\structures\MessageEmbed.js:564:8)
    at MessageEmbed.addFields (C:\Users\batub\Desktop\DARK CITY BOT'S\Genel\node_modules\discord.js\src\structures\MessageEmbed.js:328:42)
    at MessageEmbed.addField (C:\Users\batub\Desktop\DARK CITY BOT'S\Genel\node_modules\discord.js\src\structures\MessageEmbed.js:319:17)
    at InteractionCollector.<anonymous> (C:\Users\batub\Desktop\DARK CITY BOT'S\Genel\src\commands\Genel\deneme.js:48:3)
    at InteractionCollector.emit (node:events:532:35)
    at InteractionCollector.handleCollect (C:\Users\batub\Desktop\DARK CITY BOT'S\Genel\node_modules\discord.js\src\structures\interfaces\Collector.js:109:12) {
  [Symbol(code)]: 'EMBED_FIELD_VALUE'
}```
noble yarrow
#

temporarily change your collector function to this:

collector.on("collect", async button => {
  console.log("Hit!", button);
});
#

and see if you get a console output

#

cause from a rough glance, one of your messageEmbeds inside the collector is erroring

placid magnet
#
Hit! ButtonInteraction {
  type: 'MESSAGE_COMPONENT',
  id: '960082206678716416',
  applicationId: '949959308852990002',
  channelId: '956599666919739402',
  guildId: null,
  user: User {
    id: '552850125626540052',
    bot: false,
    system: false,
    flags: UserFlags { bitfield: 256 },
    username: 'Baturex',
    discriminator: '0001',
    avatar: 'a_e3ad00bb2771143c8399e0787d7f5e34',
    banner: undefined,
    accentColor: undefined
  },
  member: null,
  version: 1,
  memberPermissions: null,
  locale: 'tr',
  guildLocale: null,
  message: <ref *1> Message {
    channelId: '956599666919739402',
    guildId: null,
    id: '960082197447073802',
    createdTimestamp: 1648971833336,
    type: 'DEFAULT',
    system: false,
    content: '',
    author: ClientUser {
      id: '949959308852990002',
      bot: true,
      system: false,
      flags: [UserFlags],
      username: '✧OPİNİONBOT✧',
      discriminator: '8882',
      avatar: '8eae7ff7e48bee7773c53cf0177be37f',
      banner: undefined,
      accentColor: undefined,
      verified: true,
      mfaEnabled: true
    },
    pinned: false,
    tts: false,
    nonce: null,
    embeds: [ [MessageEmbed] ],
    components: [ [MessageActionRow] ],
    attachments: Collection(0) [Map] {},
    stickers: Collection(0) [Map] {},
    editedTimestamp: null,
    reactions: ReactionManager { message: [Circular *1] },
    mentions: MessageMentions {
      everyone: false,
      users: Collection(0) [Map] {},
      roles: Collection(0) [Map] {},
      _members: null,
      _channels: null,
      crosspostedChannels: Collection(0) [Map] {},
      repliedUser: null
    },
    webhookId: null,
    groupActivityApplication: null,
    applicationId: null,
    activity: null,
    flags: MessageFlags { bitfield: 0 },
    reference: null,
    interaction: null
  },
  customId: 'kabulet1',
  componentType: 'BUTTON',
  deferred: false,
  ephemeral: null,
  replied: false,
  webhook: InteractionWebhook { id: '949959308852990002' }
}```
noble yarrow
#

ahh, pretty sure it's this one:
.addField(":x: Başarıyla Reddedildi!") right at the bottom

the addField function needs to be addField(name, value) or addField(name, value, inlineBoolean)

hence its error of MessageEmbed field values must be non-empty strings.

noble yarrow
placid magnet
noble yarrow
#

so if you fix up that function call, that ?should? get it all working for you

placid magnet
#

erorr: Cannot edit a message authored by another user

#

😄

noble yarrow
#

whats the exact error output?

placid magnet
#
      throw new DiscordAPIError(data, res.status, request);
            ^

DiscordAPIError: Cannot edit a message authored by another user
    at RequestHandler.execute (C:\Users\batub\Desktop\DARK CITY BOT'S\Genel\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (C:\Users\batub\Desktop\DARK CITY BOT'S\Genel\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
    at async MessageManager.edit (C:\Users\batub\Desktop\DARK CITY BOT'S\Genel\node_modules\discord.js\src\managers\MessageManager.js:132:15) {
  method: 'patch',
  path: '/channels/952091049231253555/messages/960084062112981052',
  code: 50005,
  httpStatus: 403,
  requestData: {
    json: {
      content: 'Reddet',
      tts: false,
      nonce: undefined,
      embeds: [
        {
          title: null,
          type: 'rich',
          description: '> Çıkma Teklifi:',
          url: null,
          timestamp: 0,
          color: 12650427,
          fields: [ [Object] ],
          thumbnail: null,
          image: null,
          author: {
            name: 'OPİNİONBOT✧ Çıkma Teklifi Menü',
            url: undefined,
            icon_url: 'https://cdn.discordapp.com/avatars/949959308852990002/8eae7ff7e48bee7773c53cf0177be37f.webp'
          },
          footer: {
            text: 'Baturex tarafından kullanıldı.',
            icon_url: 'https://cdn.discordapp.com/avatars/552850125626540052/a_e3ad00bb2771143c8399e0787d7f5e34.gif'
          }
        }
      ],
      components: undefined,
      username: undefined,
      avatar_url: undefined,
      allowed_mentions: undefined,
      flags: 0,
      message_reference: undefined,
      attachments: undefined,
      sticker_ids: undefined
    },
    files: []
  }
}
noble yarrow
#

ah, similar issue to your collector definition initially

#

message.edit({content: ":white_check_mark: Kabulet", embeds: [kabulet] })}
your trying to edit the message the other user sent

placid magnet
#

I am very clever

#

:d

noble yarrow
placid magnet
#

worked great, but interaction failed wrote

#

a wait Is it solved with ?

noble yarrow
#

hold on, which part failed?

placid magnet
#

everything works, buttons are not deleted

noble yarrow
#

cause you don't clear them

placid magnet
#

components: clear ?

noble yarrow
#

in your edits message.edit({content: ":x: Reddet", embeds: [reddet] })}
you're editing the content and the embeds, but not the components

#

so you need to set them to an empty array

placid magnet
#

hım

noble yarrow
#

message.edit({content: ":x: Reddet", embeds: [reddet], components: [] })}

placid magnet
#

Thank you very much, can I ask you one last thing?

noble yarrow
#

sure

placid magnet
#

To use the command I want it to wait for a certain time

how can i do it in the simplest way

#
let talkedRecently = new Set();
    if (talkedRecently.has(message.author.id)) {
    message.channel.send("20 sn sonra tekrar kullanınız!");
    message.delete();
    return;
  }

  talkedRecently.add(message.author.id);
  setTimeout(() => {
    talkedRecently.delete(message.author.id);
  }, 20000);```
#

?

#

Is there anything simpler ?

noble yarrow
#

as in you want it to only trigger when they send a message and only if they've sent another message in the last x time?

placid magnet
#

I want it to be able to use it every 30 minutes

noble yarrow
#

what is the criteria for it?

it should only send that message and delete the original if they've said something already within that timeframe?

placid magnet
#

yes it should be warned

#

You can use it every 30 minutes!

#

sample:

noble yarrow
#

ok, well, I dunno what way would be the most 'efficient'... but a couple of different ways that come to mind are:

  1. The way you are doing, list of whos spoken recently and a loop to remove

  2. A list of anyone whos spoken in the channel and the timestamp of when they spoke, then you just compare the timestamp to now

#

probably other ways too, dunno

placid magnet
#

({ filter, time: 300000 }) how many minutes is this

#

1 second 1000 ?

noble yarrow
#

1 second is 1000ms

#

so that would be 300 seconds

placid magnet
#

thank you so much

#

now i did something like

#
collector.on("end", async button => {

let geckaldinn = new MessageEmbed()
.setTitle(`Çıkma Teklifi ❤️`, client.user.avatarURL())
.addField('⏰ Çıkma teklifini yanıtlamak için çok geç kaldın!', 'Sakın canını sıkma sende ona teklif gönderebilirsin. 🥰')
.setFooter(`Teklif eden: ${message.author.tag}`, message.author.displayAvatarURL({dynamic:true}))
.setColor('#c107bb')
let geckaldin = new MessageButton()
.setStyle("DANGER")
.setLabel(`Teklif etmek için !teklifet ${message.author.tag}`)
.setDisabled(true)
.setCustomId("timeout")

buttonMessage.edit({content: "⏰...", embeds: [geckaldinn], components: [new MessageActionRow({ components: [geckaldin]})]})})

}}```
#

but even if i press the button it prints this

#

I know I ask a lot of questions

#

🙏

#

i need to reset this collectrou

#

collector.stop() ?