RichPresence不适用于JDA

时间:2019-06-08 16:43:14

标签: java discord discord-jda

我注意到,我的机器人没有对RichPresence进行任何设置,就象今天看到的那样。我上次检查它的时间是在星期三,代码也在那里工作。因此,我今天再次执行了此操作,并且RichPresence没有像往常一样重设。现在,我认为Discord将更改其界面。

现在,我将最新的JDA版本导入到我的项目中,并修改了代码,以使DataObject成为JSONObject,但仍然无法正常工作。作为第二个,我试图使我的“ Spielst”对象成为RichPresence对象。不幸的是,这也不起作用。

旧类:

public class Spielst implements Activity {

    private String name;
    private String url;
    private ActivityType type;

    public static  Spielst getSpielt(String name, String url, ActivityType typ){
        return new Spielst(name,url,typ);
    }


    protected Spielst(String name, String url, ActivityType typ) {
        this.name = name;
        this.url = url;
        this.type = typ;
    }

    @Override
    public boolean isRich() {
        return false;
    }

    @Override
    public RichPresence asRichPresence() {
        return null;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getUrl() {
        return url;
    }

    @Override
    public ActivityType getType() {
        return type;
    }

    @Nullable
    @Override
    public Timestamps getTimestamps() {
        return null;
    }

    public void setPresence(OnlineStatus status, String state, String details, String application_id,
                            String large_image, String small_image, String large_text, String small_text,
                            long timestamp, long since){
        if(Bot.getInstance().getBot() == null)
            return;
        PresenceImpl presence = new PresenceImpl((JDAImpl) Bot.getInstance().getBot()).setCacheActivity(this)
                .setCacheStatus(status);
        JSONObject data = presence.getFullPresence();
        JSONObject game = data.getJSONObject("game");
        game.put("state",state);
        game.put("details", details);
        game.put("application_id", application_id);
        JSONObject assets = new JSONObject();
        game.put("timestamps",new JSONObject().put("start",timestamp));
        assets.put("large_image", large_image);
        assets.put("small_image", small_image);
        assets.put("large_text", large_text);
        assets.put("small_text", small_text);
        game.put("assets",assets);
        game.put("since",since);
        data.put("game",game);
        ((JDAImpl) Bot.getInstance().getBot())
                .getClient().send((new JSONObject()).put("d", data).put("op", 3).toString());
        System.out.println((new JSONObject()).put("d", data).put("op", 3).toString());
    }
}

新课程:

package de.letsplaybar.discordbot.main.utils;

import de.letsplaybar.discordbot.main.Bot;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.ActivityFlag;
import net.dv8tion.jda.api.entities.RichPresence;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.EnumSet;


/**
 * @author Letsplaybar
 * Created on 05.09.2017.
 */
public class Spielst implements RichPresence {

    private String name;
    private String url;
    private ActivityType type;
    private OnlineStatus status;
    private String state;
    private String details;
    private String application_id;
    private String large_image;
    private String small_image;
    private String large_text;
    private String small_text;
    private long timestamp;
    private long since;

    public static  Spielst getSpielt(String name, String url, ActivityType typ,OnlineStatus status, String state, String details, String application_id,
                                     String large_image, String small_image, String large_text, String small_text,
                                     long timestamp, long since){
        return new Spielst(name,url,typ,status,state,details,application_id,large_image,small_image,large_text,small_text,timestamp, since);
    }


    protected Spielst(String name, String url, ActivityType typ,OnlineStatus status, String state, String details, String application_id,
                      String large_image, String small_image, String large_text, String small_text,
                      long timestamp, long since) {
        this.name = name;
        this.url = url;
        this.type = typ;
    }

    @Override
    public boolean isRich() {
        return false;
    }

    @Override
    public RichPresence asRichPresence() {
        return null;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getUrl() {
        return url;
    }

    @Override
    public ActivityType getType() {
        return type;
    }

    @Nullable
    @Override
    public Timestamps getTimestamps() {
        return null;
    }



    public void setPresence(){
        Bot.getInstance().getBot().getPresence().setActivity(this);
    }

    @Override
    public long getApplicationIdLong() {
        return Long.parseLong(application_id);
    }

    @Nonnull
    @Override
    public String getApplicationId() {
        return application_id;
    }

    @Nullable
    @Override
    public String getSessionId() {
        return "4b2fdce12f639de8bfa7e3591b71a0d679d7c93f";
    }

    @Nullable
    @Override
    public String getSyncId() {
        return "e7eb30d2ee025ed05c71ea495f770b76454ee4e0";
    }

    @Override
    public int getFlags() {
        return ActivityFlag.JOIN_REQUEST.getOffset();
    }

    public long getTimestamp() {
        return timestamp;
    }

    public long getSince() {
        return since;
    }

    @Override
    public EnumSet<ActivityFlag> getFlagSet() {
        return EnumSet.of(ActivityFlag.JOIN_REQUEST);
    }

    @Nullable
    @Override
    public String getState() {
        return state;
    }

    @Nullable
    @Override
    public String getDetails() {
        return details;
    }

    @Nullable
    @Override
    public Party getParty() {
        return new Party("party1234", 1, 6);
    }

    @Nullable
    @Override
    public Image getLargeImage() {
        return new Image(getApplicationIdLong(), large_image, large_text);
    }

    @Nullable
    @Override
    public Image getSmallImage() {
        return new Image(getApplicationIdLong(), small_image, small_text);
    }
}

但是到了新班,我错过了syncid和seasonid,而且我也不知道我从哪里得到的,因为它们不在discordsite网站的文档中。有没有人找到仍然适用于旧版本的实现,还是有人知道如何获得这两个值?

2 个答案:

答案 0 :(得分:1)

JDA是为机器人帐户制作的库。由于漫游器根本无法使用丰富的状态,因此它实际上不支持对其进行设置。此外,discord的API并没有真正支持以这种方式进行设置。

使用丰富状态的正确方法是通过与discord-rpc SDKGame SDK的IPC连接。 您可以为Discord-rpc SDK使用一个Java库,例如java-discord-rpc,它可以连接到Discord客户端并在那里设置状态。

通过网关会话(例如JDA使用)更新丰富的状态并没有记录在案,并且可能会发生更改。

答案 1 :(得分:0)

机器人不能拥有丰富的形象。手动发送请求到Discord不会帮助您。如果您是自驾车,那将是对Discord TOS的反对。