Add support for custom shard ID and count
This commit is contained in:
@@ -89,6 +89,7 @@ where
|
||||
}
|
||||
|
||||
pub struct Bot<T: Send + Sync = ()> {
|
||||
shard: ShardId,
|
||||
state: Arc<T>,
|
||||
prefixes: Arc<dyn PrefixGetter<T> + Send + Sync>,
|
||||
intents: Intents,
|
||||
@@ -108,6 +109,7 @@ pub struct Bot<T: Send + Sync = ()> {
|
||||
impl<T: 'static + Send + Sync> Bot<T> {
|
||||
pub fn new(state: T, prefixes: impl PrefixGetter<T> + Send + Sync + 'static) -> Self {
|
||||
Self {
|
||||
shard: ShardId::new(0, 1),
|
||||
state: Arc::new(state),
|
||||
prefixes: Arc::new(prefixes),
|
||||
intents: Intents::empty(),
|
||||
@@ -125,6 +127,11 @@ impl<T: 'static + Send + Sync> Bot<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn shard(mut self, shard: ShardId) -> Self {
|
||||
self.shard = shard;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn intent(mut self, intent: Intents) -> Self {
|
||||
self.intents.insert(intent);
|
||||
self
|
||||
@@ -221,7 +228,7 @@ impl<T: 'static + Send + Sync> Bot<T> {
|
||||
commands: bot.commands.clone(),
|
||||
});
|
||||
|
||||
let mut gateway = Shard::new(ShardId::new(0, 1), token.to_string(), bot.intents);
|
||||
let mut gateway = Shard::new(bot.shard, token.to_string(), bot.intents);
|
||||
|
||||
loop {
|
||||
if let Some(Ok(event)) = gateway.next_event(EventTypeFlags::all()).await {
|
||||
|
||||
Reference in New Issue
Block a user