Discord Bot Java – I'm trying to have my bot send a message every so often and need help on which event listener is best suited

huangapple go评论79阅读模式
英文:

Discord Bot Java - I'm trying to have my bot send a message every so often and need help on which event listener is best suited

问题

我希望我的机器人在一天中的随机时间发送消息。
我之前使用onMessageReceived事件来实现这一点,但那取决于用户发送消息,我希望即使在一段时间内没有任何服务器活动,机器人也能随机发送消息。

基本上,我希望找到的是,在机器人在线时每隔几秒钟始终触发的事件侦听器。该事件不应取决于用户是否发送消息,或者是否有人加入语音频道等。

有人知道是否有适用于我情况的事件侦听器吗?

英文:

I want my bot to send a message randomly throughout the day.
I was using the onMessageReceived event to achieve this, but that depends on a user sending a message, and I want the bot to still send a message randomly even if there hasn't been any server activity for a while.

Basically, what I'm hoping to find is if there's an Event Listener that fires every few seconds consistently while the bot is online. The event shouldn't be dependent on if users send messages or if people join voice channels, etc.

Does anyone know of an Event Listener that could help me achieve this?

答案1

得分: 1

只需在运行命令后在您的机器人中使用定时器,您可以添加一个命令,例如!motd random 以获得随机间隔,然后如果您想在一定时间后执行它,可以使用!motd 3hours。

英文:

Just use a timer in your bot after you run a command, you could add a command like !motd random for a random interval and then if you wanted to do it after a certain period of time do !motd 3hours

huangapple
  • 本文由 发表于 2020年10月26日 09:05:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/64530357.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定