创造你的世界
社交
发送直接消息 API
13 分
您可以使用发送直接消息(dm)api向zepeto世界中的其他用户发送直接消息。 在已启动的世界中使用直接消息(dm)发送api时,消息底部会自动提供一个进入世界的链接,非常适合推广该世界。 使用时请务必遵循注意事项。 安装 窗口 → 包管理器 → zepeto world包,请先安装版本1 21 14或更高版本。 之后,请安装版本为1 0 7或更高的‘zepeto module’包。 确保zepeto应用程序运行版本3 46 000或更高。 发送直接消息api 要使用发送dm api,请添加以下导入语句。 import { socialservice } from 'zepeto module social'; 发送dm核心功能 声明 public static openpopupdirectmessage($sendmessage string, $userids? string\[], $oncomplete? system action$1)\ void; 参数 参数 描述 sendmessage 这是一个必需的参数。这是您要发送的消息的主体。如果它是空白或空的,传输将被视为失败。 userids 这是一个可选参数。 如果您传递 userids 选择 ui 将配置相应的用户 id 列表。 当未传递 userids 或传递空列表时 选择 ui 将构建为发送消息的用户的关注/被关注列表。 oncomplete 这是一个回调,当消息发送完成或失败时调用。 直接消息弹出状态 true left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type 按错误代码的情况 true left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type 使用示例 直接输入发送者并发送 1\) 请将发送 dm 按钮添加到画布中。 2\) 请按照以下示例代码编写。 import { zepetoscriptbehaviour } from 'zepeto script'; import { socialservice, directmessagepopupstate } from 'zepeto module social'; import { button } from "unityengine ui"; import { worldservice } from 'zepeto world'; export default class senddirectmessage extends zepetoscriptbehaviour { // 存储直接消息的变量 public message string; // 要发送直接消息的用户 id 数组 public userids string\[]; // 对按钮 ui 组件的引用 public senddmbutton button; start() { this senddmbutton onclick addlistener(() => { // 检查我的 id 是否包含在 userids 数组中,如果包含则返回 if (this userids includes(worldservice userid)) { console log("userids 包含我的 userid"); return; } // 使用 socialservice 打开发送直接消息的弹出窗口 socialservice openpopupdirectmessage(this message, this userids, (popupstate directmessagepopupstate) => { // 检查直接消息弹出窗口的状态 if (popupstate === directmessagepopupstate cancel) { console log("您关闭了弹出窗口或未能发送消息"); } else if (popupstate === directmessagepopupstate sendcomplete) { console log("dm 消息已成功发送,弹出窗口已关闭。"); } }); }); } } 3\) 编写脚本后,返回 unity 编辑器并将按钮拖到检查器中进行设置。输入消息正文和目标用户的 userid。 最多显示20人,因此请最多输入20人。 4\) 当您按下发送dm按钮时,好友列表ui会出现。 选择目标用户并点击发送。 5\) 如果发送dm成功,将出现一个toast ui,指示成功,并且示例脚本将输出日志。 6\) 此外,目标用户已收到dm。 如果发生错误,例如连续发送消息或消息内容为空,dm传输将被视为失败。 使用以下/关注者列表 ui 发送 1\) 请在画布上添加一个按钮。 2\) 请按照以下示例代码编写。 如果您将空列表传递给 targetuserid 参数,将会出现以下/关注者列表 ui。 import { zepetoscriptbehaviour } from 'zepeto script'; import { socialservice, directmessagepopupstate } from 'zepeto module social'; import { button } from "unityengine ui"; export default class senddirectmessage extends zepetoscriptbehaviour { // 存储直接消息的变量 public message string; // 引用按钮 ui 组件 public senddmbutton button; // 私有变量,用于存储用户 id 数组,初始化为 null private emptyids string\[]; start() { this senddmbutton onclick addlistener(() => { // 打开一个弹出窗口以使用 socialservice 发送直接消息 // 使用类的消息内容和一个空的用户 id 数组 socialservice openpopupdirectmessage(this message, this emptyids, (popupstate directmessagepopupstate) => { // 检查返回的直接消息弹出窗口状态 if (popupstate === directmessagepopupstate cancel) { console log("您关闭了弹出窗口或未能发送消息"); } else if (popupstate === directmessagepopupstate sendcomplete) { console log("直接消息发送成功,弹出窗口已关闭。"); } }); }); } } 3\) 编写脚本后,返回unity编辑器并在检查器中拖动按钮进行设置。然后请输入消息的主体。 4\) 当你按下发送dm按钮时,出现关注/粉丝界面。 选择目标用户并点击发送。(最多可以选择5人) 您一次最多可以向5人发送dm。 您不能向自己发送dm。 实际关注/粉丝用户的数量可能与发送dm弹出窗口中显示的用户数量不同。 这是因为可以选择的用户经过筛选并显示。 如果您选择了一个已阻止接收dm的用户,将视为失败,dm将不会发送。 如果您频繁调用发送dm的api,将受到限制,传输将失败。 您每10秒可以发送一次。请注意不要发送无差别的dm。 如果您发送的消息包含url,将无法正常工作,因此禁止发送包含url的消息。 如果发送的消息为空或空白,将视为失败。请务必写下消息的内容。
