ExamplesΒΆ
This is an example of using the discord links extension.
1import asyncio
2import os
3
4from coc.ext import discordlinks
5
6client = discordlinks.login(os.environ["LINKS_API_USERNAME"], os.environ["LINKS_API_PASSWORD"])
7
8
9async def main():
10 player_tag = "#JY9J2Y99"
11 discord_id = 230214242618441728
12
13 # add a link
14 await client.add_link(player_tag, discord_id)
15 print("Player Tag {} is now linked to discord id {}".format(player_tag, discord_id))
16
17 # get a link by tag
18 discord_id = await client.get_link(player_tag)
19 print("Player Tag {} is linked to discord id {}".format(player_tag, discord_id))
20
21 # update a link
22 new_discord_id = 230214242618441728
23 await client.delete_link(player_tag)
24 await client.add_link(player_tag, new_discord_id)
25 print("Link for player tag {} has been updated to have discord id {}".format(player_tag, new_discord_id))
26
27 # delete a link
28 await client.delete_link(player_tag)
29 print("Link for player tag {} has been removed from the database.".format(player_tag))
30
31 # batch get links by tag
32 player_tags = ["#JY9J2Y99", "#2GV0QY8G8", "#PP9L22C8", "#2LPC9J8L"]
33 links = await client.get_links(*player_tags)
34 for tag, discord_id in links:
35 if discord_id is None:
36 print("Player tag {} doesn't have any links.".format(tag))
37 else:
38 print("Player tag {} is linked to discord id {}".format(tag, discord_id))
39
40 # batch get links by id
41 discord_ids = [246286410946969610, 230214242618441728, 267057699856842753]
42 links = await client.get_many_linked_players(*discord_ids)
43 for tag, discord_id in links:
44 print("Discord ID {} is linked to {}".format(tag, discord_id))
45
46
47loop = asyncio.get_event_loop()
48loop.run_until_complete(main())