Closed TrueMB closed 2 years ago
Hi! I didn't knew that this plugin existed, if you want I can add it to the list of addons on the spigotmc page ^^
Is it possible to wait for the Spicord Bot and not with a timer?
Yes, I have some code tips for you. This snippet is for getting the Spicord instance without running Spicord.getInstance() as is not safe because it can return null if Spicord has not loaded when the method is executed.
import org.spicord.SpicordLoader;
public void onEnable() {
// This is an async callback, your code will not stop waiting, it will only be executed once Spicord loads.
SpicordLoader.addStartupListener(spicord -> {
// Spicord has loaded, and you can now use the valid instance from the "spicord" parameter.
// As running Spicord.getInstance() is not safe.
});
}
Now, to know when a bot has been loaded or when the bot is fully ready, you can implement one (or both) of these methods in your addon class (DC_PlayerInfoCommand.java / DC_VerifyCommand.java)
public class YourAddon extends SimpleAddon {
@Override
public void onLoad(DiscordBot bot) {
// A bot that is using your addon has been loaded, but it may be not ready
// and may have not been connected yet to Discord, so it is not usable.
}
@Override
public void onReady(DiscordBot bot) {
// A bot that is using your addon is now fully ready to be used.
}
}
Hope that helps, have fun coding :smile:
Hi! I didn't knew that this plugin existed, if you want I can add it to the list of addons on the spigotmc page ^^
That would be awsome! The funny thing is, I just saw your latest update, were you mentioned adding Plugins to your list. After that I went on your discord to find a chatroom for that. But I couldnt find any :'D
But how did you find the plugin? I never expected an answer of somebody else here and I am kinda suprised :D
Main Topic: Yes I know the Method and it would be one way to get it. But my plugin works so, that you can disable not needed features. So if somebody doesnt need the playerinfo and verify command, I still need to get the Bot.
That would be awsome! The funny thing is, I just saw your latest update, were you mentioned adding Plugins to your list. After that I went on your discord to find a chatroom for that. But I couldnt find any :'D
I have added it on the list ^^ you could have asked it on #general, as it is related to Spicord. In case you need help regarding the Spicord API or something related you can join the Discord server and ask, you are not bothering.
But how did you find the plugin? I never expected an answer of somebody else here and I am kinda suprised :D
Just coincidence :sweat_smile:
So if somebody doesnt need the playerinfo and verify command, I still need to get the Bot.
Oh- well, at least you can now get the Spicord instance safely :smile:
Oh- well, at least you can now get the Spicord instance safely 😄
You mean, if somebody uses the verify or Playerinfo command? Or is there another way?
It's 3am right now, so I will take a closer look tomorrow, since I finished the update of my other plugin. But I might just ask more often for the bot and not only once after server start, how it currently is.
You mean, if somebody uses the verify or Playerinfo command? Or is there another way?
Quote from the original issue:
Is it possible to wait for the Spicord Bot and not with a timer?
By using the code snippet I sent you, you won't need to use a timer anymore, and you will get the valid Spicord instance as soon as it loads, and then getting the bot instance from it.
You mean, if somebody uses the verify or Playerinfo command? Or is there another way?
Quote from the original issue:
Is it possible to wait for the Spicord Bot and not with a timer?
By using the code snippet I sent you, you won't need to use a timer anymore, and you will get the valid Spicord instance as soon as it loads, and then getting the bot instance from it.
But for that, your config needs to know the Addon, doesnt it? What I mean: If a player doesnt want to use the verify and playerinfo command, he just doesnt add the Addons in your Config. That would mean for my plugin that the Addon doesnt get loaded, only registered. But this doesnt get the correct Bot.
Even if somebody doesnt uses the Addons, I need the Bot. F.e. for messages that I send to the Discord Server.
But for that, your config needs to know the Addon, doesnt it? What I mean: If a player doesnt want to use the verify and playerinfo command, he just doesnt add the Addons in your Config. That would mean for my plugin that the Addon doesnt get loaded, only registered. But this doesnt get the correct Bot.
Even if somebody doesnt uses the Addons, I need the Bot. F.e. for messages that I send to the Discord Server.
I'm talking about the first code snippet, the one that doesn't uses any addon class, as you don't need to register any addon for using the SpicordLoader.addStartupListener method
OHH Now I get what you mean. I thought the first Code registered the Addon. Didnt read correctly. Sorry!
Should be fixed in cdad59e308db3ecd23ca67a671bf6c4ced439fd4
Describe the bug If too many plugins are installed and the Server gets started, it won't connect to the Discord Bot. https://github.com/TrueMB/DiscordNotify/blob/f28331380bd47cff597b93606bd14432b3d69aef/src/me/truemb/disnotify/spigot/main/Main.java#L139
Is it possible to wait for the Spicord Bot and not with a timer?
Server (please complete the following information):