admin管理员组文章数量:1323524
So, I want to wait for a message from user used specific mand. I know that the filter is probably wrong, but I have no idea now how can I approach this.
I tried something like this:
const msg_filter = m => m.author.id === message.author.id;
message.channel.awaitMessages(msg_filter, {
max: 1
});
But now, how can I get this working? Because I googled for several hours and couldn't find a way to solve this issue. I just want to fetch a message from same user as used the mand (And I was only able to fetch message from bot, nothing more).
So, I want to wait for a message from user used specific mand. I know that the filter is probably wrong, but I have no idea now how can I approach this.
I tried something like this:
const msg_filter = m => m.author.id === message.author.id;
message.channel.awaitMessages(msg_filter, {
max: 1
});
But now, how can I get this working? Because I googled for several hours and couldn't find a way to solve this issue. I just want to fetch a message from same user as used the mand (And I was only able to fetch message from bot, nothing more).
Share Improve this question asked Aug 30, 2021 at 8:33 Izzy MailmareIzzy Mailmare 251 gold badge1 silver badge4 bronze badges3 Answers
Reset to default 4Here's a link to the documentation on TextChannel#awaitMessages
But in a nutshell, awaitMessages
returns a promise that you have to resolve, like this:
const msg_filter = (m) => m.author.id === message.author.id;
const collected = await message.channel.awaitMessages({ filter: msg_filter, max: 1 });
// Or without async/await
const msg_filter = (m) => m.author.id === message.author.id;
message.channel.awaitMessages({ filter: msg_filter, max: 1 })
.then((collected) => {
// ...
});
and collected
will be a Collection
of messages. Since you're only collecting 1 message, you can use collected.first()
to get the first (and only) message in the collection, and then from there you can get it's .content
, or .reply()
to it, or do whatever else you want to do with the message.
Your format isn't wrong you just need to change the position of filter!
const msg_filter = m => m.author.id === message.author.id;
message.channel.awaitMessages({
filter: msg_filter,
max: 1
});
and make sure you put
'DIRECT_MESSAGES'
on intents function
Take a look at the official discordjs guide for this.
Example:
// `m` is a message object that will be passed through the filter function
const filter = m => m.content.includes('discord');
const collector = interaction.channel.createMessageCollector({ filter, time: 15000 });
collector.on('collect', m => {
console.log(`Collected ${m.content}`);
});
collector.on('end', collected => {
console.log(`Collected ${collected.size} items`);
});
本文标签: javascriptHow to use awaitMessages in DiscordJS v13Stack Overflow
版权声明:本文标题:javascript - How to use awaitMessages in Discord.JS v13 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742132067a2422206.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论