Closed kNoAPP closed 2 years ago
This however, works:
final bot = NyxxFactory.createNyxxWebsocket(
discordToken, GatewayIntents.allUnprivileged)
..registerPlugin(Logging())
..registerPlugin(CliIntegration())
..registerPlugin(IgnoreExceptions());
await bot.connect();
// Let the bot's connection warm up. This shouldn't be necessary, but it ensures
// future calls to Discord don't outright fail.
await Future.delayed(Duration(seconds: 2));
bot.setPresence(PresenceBuilder.of(
status: UserStatus.online,
activity: ActivityBuilder.game('Apex Legends'),
));
There's a race condition in the package somewhere.
There is no race condition, however it is true that the client does not wait for all shards to be connected before returning from the connect
methods.
If you want to perform operations that require the shards to be connected, act on each individual shard by listening to the client.eventsWs.onReady
event streams which fires when shard connects.
Describe the bug The call to set a Discord bot's presence does not work.
To Reproduce Steps to reproduce the behavior:
Expected behavior This code should display "Playing Apex Legends" under the bot's name.
Actual behavior No errors in console. No effect on the bot.
Desktop (please complete the following information):