49 lines
No EOL
1.6 KiB
HTML
49 lines
No EOL
1.6 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Document</title>
|
|
</head>
|
|
<body>
|
|
<button onclick="createToken('testinguser', '0', ['0']);">create token</button>
|
|
<button onclick="sendMessage('0', '0', 'hello');">send message</button>
|
|
|
|
<script>
|
|
let createdToken;
|
|
|
|
async function createToken(username, discordID, guildAccess) {
|
|
const res = await fetch("http://localhost:4050/api/v1/tokens/create", {
|
|
method: "POST",
|
|
body: JSON.stringify({
|
|
username,
|
|
discordID,
|
|
guildAccess
|
|
}),
|
|
headers: {
|
|
"content-type": "application/json"
|
|
}
|
|
});
|
|
const json = await res.json();
|
|
console.log("createToken()", json);
|
|
createdToken = json.token;
|
|
}
|
|
|
|
async function sendMessage(guildId, channelId, content) {
|
|
const res = await fetch(`http://localhost:4050/api/v1/guilds/${guildId}/channels/${channelId}/messages/create`, {
|
|
method: "POST",
|
|
body: JSON.stringify({
|
|
content
|
|
}),
|
|
headers: {
|
|
"content-type": "application/json",
|
|
"authorization": createdToken
|
|
}
|
|
});
|
|
const json = await res.json();
|
|
console.log("sendMessage()", json);
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |