Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

短时间内多次调用room.say(message),只发送了最后一次,怎么解决呢?message的内容是不同的。 #2673

Open
lys623 opened this issue Apr 18, 2024 · 1 comment

Comments

@lys623
Copy link

lys623 commented Apr 18, 2024

如题,有解决方案吗?

我这边会bot监听群里的信息,当匹配特殊字段信息就返回一段对于的内容。希望支持批量处理,比如批量发送多条信息到群里,bot能全返回。

Copy link

dosubot bot commented Apr 18, 2024

为了解决短时间内多次调用room.say(message)只发送最后一条消息的问题,您可以通过在每次发送消息之间引入一个延迟来实现批量发送多条不同消息。这可以通过async/await结合setTimeout来实现,以此来控制消息发送的间隔时间。

以下是一个实现示例:

async function sendMessagesSequentially(room, messages, delay) {
  for (const message of messages) {
    await room.say(message);
    await new Promise(resolve => setTimeout(resolve, delay));
  }
}

// 使用示例
const messages = ['Message 1', 'Message 2', 'Message 3']; // 要发送的消息数组
const delay = 1000; // 每条消息之间的延迟时间,单位毫秒
sendMessagesSequentially(room, messages, delay);

这段代码会按照您指定的延迟时间,逐一发送每条消息。通过这种方式,您可以有效避免因快速连续调用room.say(message)而导致的消息发送限制或合并问题。

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant