🍎Step by Step: Discord with V1 API
Based on our Discord game, here is a basic practice to demonstrate how to create a simple detective game using our API.
Last updated
Based on our Discord game, here is a basic practice to demonstrate how to create a simple detective game using our API.
Last updated
Before diving into this document, it is strongly recommended to read here to understand the relationships between games, scenes, goals, DMs, and NPCs.
All interfaces require the application of an app ID and authentication. The specific process can be found here
You need to call the gamelist interface to retrieve all playable games. This API will return basic game information, which you can display as needed. In our Discord game, we display the game name and a brief description to help players choose.
Additionally, you need to remember the game ID and scene ID. When starting the game in the next step, the API will require these to specify the game. The relationship between games and scenes can be referenced here.
After players choose a game, you need to call the startgame interface, passing in the game and scene IDs to start the game. In our Discord game, clicking the game button will fetch the game based on these IDs. In this interface, the API will return basic information about the game scene, background, NPC list, and initial dialogue.
In our Discord game, background information is displayed to help players understand the game. Relevant NPCs are loaded based on the NPC list for future conversations, and the initial dialogue between NPCs is automatically displayed.
Through the initial dialogue, players can naturally learn about the NPC's character, style, and plot. The DM will also explain the current game goal.
Once the game begins, you can use the chat interface at any time to engage in chat with the NPCs.
To enhance the game's playability, each game round limits the number of conversations with NPCs. So, in the API's response, pay attention to the "epoch"
field, as NPCs will stop responding after reaching the conversation limit.
The DM, as a special NPC, not only engages in regular chat but also controls the game's goals and game progression. The specific relationships between scenes, objectives, and NPCs can be found here.
The game's progress status is indicated in the "game status"
field of the API interface. You can start a new game or end the game based on this field.
In our Discord game, when "action=3"
(indicating the end of the game), a button to start a new game is automatically displayed, and relevant NPCs are removed. Of course, you can also implement a more interactive UI and save user game data to your server.