---
title: "sendMessage(withLocalizedFormatKey:arguments:data:to:badgePlayers:completionHandler:)"
framework: gamekit
role: symbol
role_heading: Instance Method
path: "gamekit/gkgamesession/sendmessage(withlocalizedformatkey:arguments:data:to:badgeplayers:completionhandler:)"
---

# sendMessage(withLocalizedFormatKey:arguments:data:to:badgePlayers:completionHandler:)

Sends a message to players in a game session.

## Declaration

```swift
func sendMessage(withLocalizedFormatKey key: String, arguments: [String], data: Data?, to players: [GKCloudPlayer], badgePlayers: Bool, completionHandler: @escaping @Sendable ((any Error)?) -> Void)
```

```swift
func sendMessage(withLocalizedFormatKey key: String, arguments: [String], data: Data?, to players: [GKCloudPlayer], badgePlayers: Bool) async throws
```

## Parameters

- `key`: A localized string with format tokens.
- `arguments`: An array containing entries for the format tokens contained by the key parameter.
- `data`: A Data object containing a limited amount of developer determined game information.
- `players`: A GKCloudPlayer array containing the players to be messaged.
- `badgePlayers`: A Boolean indicating whether players are badged when the message is sent.
- `completionHandler`: A block that is called after the message has been sent.

## See Also

### Communicating Between Players

- [badgedPlayers](gamekit/gkgamesession/badgedplayers.md)
- [clearBadge(for:completionHandler:)](gamekit/gkgamesession/clearbadge(for:completionhandler:).md)
