Difference between revisions of "Bot Playground/Commands/acceptFriendshipOffer"
From SmartBots Developers Docs
(6 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:{{SUBPAGENAME}}}} | {{DISPLAYTITLE:{{SUBPAGENAME}}}} | ||
− | <onlyinclude>Accept (or reject) | + | <onlyinclude>Accept (or reject) a friendship offer sent by other avatar.</onlyinclude> |
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
Bot.on("friendship_offer", (event) => { | Bot.on("friendship_offer", (event) => { | ||
− | Bot. | + | Bot.acceptFriendshipOffer(event.avatar_uuid, event.session_id, true); |
}); | }); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | See [[ | + | See [[Bot_Playground/Events/friendship_offer| friendship_offer]] event for details. |
{{API Command Table}} | {{API Command Table}} | ||
− | {{API Required Vars| | + | {{API Required Vars|{{SUBPAGENAME}}}} |
{{API Variable Group|Input}} | {{API Variable Group|Input}} | ||
{{API Variable| avatar_uuid |yes}} sender avatar UUID | {{API Variable| avatar_uuid |yes}} sender avatar UUID | ||
{{API Variable| session_id |yes}} session UUID from the event | {{API Variable| session_id |yes}} session UUID from the event | ||
− | {{API Variable|accept|yes}} true to accept | + | {{API Variable|accept|yes}} true to accept an offer, false to reject. |
{{API Variable Group|Output}} | {{API Variable Group|Output}} | ||
Line 23: | Line 23: | ||
{{API Variables Table End}} | {{API Variables Table End}} | ||
+ | |||
+ | == Example == | ||
+ | |||
+ | <syntaxhighlight lang="javascript"> | ||
+ | Bot.on("friendship_offer", async function(event) { | ||
+ | console.log("Got friendship offer from: " + event.avatar_name + "\n\nAccepting now."); | ||
+ | let response = await Bot.acceptFriendshipOffer(event.avatar_uuid, event.session_id, true); | ||
+ | if(response.success) | ||
+ | { | ||
+ | console.log("Accepted the friendship Offer"); | ||
+ | } else { | ||
+ | console.log("Rejected the friendship Offer"); | ||
+ | console.error("Error: " + response.error) | ||
+ | } | ||
+ | }); | ||
+ | |||
+ | console.log("Bot is listening, friendship offers"); | ||
+ | </syntaxhighlight> | ||
{{NavMenu}} | {{NavMenu}} | ||
__NOTOC__ | __NOTOC__ |
Latest revision as of 08:23, 18 October 2022
Accept (or reject) a friendship offer sent by other avatar.
Bot.on("friendship_offer", (event) => {
Bot.acceptFriendshipOffer(event.avatar_uuid, event.session_id, true);
});
See friendship_offer event for details.
Reference
This command accepts the following parameters:
Variable | Required | Description
| |
---|---|---|---|
Input: | |||
avatar_uuid | yes | sender avatar UUID | |
session_id | yes | session UUID from the event | |
accept | yes | true to accept an offer, false to reject. | |
Output: | |||
Function returns a Promise with the following data: | |||
success | bool | true if command completed successfully | |
error | string | error string if command has failed |
Example
Bot.on("friendship_offer", async function(event) {
console.log("Got friendship offer from: " + event.avatar_name + "\n\nAccepting now.");
let response = await Bot.acceptFriendshipOffer(event.avatar_uuid, event.session_id, true);
if(response.success)
{
console.log("Accepted the friendship Offer");
} else {
console.log("Rejected the friendship Offer");
console.error("Error: " + response.error)
}
});
console.log("Bot is listening, friendship offers");