基本上,有没有一种方法可以使用discord.js查看消息作者是否在特定服务器中?我想这样做,以便如果味精作者在特定的服务器中,则会向Discord.RichEmbed()添加一个字段。
答案 0 :(得分:0)
是的,有可能,但这取决于几件事:您的机器人也必须位于其他服务器中。可悲的是,我不知道如何在Discord.js v12中做到这一点(因为它们在那里做了很多更改,但是为此您可以只查看文档),但是我将为您提供v11.5.1的代码在这里
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
int ID_NOTIFY = info.getId();
String CHANNEL_ID = "channel-1";
String CHANNEL_NAME = "channel-name";
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(context, 1, intent, 0);
Intent reminderDeletor = new Intent(context, DeleteNotifyReminder.class);
reminderDeletor.putExtra("id", info.getId());
PendingIntent pird = PendingIntent.getBroadcast(context, info.getId(), reminderDeletor, 0);
Notification.Action actionDelete = new Notification.Action(R.drawable.ic_delete, getString(R.string.delete), pird);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
int importanse = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, importanse);
Objects.requireNonNull(manager).createNotificationChannel(channel);
Notification.Builder builderCompat = new Notification.Builder(context, CHANNEL_ID)
.setContentTitle(getString(R.string.app_name))
.setContentIntent(pi)
.setSmallIcon(R.drawable.notify_remind_icon)
.setContentText(info.getRemind())
.setOngoing(true)
.setChannelId(CHANNEL_ID)
.addAction(actionDelete);
if (needColor) builderCompat.setColor(color);
if (info.getRemind().length() > 70) builderCompat.setStyle(new Notification.BigTextStyle().bigText(info.getRemind().substring(0, 70)));
else builderCompat.setStyle(new Notification.BigTextStyle().bigText(info.getRemind()));
manager.notify(ID_NOTIFY, builderCompat.build());
}else {
Notification.Builder builder = new Notification.Builder(context)
.setContentTitle(getString(R.string.app_name))
.setContentIntent(pi)
.setSmallIcon(R.drawable.notify_remind_icon)
.setContentText(info.getRemind())
.setOngoing(true)
.addAction(R.drawable.ic_delete, getString(R.string.delete), pird);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && needColor) {
builder.setColor(color);
}
String text = info.getRemind();
if (text.length() > 70) builder.setStyle(new Notification.BigTextStyle().bigText(text.substring(0, 70)));
else builder.setStyle(new Notification.BigTextStyle().bigText(text));
Objects.requireNonNull(manager).notify(ID_NOTIFY, builder.build());
}