【发布时间】:2020-08-01 05:11:12
【问题描述】:
我正在开发一个不和谐的机器人,它使用私人消息来通知用户是否已收到版主的警告。在处理此问题时,我发现存在一种边缘情况,即机器人由于其隐私设置而无法向用户发送消息。如何编写代码来打开私人频道、尝试发送消息并处理无法发送的问题?
这是发送消息的代码:
public static void sendNotification(Warning warning, TextChannel alt) {
User target = jda.getUserById(warning.getuId());
if(target == null)
return;
target.openPrivateChannel().queue(c -> c.sendMessage(WarningUtil.generateWarningMessage(warning)).queue());
}
【问题讨论】:
标签: java discord-jda