-
Notifications
You must be signed in to change notification settings - Fork 18
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
请问如何新建或者获取一个bot对象 #4
Comments
启动类添加 @EnableScheduling 注解 @Resource
private BotContainer botContainer;
@Scheduled(cron = "0 0 00 * * ?", zone = "Asia/Shanghai")
private void sendMsg() {
val bot = botContainer.getBots().get(botId);
if (bot != null) {
bot.sendGroupMsg(groupId, "hi", false);
}
} |
非常非常感谢 定时发送已经明白了 !! 后续功能的实装请允许我参考https://github.com/MisakaTAT/YuriBot 谢谢! |
不好意思,还需要再问一下..... |
Global.bot_selfId请替换为你自己机器人的QQ号, long类型 |
这里换成机器人的QQ号就好了 谢谢 |
新建机器人在 Go-Mirai-Client 创建一个新的账号,支持多账号登录。 获取已有的机器人@Component
public class A {
@Autowired
BotContainer botContainer;
@Scheduled(fixedRate = 3000)
public void test() {
long botId = 123L;
Map<Long, Bot> allBots = botContainer.getBots();
Bot bot = allBots.get(botId);
if (bot != null) {
bot.sendPrivateMsg();
}
}
} 定时任务首先,在项目启动类上添加 @EnableScheduling 注解,开启对定时任务的支持 @SpringBootApplication
@EnableScheduling
public class ScheduledApplication {
public static void main(String[] args) {
SpringApplication.run(ScheduledApplication.class, args);
}
} 其次,编写定时任务类和方法,定时任务类通过 Spring IOC 加载,使用 @component 注解,定时方法使用 @scheduled 注解。 @Component
public class ScheduledTask {
@Scheduled(fixedRate = 3000)
public void scheduledTask() {
System.out.println("任务执行时间:" + LocalDateTime.now());
}
} |
感谢你详细的回答,现在定时任务已经成功跑起来了,谢谢。 |
如题,现在正在尝试做一个定时发送群消息到指定群的功能,不知道如何实现。
The text was updated successfully, but these errors were encountered: