如何让我的不和谐机器人自动回复任何消息

时间:2021-04-04 06:57:24

标签: discord discord.js

我想要做的是设置一个自动响应不和谐机器人,它可以对特定频道中正在发送的任何消息添加反应。我不明白为什么它没有出现不一致。

1 个答案:

答案 0 :(得分:0)

很简单,只需要添加一个消息事件监听器,验证通道id是否是你想要的,然后使用.react方法。例如:

ActivityApplicationBinding binding;

boolean isOnlyImageAllowed = true;
private static final int PICK_PHOTO = 1958;
private static final int REQUEST_EXTERNAL_STORAGE = 1;
private static String[] PERMISSIONS_STORAGE = {
        Manifest.permission.WRITE_EXTERNAL_STORAGE
};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    binding = ActivityApplicationBinding.inflate(getLayoutInflater());
    View view = binding.getRoot();
    setContentView(view);
  

    //check user storage permission

    int permission = ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
    if (permission != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(
                this,
                PERMISSIONS_STORAGE,
                REQUEST_EXTERNAL_STORAGE
        );
    }




    binding.form4.choosePropertyFile.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent intent;
            if (isOnlyImageAllowed) {
                // only image can be selected
                intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            } else {
                // any type of files including image can be selected
                intent = new Intent(Intent.ACTION_GET_CONTENT);
                intent.setType("file/*");
            }
            startActivityForResult(intent, PICK_PHOTO);
        }
    });



}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == RESULT_OK && requestCode == PICK_PHOTO) {
        Uri imageUri = data.getData();

        binding.form4.selectedPropertyFile.setText("" + imageUri.getLastPathSegment());

    }

}